fix(invoke): adjust redaction regex to allow words following bearer#1480
Conversation
|
Claude Security Review: no high-confidence findings. (run) |
Package TarballHow to installgh release download pr-1480-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.18.0.tgz |
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Looks good to merge. The fix correctly switches from a prefix-based match (which over-redacted bare words like token after bearer) to a JWT-shape match, which directly addresses #1479. The tests are well-constructed: they generate real JWTs via jose rather than mocking, and they include explicit regression cases for the prose patterns that triggered the bug (bearer token is available, Invalid Bearer Token).
A couple of small things I considered but don't think need to block:
- The regex assumes AgentCore inbound auth is always JWT-shaped. The PR description calls this out explicitly, so 👍. If opaque bearer tokens are ever supported, the JWT-shape pattern won't catch them and we'll want to revisit.
- The trailing
[A-Za-z0-9_-]+is greedy and unanchored, so a JWT immediately concatenated with adjacent base64url-ish text (no quote/whitespace/punctuation between them) would over-match. In practice JWTs in logs/JSON/headers are always bounded, so this is a theoretical concern only.
No telemetry needed since this is a pure fix to a redaction utility.
|
harness failure is a transient connection failure, here is the comment it tried to post: |
| // See https://stackoverflow.com/a/74181595 (why JWTs start with `eyJ`). | ||
| .replace(/eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g, '[REDACTED]') | ||
| .replace(/(client[_-]?secret["']?\s*[:=]\s*["']?)([^"',\s}]+)/gi, '$1[REDACTED]') | ||
| .replace(/((?:access[_-]?)?token["']?\s*[:=]\s*["']?)([^"',\s}]+)/gi, '$1[REDACTED]') |
There was a problem hiding this comment.
the eslint flag is existing code, and its a false-positive. The rule is prone to false positives, and they call it out here: https://www.npmjs.com/package/safe-regex
| @@ -1,17 +1,34 @@ | |||
| import { redactSensitiveText } from '../command.js'; | |||
| import { describe, expect, it } from 'vitest'; | |||
| import { SignJWT } from 'jose'; | |||
There was a problem hiding this comment.
TIL about jose pretty neat!
| it('does not redact prose like "Invalid Bearer Token"', () => { | ||
| const input = 'Invalid Bearer Token'; | ||
| expect(redactSensitiveText(input)).toBe(input); |
There was a problem hiding this comment.
nice that our integ/e2e tests caught this!
Description
See #1479. The fix is to leverage the shape of JWT instead of a bearer prefix for redaction.
This relies on AgentCore inbound auth only accepting JWT, and not arbitrary bearer tokens.
Tests create an actual JWT (pull in jose as dev dependency) to verify the pattern matching is working as expected.
Related Issue
Closes #
Documentation PR
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typechecknpm run lintsrc/assets/, I rannpm run test:update-snapshotsand committed the updated snapshotsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.