fix(security): [CWE-614] secure cookie defaults#5
Draft
WilliamNHarvey wants to merge 2 commits into
Draft
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-614 — Nil/default cookie options emit cookies without secure attributes
Summary
Vulnerability Description
SecureCookieManager.Setaccepted nil or emptyCookieOptions, converted nil to an empty struct, and copied zero-value cookie security attributes intohttp.Cookie. Library callers that omitted options could issue encrypted or signed cookies withoutHttpOnly,Secure,SameSite, or a stablePathdefault.CookieSessionManager.Updateforwarded its stored options into the same sink, so nil session-manager options reached the same insecure default behavior.Proof of Exploit
The proof harness called
SecureCookieManager.SetandCookieSessionManager.Updatewith nil/default options. The emittedSet-Cookieheaders omittedHttpOnly,Secure,SameSite, andPath. Runtime startup was intentionally disabled for this static Go library; the source-to-sink path is deterministic and was replayed with host-side Go tests.Data Flow
Caller omits
CookieOptions->SecureCookieManager.Setreceivesopts == nilor an empty options struct -> zero-value cookie security attributes are copied intohttp.Cookie->http.SetCookieemits the header. For sessions,NewCookieSessionManager(..., nil)->CookieSessionManager.Update->SecureCookieManager.Setreaches the same sink.Changes Made
Added secure default cookie options for nil/default paths:
Path=/HTTPOnly=trueSecure=trueSameSite=LaxSetandDeletenow apply those defaults before emitting cookies. Focused regression tests cover direct secure-cookie writes and the session-manager update path.Before / After
Before:
After:
HIPAA / PII Impact Assessment
This fix protects encrypted cookie/session values that may gate access to patient data in consuming services. It does not add logging, expose cookie contents, or touch stored 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 ./....TestSecureCookieManagerSetAppliesSecureDefaultsandTestCookieSessionManagerUpdateUsesSecureDefaultCookieOptionspass.Set-Cookieassertions incookie_options_test.goand verify they requireHttpOnly,Secure,SameSite=Lax, andPath=/.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.