fix: relax custom header regex to allow any valid HTTP header#1194
fix: relax custom header regex to allow any valid HTTP header#1194jesseturner21 wants to merge 3 commits into
Conversation
Package TarballHow to installnpm install https://github.com/aws/agentcore-cli/releases/download/pr-1194-tarball/aws-agentcore-0.13.1.tgz |
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Thanks for cleaning this up — the relaxed validation and the CLI/TUI copy changes look good. I've got three things to flag before this can merge, the first of which is a correctness blocker.
The biggest concern is a cross-repo schema mismatch: the vended CDK project depends on @aws/agentcore-cdk (agentcore-l3-cdk-constructs), and its ConfigIO.readProjectSpec() still uses the old strict RequestHeaderAllowlistSchema at cdk synth time. With this PR merged, a user who configures e.g. X-Custom-Signature via the CLI will write it to agentcore.json, and then cdk deploy will fail schema validation locally before the request ever reaches AWS. A matching PR in agentcore-l3-cdk-constructs to relax RequestHeaderAllowlistSchema needs to land and ship in a released version of @aws/agentcore-cdk that this CLI's vended project pins to (see src/assets/cdk/package.json).
The other two comments are schema drift within this repo — the Zod schema is now weaker than validateHeaderAllowlist and can accept configs the CLI validators would reject.
Coverage Report
|
Relaxes header allowlist to accept any valid HTTP header name (alphanumeric, hyphens, underscores) that isn't structurally reserved (x-amz-*, x-amzn-* except Runtime-Custom-*), per the AWS AgentCore Runtime documentation. - Updates schema refine to validate character pattern + block reserved prefixes - Updates normalizeHeaderName to pass through X-* headers unchanged - Adds case-insensitive deduplication - Adds tests for X-Api-Key, X-Custom-Signature, restricted prefix rejection Refs #1151
…tion Updates CLI flag description and TUI hints to show examples of newly-accepted header names (X-Api-Key, X-Custom-Signature) and clarify when auto-prefixing applies. Refs #1151
cb3a48d to
6f9fde0
Compare
Addresses review feedback on PR #1163: - Schema now returns specific error per violated rule (character pattern, x-amz- reserved, x-amzn- reserved-except-Custom-) instead of a single three-rule string. Easier to act on for users. - Removes dead-code clause '&& !lower.startsWith('x-amzn-')' on the x-amz- check; 'x-amz-' and 'x-amzn-' are disjoint prefixes (position 5 differs: '-' vs 'n'), so the carve-out is unnecessary. - Extracts checkAllowlistHeader() in agent-env.ts as the single source of truth; header-utils.ts now consumes it instead of duplicating the rules. - Adds test pinning the documented suffix-preservation behavior of normalizeHeaderName() for the Runtime-Custom- branch. - Updates --request-header-allowlist flag help to clarify X-prefixed names pass through unchanged. Refs #1151
Summary
Fixes #1151
X-Amzn-Bedrock-AgentCore-Runtime-Custom-from header names in the allowlist configx-amz-/x-amzn-prefixes and restricted standard HTTP headersRESTRICTED_HEADERSto schema module as single source of truthinvoke -H/dev -Hauto-prefixes when the agent's allowlist uses the prefixed formTest plan
agentcore add agent --request-header-allowlist "X-Custom-Signature, X-Api-Key"stores headers without prefixagentcore add agent --request-header-allowlist "x-amz-bad"is rejectedagentcore add agent --request-header-allowlist "Content-Type"is rejectedagentcore add agent --request-header-allowlist "X-Amzn-Bedrock-AgentCore-Runtime-Custom-Foo"still works (backwards compat)agentcore add agent --request-header-allowlist "Authorization"still worksagentcore.jsonwith prefixed headers still validatesinvoke -H "MyHeader: val"auto-prefixes when allowlist has the prefixed form (backwards compat)invoke -H "X-Custom-Sig: val"passes through when allowlist has it as-is