Repository navigation
fix(server): redact credentials in request logs #33682
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { IncomingHttpHeaders } from 'node:http'; | ||
| import { UAParser } from 'ua-parser-js'; | ||
| import { ImmichQuery } from 'src/enum.js'; | ||
|
|
||
| export const fromChecksum = (checksum: string): Buffer => { | ||
| return Buffer.from(checksum, checksum.length === 28 ? 'base64' : 'hex'); | ||
|
|
@@ -41,3 +42,15 @@ export const isCrossOriginRequest = (headers: IncomingHttpHeaders, method?: stri | |
|
|
||
| return !URL.canParse(origin) || new URL(origin).host !== host; | ||
| }; | ||
|
|
||
| export const REDACTED = '********'; | ||
|
|
||
| const SENSITIVE_QUERY_PARAMS = [...Object.values(ImmichQuery), 'code']; | ||
| const sensitiveQueryParamRegex = new RegExp(`([?&](?:${SENSITIVE_QUERY_PARAMS.join('|')})=)[^&#]*`, 'g'); | ||
|
|
||
| export const redactUrl = (url: string) => | ||
| url.replaceAll(sensitiveQueryParamRegex, (_, prefix: string) => prefix + REDACTED); | ||
|
|
||
| const SENSITIVE_KEYS = ['password', 'pincode', 'secret', 'token', 'verifier', 'licensekey', 'activationkey']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why these keys and the ones on the spec are different ? e.g. pincode vs pinCode
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comparison is case insensitive by making it lowercase before comparing. |
||
|
|
||
| export const isSensitiveKey = (key: string) => SENSITIVE_KEYS.some((item) => key.toLowerCase().includes(item)); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See other comment