Skip to content

fix(core): share one header and URL sanitizer for request facts [SAP-5145] - #1313

Open
AntoineMaillard06 wants to merge 3 commits into
mainfrom
antoinemaillard/sap-5145-sdk-denylist
Open

AntoineMaillard06 wants to merge 3 commits into
mainfrom
antoinemaillard/sap-5145-sdk-denylist

Conversation

@AntoineMaillard06

@AntoineMaillard06 AntoineMaillard06 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Primary change type

  • Bug fix
  • Documentation
  • Feature
  • Tests
  • Dependency update
  • Maintenance or refactor

Problem and motivation

@sapiom/fetch, @sapiom/axios and @sapiom/node-http report request and response facts (method, URL, headers, status) with each transaction. Each integration kept its own short list of headers to leave out, and the three lists differed:

  • fetch / node-http requests left out authorization, cookie, x-api-key, x-auth-token;
  • axios requests left out any name containing auth / key / token;
  • all three responses left out only set-cookie, authorization, x-api-key.

So headers such as bt-api-key, api-key, x-goog-api-key or x-client-secret were reported by fetch and node-http. The URL and urlParsed.search were reported as sent, ?key=… / ?access_token=… / user:pass@ included. Facts describe a call; they should not carry the credentials it was made with.

Summary and scope

  • @sapiom/core: new utils/facts-sanitization.ts with one shared list.
    • isSensitiveHeaderName: authorization, proxy-authorization, cookies, sapiom-identity, payment-signature, x-payment*, names containing api-key / apikey / token / secret / password / credential / signature / auth, *-key, every bt-*, and x-sapiom-* key/token/signature headers.
    • isSensitiveQueryParam: key, api_key, apikey, token, access_token, secret, signature, sig, password, X-Amz-Signature, … (case-insensitive, decoded name).
    • sanitizeHeadersForFacts, sanitizeUrlForFacts: the latter masks those query values and user:pass@ as [REDACTED], keeping every other byte of the URL.
  • @sapiom/fetch, @sapiom/axios, @sapiom/node-http: request and response facts use the shared helpers; url and urlParsed.search are sanitized (axios's relative-URL fallback also keeps the query out of urlParsed.pathname). axios keeps its broader substring rule on top, so no header it left out before is reported now.
  • Only the facts change. The outgoing request keeps its real URL and headers; each new test asserts this against the mock server.
  • The list matches the one the Sapiom API applies when it stores facts (sapiom/Sapiom#6874), so older SDKs are covered server-side as well.
  • Out of scope: response bodies and LangChain facts (those report argumentKeys, never argument values).

Related work

Related issue or discussion: internal tracking (SAP-5145); server-side counterpart sapiom/Sapiom#6874.

Validation

pnpm --filter "@sapiom/core..." --filter "@sapiom/fetch..." --filter "@sapiom/axios..." --filter "@sapiom/node-http..." build — ok
packages/core      pnpm test — 218 passed
packages/fetch     pnpm test — 44 passed
packages/axios     pnpm test — 35 passed
packages/node-http pnpm test — 34 passed
eslint src --ext .ts (core, fetch, axios, node-http) — 0 errors (warnings pre-existing, untouched lines)
pnpm typecheck (core, fetch, axios, node-http) — ok
prettier --write on the changed files
New "Facts sanitization" tests against main's interceptors — fail in all three (facts carry ?key=FAKEKEY); pass on this branch

Tests and documentation

  • packages/core/src/utils/facts-sanitization.test.ts: header names (sensitive and kept), query parameters (masked and kept, e.g. keyword, author), URL masking (userinfo, fragment, bare search, unchanged URL), header records and iterables.
  • One Facts sanitization test each in the fetch (fetch-mock), axios (axios-mock-adapter) and node-http (nock) integration suites. Each covers a bt-api-key / api-key header, a ?key= URL and a response set-cookie, and asserts the facts are sanitized while the request sent is unchanged. All HTTP is mocked; no test opens a network connection.
  • JSDoc on the new exported helpers; packages/core/README.md gets a "What request facts contain" section.
  • Final runs used isolated cloud credentials (GOOGLE_APPLICATION_CREDENTIALS=/dev/null, empty CLOUDSDK_CONFIG, AWS config files /dev/null).

Compatibility and release impact

  • Breaking or externally visible changes: facts no longer include the listed headers, and report credential query values as [REDACTED]. A transaction's inferred resource name comes from the reported URL, so a URL with ?key=… now yields …?key=[REDACTED]…, the same across key rotations. The outgoing request is unchanged. @sapiom/core gains four exports.
  • Changeset: added (.changeset/facts-credential-sanitization.md: core minor, fetch / axios / node-http patch).

Security

  • I have not included secrets, credentials, private data, or unsanitized logs. (All fixtures are fake.)
  • This pull request does not publicly disclose a suspected vulnerability. I will follow the Security Policy for private reporting.
    • Left for a maintainer to confirm: this is hardening of what the SDK reports as telemetry, opened by the Sapiom team alongside the server-side change.

AI assistance

  • I did not use AI assistance for this change.
  • I used AI assistance and have described it below.

Claude Code (agent) wrote the shared helper, the call-site changes, the tests and the changeset. I checked each call site against main. I ran the new tests against main's interceptors (they fail: facts carry the raw ?key=) and on this branch (they pass), and ran build, typecheck, lint and the four packages' test suites.

Checklist

  • I read CONTRIBUTING.md, and this contribution follows the direct-PR or issue-first policy.
  • This pull request addresses one focused problem and contains no unrelated cleanup.
  • I added or updated tests, or explained above why tests are not applicable.
  • I ran the relevant build, typecheck, lint, and test commands, or explained any N/A checks above.
  • I updated documentation for user-facing changes, or marked it N/A above.
  • I added a Changeset for a published-package change, or explained why it is not applicable.
  • I can explain and maintain every submitted change, including any AI-assisted work.

…5145]

fetch, axios and node-http each kept their own short header list and reported the URL and its query string as sent. They now share one list in @sapiom/core that leaves out credential headers (bt-api-key, api-key and similar, matching the Sapiom API's stored-facts list) and masks credential query values and userinfo in url and urlParsed.search. Only the facts change; the outgoing request is unchanged.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The change adds shared sanitization utilities in @sapiom/core and applies them to request and response facts in Axios, Fetch, and Node HTTP. Integration tests check that recorded facts omit or redact credentials while outgoing requests retain their original URLs and headers.

Changes: HTTP Facts Sanitization

Layer / File(s) Summary
Shared sanitization utilities
packages/core/src/utils/facts-sanitization.ts, packages/core/src/utils/facts-sanitization.test.ts, packages/core/src/index.ts
Core adds and exports header and query sensitivity checks, plus header and URL sanitizers. Tests cover matching, redaction, preservation of other URL parts, and header filtering.
Request fact sanitization
packages/axios/src/interceptors.ts, packages/fetch/src/interceptors.ts, packages/node-http/src/interceptors.ts
The three clients sanitize request URL fields and headers before recording request facts. Fetch applies sanitization in both preemptive authorization and on-demand payment paths.
Response facts and integration coverage
packages/axios/src/interceptors.ts, packages/fetch/src/interceptors.ts, packages/node-http/src/interceptors.ts, packages/{axios,fetch,node-http}/src/http-client.integration.test.ts, .changeset/facts-credential-sanitization.md
Response facts use the shared header sanitizer. Integration tests check recorded request and response facts and confirm that outgoing requests retain their original credentials. The changeset documents package releases and sanitization behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant FetchInterceptors
  participant CoreSanitizers
  participant TransactionFacts
  participant HTTPRequest
  FetchInterceptors->>CoreSanitizers: Sanitize request URL and headers for facts
  CoreSanitizers-->>FetchInterceptors: Return sanitized values
  FetchInterceptors->>TransactionFacts: Record sanitized request facts
  FetchInterceptors->>HTTPRequest: Send request with original URL and headers
Loading

Suggested reviewers: gwitwer

Merge Risk: Moderate · up to b026f

This change redacts credentials from reported request facts. A relative axios URL without a baseURL can still report its query-string credential. The Sapiom-Identity token can be reported by fetch and node-http. A URL with an extra '@' in its password can leak part of that password. These should be fixed before merge. Outgoing requests are unaffected.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(core): share one header and URL sanitizer for request facts [SAP-5145]" matches the main change. The PR adds shared header and URL sanitization helpers in @sapiom/core and applies them …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template closely. It selects one primary change type (Bug fix) and fills in Problem and motivation, Summary and scope (including out-of-scope items), Related wor…
Full details: Title check

Explanation

The title "fix(core): share one header and URL sanitizer for request facts [SAP-5145]" matches the main change. The PR adds shared header and URL sanitization helpers in @sapiom/core and applies them to request and response facts in the fetch, axios, and node-http integrations. The title is concise and specific. It uses a conventional-commit prefix and a ticket reference, which are acceptable.

Full details: Description check

Explanation

The description follows the repository template closely. It selects one primary change type (Bug fix) and fills in Problem and motivation, Summary and scope (including out-of-scope items), Related work (internal tracking SAP-5145 and server-side counterpart sapiom/Sapiom#6874), Validation with exact commands and results, Tests and documentation, Compatibility and release impact (breaking-change behavior and changeset added), Security checklist, AI assistance disclosure, and the Checklist. The one gap is the Security vulnerability-disclosure checkbox, which is left unchecked with a note that a maintainer must confirm. The author also states that all fixtures are fake and that no secrets are included. The description is complete enough to pass, and the remaining item is a maintainer confirmation rather than missing content.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the headers with care,
And masks the secrets hiding there.
The facts stay neat, the request stays true,
The query’s credentials fade from view.
Three clients hop along the track,
While safe redactions guard the stack.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

…keep relative queries out of pathname [SAP-5145]
@AntoineMaillard06

Copy link
Copy Markdown
Contributor Author

Re the outside-diff comment on packages/axios/src/interceptors.ts:406 (relative-URL fallback): fixed in a77dc55. With no baseURL, the fallback now splits the endpoint at ?/#, so urlParsed.pathname is query-free and urlParsed.search is sanitized. The outgoing config is unchanged. Test: "keeps a relative URL's query out of urlParsed.pathname when there is no baseURL".

@devin-ai-integration devin-ai-integration Bot left a comment

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.

Devin Review found 1 new potential issue.

Devin Review

Comment thread packages/core/README.md Outdated

```typescript
import { SapiomClient } from '@sapiom/core';
import { SapiomClient } from "@sapiom/core";

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.

🟡 Unrelated README examples rewritten for formatting

Formatting Direct API Client and other existing examples rewrites snippets unrelated to the request-facts documentation. This adds review churn despite the contribution rule against drive-by cleanup.

Learn more

The contribution guide asks contributors to avoid drive-by cleanup. This README adds a request-facts section, but it also reformats existing examples throughout the file. The package's format script only covers TypeScript source, not this README. These unrelated edits make the substantive documentation change harder to review.

Example: The Direct API Client example changes its quote style, and the Axios example changes its layout, although neither example describes request facts.

Recommended fix: Restore the existing examples and other unrelated README lines; keep the new request-facts section and any edits needed for it.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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.

Fixed in aaa3e41. I restored packages/core/README.md from main and re-added only the "What request facts contain" section (+9 lines, nothing else changed). The same commit also reverts two unrelated prettier reflows in packages/fetch/src/interceptors.ts, so that file's diff is only the facts change.

This branch has not been deployed

No deployments
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