Skip to content

feat(api): stop copying the token in RequestHeaderSession on instances - #70

Merged
josuegiron merged 2 commits into
masterfrom
fix/instance-session-header-no-token
Nov 21, 2026
Merged

josuegiron merged 2 commits into
masterfrom
fix/instance-session-header-no-token

Conversation

@josuegiron

Copy link
Copy Markdown
Member

Reason

RequestHeaderSession copied the SecurityToken request header into the response header. That echoes the request token, which SEC-08 (#65, Q36) already keeps out of response bodies on api.New instances. Owner decision (2026-11-21): instances stop the copy, and the default instance keeps it.

Scope and stack

  • Stack: 2 of 2. This PR is stacked on fix(api)!: stop copying the basic password into Basic-Secret #69 (fix/drop-basic-secret-header). Both PRs edit adjacent lines of the README security notes (the BasicToken line and the token-echo line), so they would conflict if both targeted master. Merge fix(api)!: stop copying the basic password into Basic-Secret #69 first, then retarget this PR to master. The stack merges cleanly with fix(api): send the request info error from RequestBasic getters #68 as well (tested locally).
  • Includes:
    • On an instance, RequestHeaderSession no longer sets the SecurityToken response header.
    • The 401 for a missing header is unchanged.
    • Updated: the doc comment, ADR 0001 (section 10 and the New() defaults line), the README security note, and the migration guide ("No token echo" and its checklist item).
  • Excludes:
    • The default instance: it keeps the v0 copy. A later, separate story switches the default instance to New() behavior; this PR does not anticipate it.
    • No option restores the copy. A handler that wants to return a token sets the header itself (YAGNI-01, as in Q47).
  • Commit type: feat(api), not breaking. Instances are new in v1, so v0 programs see no change.

Changes

  • middlewares.go: set the response header only when !instanceFrom(r).fromNew. This is the same check getSecurityToken uses. The doc comment is updated, including a corrected first line.
  • instance_token_echo_test.go: a table-driven TestRequestHeaderSessionResponseHeader with three cases:
    • an instance does not copy the token;
    • the default instance copies it;
    • an instance keeps a token the handler sets (a guard for the documented way to return one).
  • README.md, docs/adr/0001-v1-instance-api.md, docs/migration-v1.md: updated as described under Scope.

Release notes

Instance changes: on an api.New instance, RequestHeaderSession no longer copies the SecurityToken request header into the response header. It still answers 401 when the header is missing. This completes "no token echo" (SEC-08) on instances. A client that read the token back from that response header must keep its own copy, or the handler must set the header. The default instance, and a RequestHeaderSession placed outside a.Handler, still copy it as in v0.

Verification

  • The instance case of TestRequestHeaderSessionResponseHeader fails on the old middlewares.go; all cases pass after the change.
  • On this branch: gofmt -l . prints nothing; go vet ./... ok; go test -race ./... ok; govulncheck ./... found no vulnerabilities.
  • Reviewed with the BMad quick review lens. It found no bugs and two minor items, both fixed: the tests are now table-driven, and the doc comment's first line is accurate.

🤖 Generated with Claude Code

RequestHeaderSession copied the SecurityToken request header into the
response header, echoing the request token that SEC-08 already keeps
out of instance bodies. On an api.New instance it no longer does; it
still answers 401 without the header. The default instance keeps the v0
copy. Instances are new in v1, so v0 programs see no change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@josuegiron
josuegiron changed the base branch from fix/drop-basic-secret-header to master November 21, 2026 17:53
@josuegiron
josuegiron merged commit 8e63345 into master Nov 21, 2026
2 checks passed
@josuegiron
josuegiron deleted the fix/instance-session-header-no-token branch November 21, 2026 17:54
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