-
Notifications
You must be signed in to change notification settings - Fork 980
Fix/feedback preview xss #7532
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
Fix/feedback preview xss #7532
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fcb16c8
fix(star-rating): close stored XSS in feedback upload/preview
ar2rsawseen 6845c96
test(star-rating): unit tests for image-utils
ar2rsawseen 78ba21f
fix(security): defense-in-depth on image upload/serve routes
ar2rsawseen 2fc5236
fix(star-rating): address PR review comments
ar2rsawseen 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
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,59 @@ | ||
| /** | ||
| * Detect image MIME type by inspecting magic bytes. Does NOT trust | ||
| * any client-supplied or stored MIME string. Returns one of the | ||
| * allowlisted image MIME types, or null if the buffer is not a | ||
| * recognized safe image format. | ||
| * @param {Buffer} buf - file content | ||
| * @returns {string|null} MIME type or null if not a recognized image | ||
| */ | ||
| function sniffImageType(buf) { | ||
| if (!buf || buf.length < 12) { | ||
| return null; | ||
| } | ||
| // PNG: 89 50 4E 47 0D 0A 1A 0A | ||
| if (buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4E && buf[3] === 0x47 | ||
| && buf[4] === 0x0D && buf[5] === 0x0A && buf[6] === 0x1A && buf[7] === 0x0A) { | ||
| return 'image/png'; | ||
| } | ||
| // JPEG: FF D8 FF | ||
| if (buf[0] === 0xFF && buf[1] === 0xD8 && buf[2] === 0xFF) { | ||
| return 'image/jpeg'; | ||
| } | ||
| // GIF87a / GIF89a: 47 49 46 38 (37|39) 61 | ||
| if (buf[0] === 0x47 && buf[1] === 0x49 && buf[2] === 0x46 && buf[3] === 0x38 | ||
| && (buf[4] === 0x37 || buf[4] === 0x39) && buf[5] === 0x61) { | ||
| return 'image/gif'; | ||
| } | ||
| // WebP: "RIFF" .... "WEBP" | ||
| if (buf[0] === 0x52 && buf[1] === 0x49 && buf[2] === 0x46 && buf[3] === 0x46 | ||
| && buf[8] === 0x57 && buf[9] === 0x45 && buf[10] === 0x42 && buf[11] === 0x50) { | ||
| return 'image/webp'; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| // Allowed feedback logo names: the literal global "feedback_logo" or | ||
| // "feedback_logo<24-char-hex-app-id>" for per-app logos. | ||
| var FEEDBACK_LOGO_NAME_RE = /^feedback_logo([a-f0-9]{24})?$/; | ||
|
|
||
| /** | ||
| * Validate a feedback logo name and, if it's a per-app logo, return | ||
| * the app id encoded in it. | ||
| * @param {string} name - candidate name | ||
| * @returns {object} parse result with `valid`, `isGlobal`, and `appId` fields | ||
| */ | ||
| function parseFeedbackLogoName(name) { | ||
| if (typeof name !== 'string') { | ||
| return {valid: false, isGlobal: false, appId: null}; | ||
| } | ||
| var m = FEEDBACK_LOGO_NAME_RE.exec(name); | ||
| if (!m) { | ||
| return {valid: false, isGlobal: false, appId: null}; | ||
| } | ||
| return {valid: true, isGlobal: !m[1], appId: m[1] || null}; | ||
| } | ||
|
|
||
| module.exports = { | ||
| sniffImageType: sniffImageType, | ||
| parseFeedbackLogoName: parseFeedbackLogoName | ||
| }; |
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.