Skip to content

Commit

Permalink
Fixed #8549 - Navigate to URL cross-site scripting attack (#8550)
Browse files Browse the repository at this point in the history
Co-authored-by: tsv2013 <[email protected]>
  • Loading branch information
tsv2013 and tsv2013 authored Jul 12, 2024
1 parent ca8e2a8 commit 0416090
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function scrollElementByChildId(id: string) {
function navigateToUrl(url: string): void {
const location = DomWindowHelper.getLocation();
if (!url || !location) return;
location.href = url;
location.href = encodeURIComponent(url);
}

function wrapUrlForBackgroundImage(url: string): string {
Expand Down
19 changes: 19 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { defaultV2Css } from "../src/defaultCss/defaultV2Css";
import { StylesManager } from "../src/stylesmanager";
import { ITheme } from "../src/themes";
import { Cover } from "../src/header";
import { DomWindowHelper } from "../src/global_variables_utils";

export default QUnit.module("Survey");

Expand Down Expand Up @@ -20125,3 +20126,21 @@ QUnit.test("Delete panel with questions", (assert) => {
assert.notOk(survey.getPanelByName("panel1"), "#5");
assert.notOk(survey.getQuestionByName("question1"), "#6");
});

QUnit.test("survey navigateToUrl encode url", function (assert) {
var survey = new SurveyModel({
questions: [
{
type: "text",
name: "q1",
}
],
"navigateToUrl": "javascript:alert(2)",
});

const location: Location = {} as any;
DomWindowHelper.getLocation = <any>(() => location);

survey.doComplete();
assert.equal(location.href, "javascript%3Aalert(2)", "encoded URL");
});

0 comments on commit 0416090

Please sign in to comment.