Skip to content

crypto: VerifyDocument's error and legacy-unsigned handling both let forged policy.json through #113

Open

Description

@codeyevsky

Problem

Two related trust gaps in packages/crypto/sign.go:

  1. :67 — when signature verification encounters a malformed signature (e.g. invalid encoding or wrong length), VerifyDocument returns a hard error rather than a result indicating signed=true, valid=false; callers that only branch on the error (rather than distinguishing "malformed" from "valid") can end up treating the error path inconsistently from a clean invalid-signature result, creating divergent handling between callers.
  2. :63 — a document with no _sig field at all is treated as a benign "legacy unsigned document" and accepted, rather than being treated as untrusted when the system otherwise expects signed documents.

Impact

An attacker can either strip the signature field entirely (accepted as "legacy") or supply a malformed signature (handled inconsistently depending on the caller) to get a forged policy.json or other signed document accepted where a properly verified result would have been expected.

Repro

  1. Take a signed document and remove its _sig field entirely; pass it to VerifyDocument and observe it is treated as a legacy unsigned document rather than rejected.
  2. Take a signed document and corrupt the _sig value into an invalid encoding; pass it to VerifyDocument and observe the function returns a hard error rather than a structured signed=true, valid=false result that callers can check uniformly.

Suggested fix

Make VerifyDocument always return a structured result (signed bool, valid bool, err error) rather than conflating malformed-signature with a bare error; a malformed signature should resolve to signed=true, valid=false, not a short-circuiting error. Change the missing-_sig case to also resolve to signed=false, valid=false and require every caller that currently special-cases "legacy unsigned" to make that an explicit, audited opt-in rather than the default outcome.

Activity

  1. sharmis-tp commented on Nov 18, 2026

    @sharmis-tp

    If VerifyDocument's error path and legacy-unsigned fallback both pass through, any policy.json is accepted regardless of signature. I'll make both paths reject the document and log the specific failure reason. The legacy-unsigned migration window should have a hard cutoff date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions