Skip to content

Block credential fields spelled with the x- header prefix - #450

Open
kevin9327 wants to merge 1 commit into
CopilotKit:mainfrom
kevin9327:fix/credential-field-aliases
Open

Block credential fields spelled with the x- header prefix#450
kevin9327 wants to merge 1 commit into
CopilotKit:mainfrom
kevin9327:fix/credential-field-aliases

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What is wrong

inspectToolArguments (added in #436, whose job is to keep credential material out of MCP tool
arguments) normalises each argument name -- lowercase, then -, . and whitespace folded to _ --
and compares the result against sensitiveFieldNames. api-key normalises exactly onto api_key
and is caught. x-api-key normalises onto x_api_key, which is not on the list, and goes out.

The spelling that most obviously names a credential is the one that is not blocked.

Measured on main before the change, via inspectToolArguments({ [name]: "value" }):

argument name main with this change
api-key blocked blocked
x-api-key passes blocked
X-API-Key passes blocked
x-auth-token passes blocked
auth_token, authToken passes blocked
bearer_token, session_token passes blocked
passwd, pwd passes blocked
api_secret, secret_key, signing_key passes blocked
ssh_key passes blocked

The change

Two parts, both narrow.

  1. normalizedFieldName drops a leading x_. x- is the conventional prefix for a non-standard
    header; it says nothing about the value, so x-api-key is the same field as api-key.
  2. sensitiveFieldNames gains the spellings of names it already carries: passwd and pwd for
    password, auth_token / authtoken / bearer_token / bearertoken / session_token /
    sessiontoken for token, api_secret / apisecret / secret_key / secretkey /
    signing_key / signingkey for secret, and ssh_key / sshkey for private_key.

Neither part widens what counts as a credential. Every added entry is another name for something
already on the list, and the prefix rule strips only a prefix that carries no meaning of its own.

Verification

bun test server/tests/content-governance.test.ts

  • With server/src/plugins/content-governance.ts reverted to main and only the tests applied:
    13 fail, 18 pass.
  • With the change: 31 pass, 0 fail.

Ten names that merely resemble credential names are pinned as still allowed -- query, url,
path, token_count, max_tokens, tokenizer, x_axis, x_offset, xml, secretary -- and
pass both before and after, so the guard against over-blocking is a real one rather than a
restatement of the new behaviour.

bun run --filter server typecheck and bunx biome check on both touched files are clean.

`inspectToolArguments` compares each argument name against a list of credential
field names after lowercasing and folding `-`, `.` and whitespace to `_`. That
made `api-key` a hit and `x-api-key` a miss, so the spelling that is more
obviously a credential header was the one that left the deployment. Measured on
`main`: `api-key` blocked; `x-api-key`, `X-API-Key`, `x-auth-token`,
`auth_token`, `authToken`, `passwd`, `pwd`, `api_secret`, `session_token`,
`bearer_token`, `ssh_key` and `signing_key` all passed.

`x_` is the conventional prefix for a non-standard header and says nothing
about the value, so it is dropped before the comparison. The list also gains
the spellings of names it already carries -- `passwd`/`pwd` for `password`,
`auth_token`/`bearer_token`/`session_token` for `token`,
`api_secret`/`secret_key`/`signing_key` for `secret`, `ssh_key` for
`private_key`. Neither change widens what counts as a credential: each new
entry is another name for something already listed, and the prefix rule only
strips a prefix that carries no meaning of its own.

The new tests fail 13 of 13 against the current `main` and pass after. Ten
names that only resemble credentials -- `query`, `url`, `path`, `token_count`,
`max_tokens`, `tokenizer`, `x_axis`, `x_offset`, `xml`, `secretary` -- are
pinned as still allowed, and pass both before and after.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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