Skip to content

Sec/lens4 headers#459

Open
fredbi wants to merge 3 commits into
go-openapi:masterfrom
fredbi:sec/lens4-headers
Open

Sec/lens4 headers#459
fredbi wants to merge 3 commits into
go-openapi:masterfrom
fredbi:sec/lens4-headers

Conversation

@fredbi
Copy link
Copy Markdown
Member

@fredbi fredbi commented May 15, 2026

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

fredbi and others added 3 commits May 15, 2026 00:37
…allbacks

The runtime delegates credential comparison to caller-supplied
authentication callbacks (UserPassAuthentication, TokenAuthentication,
ScopedTokenAuthentication, and their Ctx variants). Callers that
compare a secret against a known value must use
crypto/subtle.ConstantTimeCompare to avoid response-timing side-channels.

This commit:
- Documents the contract on all six callback type godocs.
- Updates the apikey and basic auth examples to demonstrate the
  safe pattern, so users copying the snippets inherit it.

No API change. The runtime itself does not compare secrets and
remains structurally timing-safe.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
RFC 7231 §5.3.1 defines qvalue as a fraction in [0, 1]: when the
leading digit is "1", the only valid decimal portion is "0",
"00" or "000". expectQuality previously accepted inputs like
"1.1" or "1.9" verbatim and returned values > 1, letting a
malformed Accept entry artificially boost its priority above
all properly-formed offers.

The fix surfaces the malformed input via the existing q < 0
sentinel; ParseAccept and ParseAccept2 inherit the rejection.

Found by FuzzParseAccept (lens 4 of the security scrub). The
"0;q=1.1" minimised input is persisted under testdata/fuzz/ as
a regression seed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Lands seven fuzz targets covering the header-parsing surface of
the security scrub (lens 4):

- runtime.ContentType
- mediatype.Parse / mediatype.MatchFirst / mediatype.ParseAccept
- negotiate/header.parseValueAndParams / ParseAccept / ParseList

Each target carries a seed corpus of edge cases (malformed
quoting, multi-byte sequences, oversized inputs, invalid q-values,
trailing-semicolon and comma anomalies) plus per-target invariants
(non-zero MediaType only on success; Q in [0,1]; non-empty params
keys; no empty list entries).

CI auto-discovers FuzzXxx via the shared go-test-monorepo workflow.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant