Skip to content

Commit

Permalink
fix: on loading a magic resume link and reading sessionId remove it f…
Browse files Browse the repository at this point in the history
…rom the url

- Exposing the sessionId has security implications
- The sessionId and the user email are required to successfully resume their session
- Read the sessionId but then immediately remove it from the url.
- This means it's barely visible and not dispalyed for the rest of the session
  • Loading branch information
Mike-Heneghan committed Nov 27, 2023
1 parent 067fe7d commit fcc4df2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion editor.planx.uk/src/pages/Preview/ResumePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ApplicationPath, SendEmailPayload } from "types";
import Input from "ui/Input";
import InputLabel from "ui/InputLabel";
import InputRow from "ui/InputRow";
import { removeSessionIdSearchParamWithoutReloading } from "utils";
import { object, string } from "yup";

import ReconciliationPage from "./ReconciliationPage";
Expand Down Expand Up @@ -215,7 +216,14 @@ const ResumePage: React.FC = () => {
getInitialEmailValue(route.url.query.email),
);
const [paymentRequest, setPaymentRequest] = useState<MinPaymentRequest>();
const sessionId = useCurrentRoute().url.query.sessionId;

// Read the sessionId from the url to validate against
const sessionId = route.url.query.sessionId;

// As the sessionId has been extracted it can now be removed to avoid
// unnecessarily exposing it
removeSessionIdSearchParamWithoutReloading();

const [reconciliationResponse, setReconciliationResponse] =
useState<ReconciliationResponse>();

Expand Down
6 changes: 6 additions & 0 deletions editor.planx.uk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ export const removeSessionIdSearchParam = () => {
window.history.pushState({}, document.title, currentURL);
window.location.reload();
};

export const removeSessionIdSearchParamWithoutReloading = () => {
const currentURL = new URL(window.location.href);
currentURL.searchParams.delete("sessionId");
window.history.replaceState({}, document.title, currentURL);
};

0 comments on commit fcc4df2

Please sign in to comment.