fix(security): [CWE-326] validate cookie encryptor config#6
Draft
WilliamNHarvey wants to merge 2 commits into
Draft
fix(security): [CWE-326] validate cookie encryptor config#6WilliamNHarvey wants to merge 2 commits into
WilliamNHarvey wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security Fix: CWE-326 — Cookie encryptor accepts empty secrets and weak KDF iteration inputs
Summary
Vulnerability Description
NewCookieEncryptoraccepted caller-providedsecretanditerationswithout rejecting empty secrets, too-short secrets, negative iterations, or low positive iteration counts. Those values flowed directly into the cookie encryption and signing key generator. A consuming service with an empty environment variable or weak iteration configuration could derive predictable or materially weaker cookie keys.Proof of Exploit
The proof harness constructed
NewCookieEncryptor("", 1)andNewCookieEncryptor("", -1). Both produced usable encryptors that could encrypt and decrypt dummy cookie values with matching weak inputs. Runtime startup was intentionally disabled for this static Go library; the issue is source-confirmable becausecookies.gopassed the inputs directly to the key generator and the pinned dependency only defaultediterations == 0.Data Flow
Caller-controlled constructor inputs ->
NewCookieEncryptor(secret, iterations)->goRailsYourself/crypto.KeyGenerator{Secret, Iterations}->pbkdf2.Key-> cookie encryption and signing key material ->MessageEncryptorprotects cookie values.Changes Made
Added constructor validation and a non-panic constructor path:
0as the default iteration input and normalize it to 1000.NewCookieEncryptorsignature, now panicking on unsafe configuration.NewCookieEncryptorWithErrorfor callers that need to handle validation failures explicitly.Before / After
Before:
After:
HIPAA / PII Impact Assessment
This fix strengthens confidentiality and integrity for encrypted cookie contents that may gate access to patient data in consuming services. It does not log, expose, or transform PHI/PII.
Testing
go test -v ./...go vet ./...passedQA
This repository is a backend Go library/package with no browser, admin UI, or running service surface. Manual validation is local/API-level:
go test -v ./....TestNewCookieEncryptorRejectsWeakConfigrejects empty, blank, short-secret, negative-iteration, and low-iteration inputs.TestNewCookieEncryptorAcceptsDefaultAndMinimumIterationsstill encrypts/decrypts with a valid 32-byte secret and supported iteration values.Reviewers
Ready-for-review PRs request
@doximity/security_guild_reviewers(AppSec) plusCODEOWNERS for the changed paths. Draft PRs intentionally defer security-guild
review requests until the PR is validated and marked ready. Both must approve
before merge.
This PR was auto-generated by the security-auditor agent.
The "Agent run cost" block is appended to this description automatically after
the audit run completes.