-
Notifications
You must be signed in to change notification settings - Fork 30
fix(scheduled): enforce XSS sanitization & Cloudinary validation for scheduled messages #584
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
Closed
harrshita123
wants to merge
4
commits into
UTKARSHH20:main
from
harrshita123:fix/scheduled-message-security
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ee2cfcd
fix(scheduled): enforce XSS sanitization & Cloudinary validation for …
harrshita123 c985918
Revert "fix(scheduled): enforce XSS sanitization & Cloudinary validat…
harrshita123 18c8049
Reapply "fix(scheduled): enforce XSS sanitization & Cloudinary valida…
harrshita123 6d48ae6
fix(scheduled): resolve CodeRabbit review comments
harrshita123 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Attachment validation utilities shared between live message handling and scheduled messages. | ||
| * These functions validate Base64 data URLs for images and audio files, enforce MIME allow‑lists, | ||
| * and ensure size limits (5 MB for images, 10 MB for audio). They return an object | ||
| * { isValid: boolean, error?: string }. | ||
| */ | ||
|
|
||
| export const validateImageAttachment = (base64Str, maxSizeBytes = 5 * 1024 * 1024) => { | ||
| if (typeof base64Str !== 'string' || !base64Str) return { isValid: false, error: "Invalid file format structure or corrupt payload." }; | ||
| // Verify Data URL format | ||
| const match = base64Str.match(/^data:([^;]+);base64,(.+)$/); | ||
| if (!match) { | ||
| return { isValid: false, error: "Invalid file format structure or corrupt payload." }; | ||
| } | ||
| const mimeType = match[1]; | ||
| const rawData = match[2]; | ||
| const ALLOWED_MIME_TYPES = ["image/jpeg", "image/png", "image/webp", "image/gif"]; | ||
| if (!ALLOWED_MIME_TYPES.includes(mimeType.toLowerCase())) { | ||
| return { isValid: false, error: "Unsupported image signature type. Allowed formats: JPEG, PNG, WEBP, GIF." }; | ||
| } | ||
| // Estimate binary size | ||
| const binarySizeEstimate = Math.floor((rawData.length * 3) / 4) - (rawData.endsWith("==") ? 2 : rawData.endsWith("=") ? 1 : 0); | ||
| if (binarySizeEstimate > maxSizeBytes) { | ||
| return { isValid: false, error: "File boundary limit exceeded. Image size must be under 5MB." }; | ||
| } | ||
| return { isValid: true }; | ||
| }; | ||
|
|
||
| export const validateAudioAttachment = (base64Str, maxSizeBytes = 10 * 1024 * 1024) => { | ||
| if (typeof base64Str !== 'string' || !base64Str) return { isValid: false, error: "Invalid audio format structure or corrupt payload." }; | ||
| const match = base64Str.match(/^data:([^;]+);base64,(.+)$/); | ||
| if (!match) { | ||
| return { isValid: false, error: "Invalid audio format structure or corrupt payload." }; | ||
| } | ||
| const mimeType = match[1]; | ||
| const rawData = match[2]; | ||
| const ALLOWED_MIME_TYPES = [ | ||
| "audio/webm", | ||
| "audio/mp3", | ||
| "audio/wav", | ||
| "audio/mpeg", | ||
| "audio/ogg", | ||
| "audio/x-m4a", | ||
| "audio/m4a", | ||
| ]; | ||
| if (!ALLOWED_MIME_TYPES.includes(mimeType.toLowerCase())) { | ||
| return { isValid: false, error: "Unsupported audio format. Allowed formats: WEBM, MP3, WAV, OGG, M4A." }; | ||
| } | ||
| const binarySizeEstimate = Math.floor((rawData.length * 3) / 4) - (rawData.endsWith("==") ? 2 : rawData.endsWith("=") ? 1 : 0); | ||
| if (binarySizeEstimate > maxSizeBytes) { | ||
| return { isValid: false, error: "Audio size exceeds the 10MB limit." }; | ||
| } | ||
| return { isValid: true }; | ||
| }; | ||
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
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.