Skip to content

Add a hidden, repeatable --header flag for API requests - #382

Merged
davixcky merged 2 commits into
mainfrom
davido/cli-header-flag
Oct 1, 2026
Merged

davixcky merged 2 commits into
mainfrom
davido/cli-header-flag

Conversation

@davixcky

@davixcky davixcky commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

We decided on 29 Sep (sprint planning, then David and Scott's huddle) to count sandbox GitHub Action usage from API metrics instead of putting a label on every sandbox. For that, the CLI needs a way for an integration to identify itself on its requests. Scott and David agreed on option C: a generic, repeatable --header flag, with no config-file surface.

$ signadot --header "Signadot-Client-Context: integration=sandbox-action,integration-version=0.1.0" \
    sandbox apply -f sandbox.yaml

What

  • The flag: a global persistent --header "Name: value", repeatable. A repeated name keeps every value in order, as HTTP allows.
  • Hidden (MarkHidden) while its use is worked out.
  • Protected headers: you can't set the headers the CLI or Go's transport owns: Authorization, Proxy-Authorization, Signadot-Api-Key, Signadot-Cluster-Token, Cookie, User-Agent, Accept, Accept-Encoding, Content-Type, Content-Length, and the framing and hop-by-hop headers (Host, Transfer-Encoding, Connection, Keep-Alive, Proxy-Connection, TE, Trailer, Upgrade, Expect). Names and values are checked with httpguts, the same checks Go's transport applies, so control characters are refused too. Bad input fails before any request, with a message naming the flag.
  • No SDK change: the SDK already accepts an http.Client. Only when --header is given does the CLI pass one, whose transport adds the headers. The SDK skips its own User-Agent wrapper once it gets a custom client, so that transport also sets User-Agent. Without the flag, every request is exactly as before.

Tests

  • TestParseHeaders: canonicalisation, trimming, repeated names, empty values.
  • TestParseHeadersRefuses: malformed, an invalid name, CR/LF, NUL and DEL (a tab is allowed), and protected headers including Accept, Accept-Encoding, TE and Upgrade.
  • TestExtraHeadersReachTheAPI: a real SDK call to an httptest server, with and without the flag. The extra header arrives, and User-Agent and Signadot-Api-Key are intact.
  • TestHeaderFlagIsHidden
  • Manually: --help doesn't mention it, and --header "Authorization: x" is refused.

internal/repoconfig fails locally in a git worktree, because go-git can't find HEAD there. That package is untouched here; CI will show whether it passes in a normal checkout.

Still to agree

  • The header name and keys the API records: Signadot-Client-Context with integration=…,integration-version=… is the proposal. The flag itself doesn't depend on that choice.
  • The API side (Scott) turns it into a metric. The sandbox Action will pass the flag once this ships in 1.9.0.

🤖 Generated with Claude Code

Integrations such as the sandbox GitHub Action need to say who they are,
so that usage can be counted from the API's metrics rather than from a
label on every sandbox. --header "Name: value" adds a header to every
API request, and may be given more than once; a repeated name keeps
every value, as HTTP allows.

The headers the CLI owns cannot be set this way: Authorization,
Signadot-Api-Key, Signadot-Cluster-Token, User-Agent, Cookie and the
framing headers. Names must be RFC 9110 tokens and values one line.

Only when --header is given does the SDK get an http.Client of the
CLI's own; the SDK then skips its User-Agent wrapper, so the new
transport sets User-Agent too. Without the flag every request is
exactly as before. Hidden while its use is worked out.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium. Approved; Bugbot and Security Agent were not running, and remaining signals plus policy do not require human review. No reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@scott-cotton

Copy link
Copy Markdown
Member

Looks overall good to me.

Some findings would help make it more solid:

  1. Control characters get through validation (internal/config/headers.go:46). The check only rejects CR and LF. A value containing another control character, such as NUL (\x00) or DEL (\x7f), passes, and then every request fails in Go's HTTP transport with "invalid header field value". The PR promises bad headers are rejected before any request is sent. httpguts.ValidHeaderFieldValue would catch these up front.
  2. The blocked-headers list is missing Accept-Encoding and Accept (internal/config/headers.go:13).
    • --header "Accept-Encoding: gzip" turns off Go's automatic decompression. The SDK then receives gzipped bytes and fails to decode the JSON, with a confusing error.
    • Accept is added alongside the one the runtime already sets, so the server sees two conflicting values.
  3. The help text overpromises (internal/config/api.go:262). It says the header goes to "every API request", but only clients built through GetBaseTransport() get it. The local connect daemon builds its own transport (internal/locald/sandboxmanager/apiclient/apiclient.go:143,168), so its API calls, including token refresh, never carry the header. Neither does the remote MCP client (internal/mcp/remote/remote.go:134). This doesn't affect the sandbox-action use case the PR is for. Either narrow the help text or pass the headers through to those clients.

From review:
- Validate names and values with httpguts, the checks Go's HTTP
  transport applies, so a value with NUL, DEL or any other control
  character is refused up front instead of failing every request with
  'invalid header field value'.
- Refuse Accept and Accept-Encoding: the latter turned off the
  transport's transparent decompression, so the SDK was handed gzipped
  bytes, and the former went out beside the one the runtime sets. Also
  refuse the remaining hop-by-hop headers (Keep-Alive,
  Proxy-Connection, TE, Trailer, Upgrade, Expect).
- The help and comments no longer say every API request: only clients
  built from API.GetBaseTransport carry the headers, and the local
  connect daemon and the remote MCP client build their own.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@davixcky

davixcky commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @scott-cotton, all three fixed in 5e3def0:

  1. Control characters: names and values are now checked with httpguts.ValidHeaderFieldName / ValidHeaderFieldValue, the same checks Go's transport applies. NUL, DEL and any other control character is refused before any request (tab is still allowed, as HTTP permits it). Tests cover \x00, \x7f and CR/LF.
  2. Accept / Accept-Encoding: both are added to the denied list, along with the remaining hop-by-hop headers (Keep-Alive, Proxy-Connection, TE, Trailer, Upgrade, Expect), with tests.
  3. Help text: narrowed to "add a header to the CLI's API requests … not sent by the local connect daemon or the MCP client", and the comments in api.go and headers.go say the same. I didn't plumb it through to locald and MCP: the Action doesn't need it, and locald would need the headers carried in the connect invocation config. Happy to do that as a follow-up if we want it.

@scott-cotton scott-cotton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davixcky
davixcky merged commit 96cc85e into main Oct 1, 2026
1 check passed
@davixcky
davixcky deleted the davido/cli-header-flag branch October 1, 2026 15:22
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.

2 participants