Repository navigation
fix(core): share one header and URL sanitizer for request facts [SAP-5145] - #1313
AntoineMaillard06 wants to merge 3 commits into
Conversation
…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.
Walkthrough
Merge Risk:
|
…keep relative queries out of pathname [SAP-5145]
|
Re the outside-diff comment on |
|
|
||
| ```typescript | ||
| import { SapiomClient } from '@sapiom/core'; | ||
| import { SapiomClient } from "@sapiom/core"; |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
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.
Primary change type
Problem and motivation
@sapiom/fetch,@sapiom/axiosand@sapiom/node-httpreport 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:authorization,cookie,x-api-key,x-auth-token;auth/key/token;set-cookie,authorization,x-api-key.So headers such as
bt-api-key,api-key,x-goog-api-keyorx-client-secretwere reported by fetch and node-http. The URL andurlParsed.searchwere 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: newutils/facts-sanitization.tswith one shared list.isSensitiveHeaderName:authorization,proxy-authorization, cookies,sapiom-identity,payment-signature,x-payment*, names containingapi-key/apikey/token/secret/password/credential/signature/auth,*-key, everybt-*, andx-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 anduser: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;urlandurlParsed.searchare sanitized (axios's relative-URL fallback also keeps the query out ofurlParsed.pathname). axios keeps its broader substring rule on top, so no header it left out before is reported now.argumentKeys, never argument values).Related work
Related issue or discussion: internal tracking (SAP-5145); server-side counterpart sapiom/Sapiom#6874.
Validation
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.Facts sanitizationtest each in the fetch (fetch-mock), axios (axios-mock-adapter) and node-http (nock) integration suites. Each covers abt-api-key/api-keyheader, a?key=URL and a responseset-cookie, and asserts the facts are sanitized while the request sent is unchanged. All HTTP is mocked; no test opens a network connection.packages/core/README.mdgets a "What request facts contain" section.GOOGLE_APPLICATION_CREDENTIALS=/dev/null, emptyCLOUDSDK_CONFIG, AWS config files/dev/null).Compatibility and release impact
[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/coregains four exports..changeset/facts-credential-sanitization.md: core minor, fetch / axios / node-http patch).Security
AI assistance
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
CONTRIBUTING.md, and this contribution follows the direct-PR or issue-first policy.