Files
PaperClipAI/server
Dotta bff0f6dab5 fix(redaction): preserve SigV4 presigned upload URLs in tool results (#22959)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Tool results flow through `validateToolContent`,
`redactSensitiveText`, and `redactCommandText` before reaching the agent
> - `COMMAND_ENV_SECRET_ASSIGNMENT_RE` matched `X-Amz-Credential` and
`X-Amz-Security-Token` inside AWS SigV4 presigned URLs and consumed the
rest of the URL, wiping `X-Amz-Signature`
> - Agents received truncated upload URLs and could not execute signed
S3/R2 `PUT` uploads returned by MCP tools
> - This pull request extracts a focused SigV4 helper that temporarily
sets aside validated `X-Amz-Credential` and `X-Amz-Security-Token`
parameters inside complete HTTPS SigV4 presigned queries before command
redaction, while keeping request-identity hashing and approval
encryption sensitive for those URLs
> - The benefit is that agents receive usable short-lived presigned
upload links while percent-encoded or malformed secrets, other secret
parameters, secret-named assignments, incomplete queries, placeholder
collisions, and retried write idempotency keys remain safe

## Linked Issues or Issue Description

- Refs #14014

## What Changed

- Extracted `packages/adapter-utils/src/sigv4-presigned-url.ts` to
detect complete HTTPS SigV4 presigned queries
(`X-Amz-Algorithm=AWS4-HMAC-SHA256`, valid SigV4 `X-Amz-Credential`
scope, `X-Amz-Date`, numeric `X-Amz-Expires`, `X-Amz-SignedHeaders`, and
64-hex `X-Amz-Signature`), including single- and double-escaped `\u0026`
query separators and trailing markdown/prose delimiters.
- Validated raw and iteratively percent-decoded `X-Amz-Credential` and
`X-Amz-Security-Token` values against canonical decoded shapes and
shared standalone secret token patterns (`sk-`, `gh*_`, `github_pat_`,
Stripe `sk_`/`rk_` keys, JWTs), failing closed on malformed/deeply
nested percent-encoding and private-use placeholder collisions.
- Updated `packages/adapter-utils/src/command-redaction.ts` to delegate
SigV4 parameter protection to `protectSigV4PresignedUrlParameters` and
keep `collectDiagnosticEnvironmentSecrets` treating SigV4 presigned URLs
as private.
- Updated `server/src/services/tool-content-guards.ts`
(`containsSensitiveToolArguments`) to keep SigV4 presigned URLs
classified as sensitive for `toolRequestIdentityHash` (preserving HMAC
`side_effect:v2` idempotency keys across deploys) and
`signToolArguments` (keeping v2 A256GCM encryption at rest).
- Added unit and end-to-end tests in
`packages/adapter-utils/src/command-redaction.test.ts` and
`server/src/__tests__/tool-content-guards.test.ts` covering complete
SigV4 URLs, percent-encoded/double-encoded/malformed smuggled secrets,
sibling secret redaction, model-classifier parity, and HMAC
identity/approval encryption stability.

## Verification

- `pnpm vitest run packages/adapter-utils/src/command-redaction.test.ts
server/src/__tests__/tool-content-guards.test.ts
server/src/__tests__/redaction.test.ts
server/src/__tests__/remote-mcp-redaction.test.ts` — passed (`4` files,
`143` tests).
- `pnpm --filter @paperclipai/adapter-utils typecheck && pnpm --filter
@paperclipai/adapter-utils build && pnpm --filter @paperclipai/server
typecheck` — passed (all 7 server typecheck layers).
- `pnpm verify` — exited with code `2` because graph worker
`@paperclipai/server` hit `SIGKILL` under local memory pressure;
required CI covers the broad suite.
- Verified end-to-end via `validateToolContent`
(`server/src/services/tool-content-guards.ts`) with a realistic MCP
presigned upload response: complete S3 SigV4 URLs arrive intact while
sibling `apiKey`/`Authorization: Bearer` secrets and percent-encoded
smuggled secrets are redacted, and `toolRequestIdentityHash` /
`signToolArguments` remain HMAC-keyed and v2-encrypted.

## Risks

- Complete HTTPS SigV4 presigned URLs remain visible in tool results,
audit summaries, and transcripts until their short expiry window
(`X-Amz-Expires`). Incomplete SigV4 queries, non-SigV4 parameters,
secret-named assignments/CLI flags/JSON keys, percent-encoded/malformed
smuggled tokens, and placeholder collisions fail closed.

## Model Used

- Antigravity AI coding assistant (Google DeepMind agentic runtime,
extended reasoning with local tool execution and verification).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-25 15:31:40 -06:00
..