Skip to content

fix(invoke): adjust redaction regex to allow words following bearer#1480

Merged
Hweinstock merged 1 commit into
aws:mainfrom
Hweinstock:fix/bearer-token-regex
Jun 8, 2026
Merged

fix(invoke): adjust redaction regex to allow words following bearer#1480
Hweinstock merged 1 commit into
aws:mainfrom
Hweinstock:fix/bearer-token-regex

Conversation

@Hweinstock

@Hweinstock Hweinstock commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

How have you tested the change?

  • I ran npm run test:unit and npm run test:integ
  • I ran npm run typecheck
  • I ran npm run lint
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

@github-actions github-actions Bot added the size/s PR size: S label Jun 8, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 8, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Jun 8, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.18.0.tgz

How to install

gh 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

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Jun 8, 2026

@agentcore-cli-automation agentcore-cli-automation 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.

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.

@Hweinstock

Copy link
Copy Markdown
Contributor Author

harness failure is a transient connection failure, here is the comment it tried to post:

Summary of my analysis:

**Findings:**
1. The fix is correct and well-scoped: matches by JWT shape, no longer captures bare words after `bearer`.
2. Tests properly use real JWTs via `jose` (no excessive mocking).
3. The PR comment correctly explains the rationale.
4. The trailing `[A-Za-z0-9_-]+` is greedy and could potentially over-match if a JWT is concatenated directly with adjacent base64url-like alphanumeric text. In practice this is unlikely (JWTs are bounded by quotes/whitespace/punctuation), but worth noting. Not a blocker.
5. A theoretical concern: if AgentCore ever supports non-JWT bearer tokens (opaque tokens), this regex won't catch them. The PR description explicitly acknowledges this assumption.
6. No telemetry needed (pure refactor of redaction utility).

I don't see any serious issues that need code changes. Let me approve with a minor note.

// 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]')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@Hweinstock Hweinstock marked this pull request as ready for review June 8, 2026 19:14
@Hweinstock Hweinstock requested a review from a team June 8, 2026 19:14
@@ -1,17 +1,34 @@
import { redactSensitiveText } from '../command.js';
import { describe, expect, it } from 'vitest';
import { SignJWT } from 'jose';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TIL about jose pretty neat!

Comment on lines +74 to +76
it('does not redact prose like "Invalid Bearer Token"', () => {
const input = 'Invalid Bearer Token';
expect(redactSensitiveText(input)).toBe(input);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice that our integ/e2e tests caught this!

@Hweinstock Hweinstock merged commit a9b0160 into aws:main Jun 8, 2026
35 of 37 checks passed
@Hweinstock Hweinstock deleted the fix/bearer-token-regex branch June 8, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants