fix(security): sanitize notification HTML to prevent XSS. #3126
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.
This pull request updates dependencies and enhances security in the notifications component. The most significant change is the introduction of the
dompurifylibrary to sanitize HTML content in notifications, which helps prevent XSS attacks. Additionally, several dependency versions are updated in the lockfile.Security Improvements:
NotificationsListcomponent now sanitizes notification bodies usingDOMPurifybefore rendering HTML, reducing the risk of cross-site scripting (XSS) vulnerabilities. [1] [2]Dependency Updates:
dompurifyas a production dependency in bothpackage.jsonandpackage-lock.json. [1] [2] [3] [4]@types/trusted-typesto version 2.0.7 inpackage-lock.jsonfor compatibility withdompurify. [1] [2]http-proxy-middlewarefrom devDependencies to dependencies inpackage-lock.json. [1] [2]Description
This PR fixes a Cross-Site Scripting (XSS) vulnerability in the notifications display component. The
NotificationsList.jsxcomponent was usingdangerouslySetInnerHTMLto render notification bodies as raw HTML without any client-side sanitization.Vulnerability: Malicious scripts (e.g.,
<script>alert('XSS')</script>or<img src="x" onerror="...">) could execute in the user's browser, potentially allowing attackers to steal session tokens, perform actions on behalf of users, or redirect to malicious sites.Fix: Added DOMPurify library to sanitize HTML content before rendering, stripping dangerous scripts and event handlers while preserving safe HTML tags.
Changes:
dompurifydependency topackage.jsonNotificationsList.jsxnotif?.bodywithDOMPurify.sanitize()before renderingType of change
Checklist
developdompurifyis the industry-standard library for HTML sanitization in JavaScript. It is strictly necessary to properly fix this XSS vulnerability.Black,Flake,Isort) gave 0 errors. ESLint passed with no errors.testsfolder). All the tests (new and old ones) gave 0 errors.DeepSource,Django Doctorsor other third-party linters have triggered any alerts during the CI checks, I have solved those alerts.Security Impact
<b>,<i>,<a>,<p>, etc. preservedFiles Changed
frontend/package.jsondompurify: ^3.3.1frontend/package-lock.jsonfrontend/src/components/jobs/notification/NotificationsList.jsxRelated issue : #3123