-
Notifications
You must be signed in to change notification settings - Fork 13.9k
feat(apps): ad-hoc redaction for apps logs #40096
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
87a2a1e
feat: add redaction to apps logs
d-gubert 33f9de1
feat: add new lib file for the app redactor
d-gubert 0a96d97
refactor: use redactor function from lib
d-gubert 0140681
refactor: change redaction to explicit paths instead of recursive
d-gubert 68b66b4
refactor: change apps logger to use the redaction paths
d-gubert 1abcf9e
refactor: adapt debug logs in persistence bridge
d-gubert c7e0cf6
feat: add censorUrl to tools package
d-gubert a0e0ec5
test(tools): add comprehensive unit tests for censorUrl
Copilot 5e09194
test(tools): cover relative URL and URL object immutability
Copilot 40a8c30
add changeset
d-gubert 0b48b18
refactor: group data in debug log call
d-gubert 9f0c0e5
refactor: add options to logger package
d-gubert 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,5 @@ | ||
| --- | ||
| '@rocket.chat/server-fetch': minor | ||
| --- | ||
|
|
||
| Introduces redaction of potentially sensitive data when logging request URLs |
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,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Introduces redaction of potentially sensitive data in logs related to apps-engine |
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,5 @@ | ||
| --- | ||
| '@rocket.chat/tools': minor | ||
| --- | ||
|
|
||
| Adds new function for censoring URL components in logs |
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,42 @@ | ||
| import fastRedact from 'fast-redact'; | ||
|
|
||
| const requestFields = [ | ||
| 'headers.Cookie', | ||
| 'headers.cookie', | ||
| 'headers["x-auth-token"]', | ||
| 'headers["X-Auth-Token"]', | ||
| 'headers.auth', | ||
| 'headers.Auth', | ||
| 'headers.authorization', | ||
| 'headers.Authorization', | ||
| 'headers.access_token', | ||
| 'content.password', | ||
| 'content.pass', | ||
| 'data.password', | ||
| 'data.pass', | ||
| ]; | ||
|
|
||
| const entityFields = ['password', 'pass', 'customFields.*', '_unmappedProperties_']; | ||
|
|
||
| const roomFields = ['customFields.*', '_unmappedProperties_', ...entityFields.map((field) => `creator.${field}`)]; | ||
|
|
||
| export const redactionFieldPaths = [ | ||
| // Incoming requests to the Apps API endpoints | ||
| ...requestFields, | ||
| ...entityFields.map((field) => `user.${field}`), | ||
| 'query.access_token', | ||
| 'query.query', // The deprecated `query` search param | ||
| // Outgoing requests from the Apps to the outter webs | ||
| ...requestFields.map((field) => `request.${field}`), | ||
| `request.query`, // `query` here is a string, so we have to redact it all | ||
| // Slashcommands | ||
| ...roomFields.map((field) => `params[0].room.${field}`), | ||
| ...entityFields.map((field) => `params[0].sender.${field}`), | ||
| ]; | ||
|
|
||
| export const redact = fastRedact({ | ||
| paths: redactionFieldPaths, | ||
| censor: '[Redacted]', | ||
| serialize: false, | ||
| strict: false, | ||
| }); | ||
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
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,53 @@ | ||
| import { censorUrl } from './censorUrl'; | ||
|
|
||
| describe('censorUrl', () => { | ||
|
d-gubert marked this conversation as resolved.
|
||
| it('returns the original value when URL parsing fails', () => { | ||
| const input = 'not-a-url'; | ||
|
|
||
| expect(censorUrl(input)).toBe(input); | ||
| }); | ||
|
|
||
| it('returns relative URLs unchanged when no base is provided', () => { | ||
| const input = '/path/to/resource?query=secret&access_token=token'; | ||
|
|
||
| expect(censorUrl(input)).toBe(input); | ||
| }); | ||
|
|
||
| it('does not change URLs without sensitive parts', () => { | ||
| expect(censorUrl('https://example.com/path?foo=bar')).toBe('https://example.com/path?foo=bar'); | ||
| }); | ||
|
|
||
| it('redacts username and password from auth section', () => { | ||
| expect(censorUrl('https://user:password@example.com/path')).toBe('https://*Redacted*:*Redacted*@example.com/path'); | ||
| }); | ||
|
|
||
| it('redacts only username when password is not present', () => { | ||
| expect(censorUrl('https://user@example.com/path')).toBe('https://*Redacted*@example.com/path'); | ||
| }); | ||
|
|
||
| it('redacts query and access_token search params', () => { | ||
| expect(censorUrl('https://example.com/path?query=secret&access_token=token&foo=bar')).toBe( | ||
| 'https://example.com/path?query=*Redacted*&access_token=*Redacted*&foo=bar', | ||
| ); | ||
| }); | ||
|
|
||
| it('redacts access_token even when query is absent', () => { | ||
| expect(censorUrl('https://example.com/path?access_token=token&foo=bar')).toBe( | ||
| 'https://example.com/path?access_token=*Redacted*&foo=bar', | ||
| ); | ||
| }); | ||
|
|
||
| it('accepts URL objects as input', () => { | ||
| expect(censorUrl(new URL('https://user:password@example.com/path?query=secret'))).toBe( | ||
| 'https://*Redacted*:*Redacted*@example.com/path?query=*Redacted*', | ||
| ); | ||
| }); | ||
|
|
||
| it('does not modify the original URL object', () => { | ||
| const input = new URL('https://user:password@example.com/path?query=secret&access_token=token'); | ||
| const originalValue = input.toString(); | ||
|
|
||
| expect(censorUrl(input)).toBe('https://*Redacted*:*Redacted*@example.com/path?query=*Redacted*&access_token=*Redacted*'); | ||
| expect(input.toString()).toBe(originalValue); | ||
| }); | ||
| }); | ||
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,45 @@ | ||
| /** | ||
| * Redacts sensitive information from a URL string. | ||
| * | ||
| * This function parses a URL and replaces potentially sensitive data with placeholder text. | ||
| * It redacts the following URL components: | ||
| * - Username in the authentication section | ||
| * - Password in the authentication section | ||
| * - Query parameters named: 'query', 'access_token' | ||
| * | ||
| * Note: We use `*Redacted*` instead of `[Redacted]` for legibility, as `[` and `]` would be encoded by toString() | ||
| * | ||
| * @param url - The URL string to be censored | ||
| * @returns The URL string with sensitive information redacted, or the original URL if parsing fails | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * censorUrl('https://user:password@example.com/path?query=secret&access_token=token'); | ||
| * // Returns: 'https://*Redacted*:*Redacted*@example.com/path?query=*Redacted*&access_token=*Redacted*' | ||
| * ``` | ||
| */ | ||
| export function censorUrl(url: string | URL): string { | ||
| try { | ||
| const parsedUrl = new URL(url); | ||
|
d-gubert marked this conversation as resolved.
|
||
|
|
||
| if (parsedUrl.username) { | ||
| parsedUrl.username = '*Redacted*'; | ||
| } | ||
|
|
||
| if (parsedUrl.password) { | ||
| parsedUrl.password = '*Redacted*'; | ||
| } | ||
|
|
||
| if (parsedUrl.searchParams.has('query')) { | ||
| parsedUrl.searchParams.set('query', '*Redacted*'); | ||
| } | ||
|
|
||
| if (parsedUrl.searchParams.has('access_token')) { | ||
| parsedUrl.searchParams.set('access_token', '*Redacted*'); | ||
| } | ||
|
|
||
| return parsedUrl.toString(); | ||
| } catch { | ||
| return url.toString(); | ||
| } | ||
| } | ||
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.