Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/core/src/utils/data-collection/filterQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CollectBehavior } from '../../types/datacollection';
import { FILTERED_VALUE } from './filtering-snippets';
import { FILTERED_VALUE, SENSITIVE_URL_PARAM_SNIPPETS } from './filtering-snippets';
import { shouldFilterDataKey } from './filterKeyValueData';

/**
Expand All @@ -12,7 +12,9 @@ export function filterQueryPair(pair: string, behavior: CollectBehavior): string
const encodedKey = separatorIndex === -1 ? pair : pair.slice(0, separatorIndex);
const key = new URLSearchParams(`${encodedKey}=`).keys().next().value;

return key !== undefined && shouldFilterDataKey(key, behavior) ? `${encodedKey}=${FILTERED_VALUE}` : pair;
return key !== undefined && shouldFilterDataKey(key, behavior, SENSITIVE_URL_PARAM_SNIPPETS)
? `${encodedKey}=${FILTERED_VALUE}`
: pair;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/utils/data-collection/filtering-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export const SENSITIVE_KEY_SNIPPETS = [
'cookie',
];

/**
* Extra substrings matched only against URL query and fragment parameter names. `code` carries OAuth
* authorization codes there, but as a general term it would also filter keys like `statusCode` or `zipcode`
* in headers and local variables.
*/
export const SENSITIVE_URL_PARAM_SNIPPETS = ['code'];

/**
* Extra substrings matched only against individual Cookie / Set-Cookie **names** (not header names),
* so we can cover common session secrets that do not match {@link SENSITIVE_KEY_SNIPPETS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ describe('filterKeyValueData', () => {
const result = filterKeyValueData(data, true);
expect(result[headerName]).toBe('[Filtered]');
});

it('does not filter keys that only match the URL-only `code` term', () => {
const data = { statusCode: 200, 'X-Country-Code': 'AT' };
expect(filterKeyValueData(data, true)).toEqual(data);
});
});

describe('non-string values', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('filterQueryParams', () => {

expect(result).toBe('auth=[Filtered]&redirect=/home');
});

it('filters OAuth authorization codes', () => {
const result = filterQueryParams('code=abc123&state=xyz', true);

expect(result).toBe('code=[Filtered]&state=xyz');
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Feat PR lacks integration coverage

Low Severity

This feat PR only adds unit tests for the new code URL-param filtering. Review guidelines ask feat PRs to include at least one integration or E2E test of the user-visible behavior. Existing suites already assert token redaction, so they would not catch a regression of this term. This was flagged because it was mentioned in the review rules file.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 1c77b0c. Configure here.

});

describe('denyList mode ({ deny: [...] })', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ describe('filterUrlFragment', () => {
expect(filterUrlFragment('/a?token=abc?b', true)).toBe('/a?token=[Filtered]');
});

it('filters OAuth authorization codes', () => {
expect(filterUrlFragment('code=abc123&state=xyz', true)).toBe('code=[Filtered]&state=xyz');
});

it('keeps anchors and hash route paths as-is', () => {
expect(filterUrlFragment('details', true)).toBe('details');
expect(filterUrlFragment('/settings', true)).toBe('/settings');
Expand Down
Loading