Skip to content
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

fix (XSS): CWE-79 detected by Snyk #78

Merged
merged 3 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"dependencies": {
"bootstrap": "^5.0.0",
"dompurify": "^2.4.1",
"jquery": "^3.6.0"
}
}
2 changes: 2 additions & 0 deletions test/test-app.ecmas.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ <h1 class="text-primary fw-light">Test App: Bootstrap-vs-bootstrap5toggle</h1>
<main class="container bg-white px-3 py-3 rounded"></main>
</body>

<script src="/node_modules/dompurify/dist/purify.min.js"></script>
<script src="test-app.js"></script>
<script src="test-loader.js"></script>
<script src="test-runner.js"></script>

</html>
2 changes: 2 additions & 0 deletions test/test-app.jquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ <h1 class="text-primary fw-light">Test App: Bootstrap-vs-bootstrap5toggle</h1>
<main class="container bg-white px-3 py-3 rounded"></main>
</body>

<script src="/node_modules/dompurify/dist/purify.min.js"></script>
<script src="test-app.js"></script>
<script src="test-loader.js"></script>
<script src="test-runner.js"></script>

</html>
290 changes: 152 additions & 138 deletions test/test-app.js
Original file line number Diff line number Diff line change
@@ -1,143 +1,157 @@
const ENV = $('#env-data')
const TESTCASES =[
{name: 'status' , code:'status'},
{name: 'tristate' , code:'tristate'},
{name: 'size' , code:'size'},
{name: 'custom size' , code:'custom-size'},
{name: 'outline on' , code:'outline-on'},
{name: 'outline off' , code:'outline-off'},
{name: 'color on' , code:'color-on'},
{name: 'color off' , code:'color-off'},
{name: 'custom text' , code:'custom-text'},
{name: 'custom style' , code:'custom-style'},
{name: 'layout' , code:'layout'},
{name: 'API contructor' , code:'api-constructor'},
{name: 'API methods' , code:'api-methods'}
const ENV = $("#env-data");
const TESTCASES = [
{ name: "status", code: "status" },
{ name: "tristate", code: "tristate" },
{ name: "size", code: "size" },
{ name: "custom size", code: "custom-size" },
{ name: "outline on", code: "outline-on" },
{ name: "outline off", code: "outline-off" },
{ name: "color on", code: "color-on" },
{ name: "color off", code: "color-off" },
{ name: "custom text", code: "custom-text" },
{ name: "custom style", code: "custom-style" },
{ name: "layout", code: "layout" },
{ name: "API contructor", code: "api-constructor" },
{ name: "API methods", code: "api-methods" },
];
function appStartup(test) {
ENV.html('');
ENV.append(
$("<div>").append($("<code>").html("Bootstrap v"+Bootstrap)),
$("<div>").append($("<code>").html("bs-toggle v"+plugin)),
$("<div>").append($("<code>").html("Interface "+INTERFACE))
)
MAIN.html('');
DESCRIPTION.html('');
ENV.html("");
ENV.append(
$("<div>").append(
$("<code>").html("Bootstrap v" + DOMPurify.sanitize(Bootstrap))
),
$("<div>").append(
$("<code>").html("bs-toggle v" + DOMPurify.sanitize(plugin))
),
$("<div>").append(
$("<code>").html("Interface " + DOMPurify.sanitize(INTERFACE))
)
);
MAIN.html("");
DESCRIPTION.html("");
switch (test) {
case "status":
initTestStatus();
break;
case "tristate":
initTestTristate();
break;
case "size":
initTestSize();
break;
case "custom-size":
initTestCustomSize();
break;
case "outline-on":
initTestOutline(STATES.activated);
break;
case "outline-off":
initTestOutline(STATES.disactivated);
break;
case "color-on":
initTestColor(STATES.activated);
break;
case "color-off":
initTestColor(STATES.disactivated);
break;
case "custom-text":
initTestCustomText();
break;
case "custom-style":
initTestCustomStyle();
break;
case "layout":
initTestLayout();
break;
case "api-constructor":
initTestApiContructor();
break;
case "api-methods":
initTestApiMethods();
break;

default:
throw new DOMException("Unknown test case: " + test, "NotSupportedError");
}
switch (INTERFACE) {
case "ECMAS":
document
.querySelectorAll('input[type=checkbox][data-toggle="toggle"]')
.forEach(function (ele) {
ele.bootstrapToggle();
});
break;
case "JQUERY":
$('input[data-toggle="toggle"]').bootstrapToggle();
break;

default:
throw new DOMException(
"Unknown interface: " + INTERFACE,
"NotSupportedError"
);
}

setTimeout(function () {
switch (test) {
case 'status':
initTestStatus()
break;
case 'tristate':
initTestTristate()
break;
case 'size':
initTestSize()
break;
case 'custom-size':
initTestCustomSize()
break;
case 'outline-on':
initTestOutline(STATES.activated)
break;
case 'outline-off':
initTestOutline(STATES.disactivated)
break;
case 'color-on':
initTestColor(STATES.activated)
break;
case 'color-off':
initTestColor(STATES.disactivated)
break;
case 'custom-text':
initTestCustomText()
break;
case 'custom-style':
initTestCustomStyle()
break;
case 'layout':
initTestLayout()
break;
case 'api-constructor':
initTestApiContructor()
break;
case 'api-methods':
initTestApiMethods()
break;

default:
throw new DOMException('Unknown test case: '+ test, "NotSupportedError");
case "status":
testStatus();
break;
case "size":
testSize();
break;
case "custom-size":
testCustomSize();
break;
case "outline-on":
testOutline(STATES.activated);
break;
case "outline-off":
testOutline(STATES.disactivated);
break;
case "color-on":
testColor(STATES.activated);
break;
case "color-off":
testColor(STATES.disactivated);
break;
case "custom-text":
testCustomText();
break;
case "custom-style":
testCustomStyle();
break;
case "layout":
testLayout();
break;
case "api-constructor":
case "api-methods":
case "tristate":
break;

default:
throw new DOMException(
"Unknown test case: " + test,
"NotSupportedError"
);
}
switch (INTERFACE) {
case 'ECMAS':
document.querySelectorAll('input[type=checkbox][data-toggle="toggle"]').forEach(function(ele) {
ele.bootstrapToggle();
});
break;
case 'JQUERY':
$('input[data-toggle="toggle"]').bootstrapToggle();
break;

default:
throw new DOMException('Unknown interface: '+ INTERFACE, "NotSupportedError");
}

setTimeout(function () {
switch (test) {
case 'status':
testStatus()
break;
case 'size':
testSize()
break;
case 'custom-size':
testCustomSize()
break;
case 'outline-on':
testOutline(STATES.activated)
break;
case 'outline-off':
testOutline(STATES.disactivated)
break;
case 'color-on':
testColor(STATES.activated)
break;
case 'color-off':
testColor(STATES.disactivated)
break;
case 'custom-text':
testCustomText()
break;
case 'custom-style':
testCustomStyle()
break;
case 'layout':
testLayout()
break;
case 'api-constructor':
case 'api-methods':
case 'tristate':
break;

default:
throw new DOMException('Unknown test case: '+ test, "NotSupportedError");
}
}, 500);
}, 500);
}
$( function () {
$.getJSON('../package-lock.json', function(data) {
Bootstrap = data.packages["node_modules/bootstrap"].version;
plugin = data.version;
});
TESTCASES.forEach((testCase)=>{
$('#test-selector').append(
$('<button type="button">')
.addClass("btn btn-secondary text-capitalize")
.attr('data-test',testCase.code)
.html(testCase.name)
)
});
$('#test-selector button[data-test]').click(function() {
appStartup($(this).attr('data-test'))
});
});
$(function () {
$.getJSON("../package-lock.json", function (data) {
Bootstrap = data.packages["node_modules/bootstrap"].version;
plugin = data.version;
});
TESTCASES.forEach((testCase) => {
$("#test-selector").append(
$('<button type="button">')
.addClass("btn btn-secondary text-capitalize")
.attr("data-test", testCase.code)
.html(testCase.name)
);
});

$("#test-selector button[data-test]").click(function () {
appStartup($(this).attr("data-test"));
});
});