-
Notifications
You must be signed in to change notification settings - Fork 0
[Cycode] Fix for SAST detections - Unsanitized user input in dynamic HTML insertion (XSS) #5
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
base: main
Are you sure you want to change the base?
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,3 +1,4 @@ | ||||||||||
|
|
||||||||||
| webgoat.customjs.profileUpload = function () { | ||||||||||
|
|
||||||||||
| var picture = document.getElementById("uploadedFile").files[0]; | ||||||||||
|
|
@@ -8,10 +9,12 @@ | |||||||||
| formData.append("password", $("#password").val()); | ||||||||||
| return formData; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| webgoat.customjs.profileUploadCallback = function () { | ||||||||||
| $.get("PathTraversal/profile-picture", function (result, status) { | ||||||||||
| document.getElementById("preview").src = "data:image/png;base64," + result; | ||||||||||
| var base64String = "data:image/png;base64," + result; | ||||||||||
| var sanitizedBase64String = sanitizeHtml(base64String); | ||||||||||
| document.getElementById("preview").src = sanitizedBase64String; | ||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -27,7 +30,9 @@ | |||||||||
|
|
||||||||||
| webgoat.customjs.profileUploadCallbackFix = function () { | ||||||||||
| $.get("PathTraversal/profile-picture", function (result, status) { | ||||||||||
| document.getElementById("previewFix").src = "data:image/png;base64," + result; | ||||||||||
| var base64String = "data:image/png;base64," + result; | ||||||||||
| var sanitizedBase64String = sanitizeHtml(base64String); | ||||||||||
| document.getElementById("previewFix").src = sanitizedBase64String; | ||||||||||
|
cycode-security[bot] marked this conversation as resolved.
|
||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -36,7 +41,7 @@ | |||||||||
| var picture = document.getElementById("uploadedFileRemoveUserInput").files[0]; | ||||||||||
| var formData = new FormData(); | ||||||||||
| formData.append("uploadedFileRemoveUserInput", picture); | ||||||||||
| formData.append("fullName", $("#fullNameRemoveUserInput").val()); | ||||||||||
| formData.append("email", $("#emailRemoveUserInput").val()); | ||||||||||
| formData.append("password", $("#passwordRemoveUserInput").val()); | ||||||||||
| return formData; | ||||||||||
|
|
@@ -44,20 +49,26 @@ | |||||||||
|
|
||||||||||
| webgoat.customjs.profileUploadCallbackRemoveUserInput = function () { | ||||||||||
| $.get("PathTraversal/profile-picture", function (result, status) { | ||||||||||
| document.getElementById("previewRemoveUserInput").src = "data:image/png;base64," + result; | ||||||||||
| var base64String = "data:image/png;base64," + result; | ||||||||||
| var sanitizedBase64String = sanitizeHtml(base64String); | ||||||||||
| document.getElementById("previewRemoveUserInput").src = sanitizedBase64String; | ||||||||||
|
Author
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. ❗Cycode: SAST violation: 'Unsanitized user input in dynamic HTML insertion (XSS)'. Severity: High DescriptionUnsanitized user input in dynamic HTML insertion can lead to Cross-Site Scripting (XSS) attacks. This vulnerability arises when user-provided data is directly inserted into the DOM without proper sanitization, potentially allowing attackers to execute malicious scripts. Cycode Remediation Guideline✅ Do
import sanitizeHtml from 'sanitize-html';
const html = `<strong>${user.Input}</strong>`;
document.body.innerHTML = sanitizeHtml(html);📋 References🎥 Learning materials (by Secure Code Warrior)Tell us how you wish to proceed using one of the following commands:
|
||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| webgoat.customjs.profileUploadCallbackRetrieval = function () { | ||||||||||
| $.get("PathTraversal/profile-picture", function (result, status) { | ||||||||||
| document.getElementById("previewRetrieval").src = "data:image/png;base64," + result; | ||||||||||
| var base64String = "data:image/png;base64," + result; | ||||||||||
| var sanitizedBase64String = sanitizeHtml(base64String); | ||||||||||
| document.getElementById("previewRetrieval").src = sanitizedBase64String; | ||||||||||
|
Author
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. ❗Cycode: SAST violation: 'Unsanitized user input in dynamic HTML insertion (XSS)'. Severity: High DescriptionUnsanitized user input in dynamic HTML insertion can lead to Cross-Site Scripting (XSS) attacks. This vulnerability arises when user-provided data is directly inserted into the DOM without proper sanitization, potentially allowing attackers to execute malicious scripts. Cycode Remediation Guideline✅ Do
import sanitizeHtml from 'sanitize-html';
const html = `<strong>${user.Input}</strong>`;
document.body.innerHTML = sanitizeHtml(html);📋 References🎥 Learning materials (by Secure Code Warrior)Tell us how you wish to proceed using one of the following commands:
|
||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function newRandomPicture() { | ||||||||||
| $.get("PathTraversal/random-picture", function (result, status) { | ||||||||||
| document.getElementById("randomCatPicture").src = "data:image/png;base64," + result; | ||||||||||
| var base64String = "data:image/png;base64," + result; | ||||||||||
| var sanitizedBase64String = sanitizeHtml(base64String); | ||||||||||
| document.getElementById("randomCatPicture").src = sanitizedBase64String; | ||||||||||
|
Author
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. ❗Cycode: SAST violation: 'Unsanitized user input in dynamic HTML insertion (XSS)'. Severity: High DescriptionUnsanitized user input in dynamic HTML insertion can lead to Cross-Site Scripting (XSS) attacks. This vulnerability arises when user-provided data is directly inserted into the DOM without proper sanitization, potentially allowing attackers to execute malicious scripts. Cycode Remediation Guideline✅ Do
import sanitizeHtml from 'sanitize-html';
const html = `<strong>${user.Input}</strong>`;
document.body.innerHTML = sanitizeHtml(html);📋 References🎥 Learning materials (by Secure Code Warrior)Tell us how you wish to proceed using one of the following commands:
|
||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
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.
❗Cycode: SAST violation: 'Unsanitized user input in dynamic HTML insertion (XSS)'.
Severity: High
Description
Unsanitized user input in dynamic HTML insertion can lead to Cross-Site Scripting (XSS) attacks. This vulnerability arises when user-provided data is directly inserted into the DOM without proper sanitization, potentially allowing attackers to execute malicious scripts.
Cycode Remediation Guideline
✅ Do
📋 References
🎥 Learning materials (by Secure Code Warrior)
Tell us how you wish to proceed using one of the following commands: