Skip to content

Commit

Permalink
Added sanitization for returnURL. (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov authored Dec 3, 2021
1 parent cdf134c commit 3174681
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 17 deletions.
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 @@ -62,6 +62,7 @@
"webpack-merge": "^5.2.0"
},
"dependencies": {
"@braintree/sanitize-url": "^5.0.2",
"@monaco-editor/loader": "^1.2.0",
"@paperbits/azure": "0.1.468",
"@paperbits/common": "0.1.468",
Expand Down
8 changes: 4 additions & 4 deletions src/components/defaultAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IAuthenticator, AccessToken } from "./../authentication";
import * as Constants from "./../constants";
import { sanitizeUrl } from "@braintree/sanitize-url";
import { AccessToken, IAuthenticator } from "./../authentication";

export class DefaultAuthenticator implements IAuthenticator {
constructor() { }

export class DefaultAuthenticator implements IAuthenticator {
private runSsoFlow(): Promise<void> {
return new Promise<void>(async () => {
const url = new URL(location.href);
Expand All @@ -20,7 +20,7 @@ export class DefaultAuthenticator implements IAuthenticator {
await this.setAccessToken(token);

// wait for redirect to happen, deliberatly not resolving the promise
window.location.assign(returnUrl);
window.location.assign(sanitizeUrl(returnUrl));
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/setup/setupDialog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import template from "./setupDialog.html";
import * as Constants from "../../constants";
import { Component, OnMounted } from "@paperbits/common/ko/decorators";
import { ViewManager } from "@paperbits/common/ui";
import { Router } from "@paperbits/common/routing";
Expand All @@ -21,7 +22,7 @@ export class SetupDialog {
try {
this.viewManager.removeShutter();
await this.provisioningService.provision();
await this.router.navigateTo("/");
await this.router.navigateTo(Constants.pageUrlHome);

window.location.reload();
}
Expand Down
19 changes: 10 additions & 9 deletions src/components/users/signin/ko/runtime/signin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as ko from "knockout";
import * as validation from "knockout.validation";
import template from "./signin.html";
import { sanitizeUrl } from "@braintree/sanitize-url";
import { EventManager } from "@paperbits/common/events";
import { Component, RuntimeComponent, OnMounted, Param } from "@paperbits/common/ko/decorators";
import { UsersService } from "../../../../../services/usersService";
import { MapiError } from "../../../../../errors/mapiError";
import { Component, OnMounted, Param, RuntimeComponent } from "@paperbits/common/ko/decorators";
import { Router } from "@paperbits/common/routing/router";
import { ValidationReport } from "../../../../../contracts/validationReport";
import { MapiError } from "../../../../../errors/mapiError";
import { RouteHelper } from "../../../../../routing/routeHelper";
import { Router } from "@paperbits/common/routing/router";
import { UsersService } from "../../../../../services/usersService";

@RuntimeComponent({
selector: "signin-runtime"
Expand Down Expand Up @@ -102,18 +103,18 @@ export class Signin {

try {
this.working(true);

const userId = await this.usersService.signIn(this.username(), this.password());

if (userId) {
const clientReturnUrl = sessionStorage.getItem("returnUrl");
const returnUrl = this.routeHelper.getQueryParameter("returnUrl") || clientReturnUrl;

if (returnUrl) {
this.router.navigateTo(returnUrl);
await this.router.navigateTo(sanitizeUrl(returnUrl));
return;
}

this.navigateToHome();

const validationReport: ValidationReport = {
Expand All @@ -130,7 +131,7 @@ export class Signin {
source: "signin",
errors: ["Please provide a valid email and password."]
};

this.eventManager.dispatchEvent("onValidationErrors", validationReport);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/routing/signOutRouteGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ export class SignOutRouteGuard implements RouteGuard {
}

this.authenticator.clearAccessToken();
location.assign("/");
location.assign(Constants.pageUrlHome);
}
}
3 changes: 2 additions & 1 deletion src/services/aadService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Msal from "msal";
import * as Constants from "../constants";
import { sanitizeUrl } from "@braintree/sanitize-url";
import { HttpClient } from "@paperbits/common/http";
import { Router } from "@paperbits/common/routing";
import { RouteHelper } from "../routing/routeHelper";
Expand Down Expand Up @@ -46,7 +47,7 @@ export class AadService {

this.router.getCurrentUrl() === returnUrl
? location.reload()
: await this.router.navigateTo(returnUrl);
: await this.router.navigateTo(sanitizeUrl(returnUrl));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/services/provisioningService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ProvisionService {
throw new Error("Unable to setup website.");
}
}
this.router.navigateTo("/");
this.router.navigateTo(Constants.pageUrlHome);
this.viewManager.setHost({ name: "page-host" });
this.viewManager.showToolboxes();
}
Expand Down

0 comments on commit 3174681

Please sign in to comment.