Repository navigation
fix(core): share one header and URL sanitizer for request facts [SAP-5145] #1313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AntoineMaillard06
wants to merge
3
commits into
main
Choose a base branch
from
antoinemaillard/sap-5145-sdk-denylist
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b026f45
fix(core): share one header and URL sanitizer for request facts [SAP-…
AntoineMaillard06 a77dc55
fix(core): leave Sapiom-Identity out of facts, mask userinfo with @, …
AntoineMaillard06 aaa3e41
docs(core): keep the README change to the request-facts section [SAP-…
AntoineMaillard06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "@sapiom/core": minor | ||
| "@sapiom/fetch": patch | ||
| "@sapiom/axios": patch | ||
| "@sapiom/node-http": patch | ||
| --- | ||
|
|
||
| Request and response facts now share one header and URL sanitizer. `@sapiom/fetch`, `@sapiom/axios` and `@sapiom/node-http` leave out the same credential headers (`authorization`, cookies, `x-api-key`, `api-key`, `bt-api-key` and other `*-api-key` / `*token*` / `*secret*` / `*password*` headers, payment signatures, `x-sapiom-*` key and token headers), and mask credential query values (`key`, `api_key`, `token`, `access_token`, `signature`, `sig`, `password`, …) and `user:pass@` in the reported `url` and `urlParsed.search`. Only the facts change: the outgoing request is sent exactly as before. `@sapiom/core` exports the helpers (`sanitizeHeadersForFacts`, `sanitizeUrlForFacts`, `isSensitiveHeaderName`, `isSensitiveQueryParam`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import { | ||
| REDACTED_FACT_VALUE, | ||
| isSensitiveHeaderName, | ||
| isSensitiveQueryParam, | ||
| sanitizeHeadersForFacts, | ||
| sanitizeUrlForFacts, | ||
| } from "./facts-sanitization"; | ||
|
|
||
| describe("facts sanitization", () => { | ||
| describe("isSensitiveHeaderName", () => { | ||
| it.each([ | ||
| "authorization", | ||
| "Authorization", | ||
| "proxy-authorization", | ||
| "cookie", | ||
| "set-cookie", | ||
| "payment-signature", | ||
| "x-payment", | ||
| "x-api-key", | ||
| "api-key", | ||
| "apikey", | ||
| "bt-api-key", | ||
| "BT-Trace-Id", | ||
| "x-goog-api-key", | ||
| "x-auth-token", | ||
| "x-client-secret", | ||
| "x-db-password", | ||
| "x-license-key", | ||
| "x-sapiom-api-key", | ||
| "x-sapiom-service-key", | ||
| "x-sapiom-signature", | ||
| "x-sapiom-workflow-token", | ||
| "Sapiom-Identity", | ||
| ])("leaves out %s", (name) => { | ||
| expect(isSensitiveHeaderName(name)).toBe(true); | ||
| }); | ||
|
|
||
| it.each([ | ||
| "content-type", | ||
| "accept", | ||
| "user-agent", | ||
| "x-request-id", | ||
| "x-sapiom-transaction-id", | ||
| "x-sapiom-trace-id", | ||
| ])("keeps %s", (name) => { | ||
| expect(isSensitiveHeaderName(name)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isSensitiveQueryParam", () => { | ||
| it.each([ | ||
| "key", | ||
| "KEY", | ||
| "api_key", | ||
| "apikey", | ||
| "token", | ||
| "access_token", | ||
| "secret", | ||
| "signature", | ||
| "sig", | ||
| "password", | ||
| "X-Amz-Signature", | ||
| "api%5Fkey", | ||
| ])("masks %s", (name) => { | ||
| expect(isSensitiveQueryParam(name)).toBe(true); | ||
| }); | ||
|
|
||
| it.each(["q", "limit", "keyword", "monkey", "author"])( | ||
| "keeps %s", | ||
| (name) => { | ||
| expect(isSensitiveQueryParam(name)).toBe(false); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| describe("sanitizeUrlForFacts", () => { | ||
| it("masks credential query values and keeps every other part as it was", () => { | ||
| expect( | ||
| sanitizeUrlForFacts( | ||
| "https://api.example.com/v1/geocode?key=abc123&address=Paris&access_token=t#top", | ||
| ), | ||
| ).toBe( | ||
| `https://api.example.com/v1/geocode?key=${REDACTED_FACT_VALUE}&address=Paris&access_token=${REDACTED_FACT_VALUE}#top`, | ||
| ); | ||
| }); | ||
|
|
||
| it("masks userinfo", () => { | ||
| expect( | ||
| sanitizeUrlForFacts("https://alice:hunter2@api.example.com/x"), | ||
| ).toBe(`https://${REDACTED_FACT_VALUE}@api.example.com/x`); | ||
| }); | ||
|
|
||
| it("masks a password that itself contains @, and not an @ in the query", () => { | ||
| expect( | ||
| sanitizeUrlForFacts("https://alice:p@ss@api.example.com/x?q=a@b"), | ||
| ).toBe(`https://${REDACTED_FACT_VALUE}@api.example.com/x?q=a@b`); | ||
| expect(sanitizeUrlForFacts("https://api.example.com/x?q=a@b")).toBe( | ||
| "https://api.example.com/x?q=a@b", | ||
| ); | ||
| }); | ||
|
|
||
| it("works on a bare search string", () => { | ||
| expect(sanitizeUrlForFacts("?token=abc&q=1")).toBe( | ||
| `?token=${REDACTED_FACT_VALUE}&q=1`, | ||
| ); | ||
| expect(sanitizeUrlForFacts("")).toBe(""); | ||
| }); | ||
|
|
||
| it("returns a URL with nothing to mask unchanged", () => { | ||
| const url = "https://api.example.com/search?q=a%20b&limit=10&keyword=k"; | ||
| expect(sanitizeUrlForFacts(url)).toBe(url); | ||
| }); | ||
| }); | ||
|
|
||
| describe("sanitizeHeadersForFacts", () => { | ||
| it("drops sensitive headers from a record and stringifies the rest", () => { | ||
| expect( | ||
| sanitizeHeadersForFacts({ | ||
| "bt-api-key": "k", | ||
| "api-key": "k", | ||
| Authorization: "Bearer t", | ||
| "content-type": "application/json", | ||
| "content-length": 42, | ||
| "x-empty": undefined, | ||
| }), | ||
| ).toEqual({ "content-type": "application/json", "content-length": "42" }); | ||
| }); | ||
|
|
||
| it("accepts a Headers entries iterable", () => { | ||
| const headers = new Map<string, string>([ | ||
| ["set-cookie", "sid=1"], | ||
| ["accept", "*/*"], | ||
| ]); | ||
| expect(sanitizeHeadersForFacts(headers.entries())).toEqual({ | ||
| accept: "*/*", | ||
| }); | ||
| }); | ||
|
|
||
| it("applies an extra exclusion on top of the shared list", () => { | ||
| expect( | ||
| sanitizeHeadersForFacts( | ||
| { "x-idempotency-key-id": "1", accept: "*/*" }, | ||
| (name) => name.includes("key"), | ||
| ), | ||
| ).toEqual({ accept: "*/*" }); | ||
| }); | ||
|
|
||
| it("returns an empty record for no headers", () => { | ||
| expect(sanitizeHeadersForFacts(undefined)).toEqual({}); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.