Skip to content

Commit

Permalink
Fix potential xss in admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
mpysiak committed May 9, 2024
1 parent 9b7e954 commit d4812f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import 'semantic-ui-css/components/api';
import 'semantic-ui-css/components/checkbox';
import $ from 'jquery';
import { sanitizeInput} from "./sylius-sanitizer";

const createRootContainer = function createRootContainer() {
return $('<div class="ui list"></div>');
Expand Down Expand Up @@ -81,7 +82,7 @@ $.fn.extend({
onSuccess(response) {
response.forEach((leafNode) => {
leafContainerElement.append((
createLeafFunc(leafNode.name, leafNode.code, leafNode.hasChildren, multiple, leafNode.level)
createLeafFunc(sanitizeInput(leafNode.name), sanitizeInput(leafNode.code), leafNode.hasChildren, multiple, leafNode.level)
));
});
content.append(leafContainerElement);
Expand Down Expand Up @@ -169,7 +170,7 @@ $.fn.extend({
const rootContainer = createRootContainer();
response.forEach((rootNode) => {
rootContainer.append((
createLeaf(rootNode.name, rootNode.code, rootNode.hasChildren, multiple, rootNode.level)
createLeaf(sanitizeInput(rootNode.name), sanitizeInput(rootNode.code), rootNode.hasChildren, multiple, rootNode.level)
));
});
tree.append(rootContainer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function sanitizeInput(input) {
const div = document.createElement('div');
div.textContent = input;
return div.innerHTML; // Converts text content to plain HTML, stripping any scripts
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import 'semantic-ui-css/components/dropdown';
import $ from 'jquery';
import { sanitizeInput } from "./sylius-sanitizer";

$.fn.extend({
autoComplete() {
Expand Down Expand Up @@ -37,8 +38,8 @@ $.fn.extend({
},
onResponse(response) {
let results = response.map(item => ({
name: item[choiceName],
value: item[choiceValue],
name: sanitizeInput(item[choiceName]),
value: sanitizeInput(item[choiceValue]),
}));

if (!element.hasClass('multiple')) {
Expand Down Expand Up @@ -72,7 +73,7 @@ $.fn.extend({
onSuccess(response) {
response.forEach((item) => {
menuElement.append((
$(`<div class="item" data-value="${item[choiceValue]}">${item[choiceName]}</div>`)
$(`<div class="item" data-value="${item[choiceValue]}">${sanitizeInput(item[choiceName])}</div>`)
));
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function sanitizeInput(input) {
const div = document.createElement('div');
div.textContent = input;
return div.innerHTML; // Converts text content to plain HTML, stripping any scripts
}

0 comments on commit d4812f9

Please sign in to comment.