Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fixes #5102 - Bad Oauth State with FxA login
Browse files Browse the repository at this point in the history
  • Loading branch information
punamdahiya committed Oct 30, 2018
1 parent bbeb53a commit d2f5d77
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,14 +1093,20 @@ app.get("/api/fxa-oauth/login/*", async function(req, res, next) {
let state = stateBytes.toString("hex");
let stateId = null;

const cookies = new Cookies(req, res, {keys: dbschema.getKeygrip("fxa-oauth")});

if (req.deviceId) {
if (cookies.get("fxaState")) {
// Remove invalid fxaState cookie in favor of using deviceId as StateId
cookies.set("fxaState");
cookies.set("fxaState.sig");
}
stateId = req.deviceId;
} else {
const uuidPromise = util.promisify(genUuid.generate);
const uuid = await uuidPromise(genUuid.V_RANDOM);
stateId = uuid.toString();

const cookies = new Cookies(req, res, {keys: dbschema.getKeygrip("fxa-oauth")});
cookies.set("fxaState", stateId, {signed: true});
}

Expand Down Expand Up @@ -1138,7 +1144,7 @@ app.get("/api/fxa-oauth/confirm-login", async function(req, res, next) {
const cookies = new Cookies(req, res, {keys: dbschema.getKeygrip("fxa-oauth")});

let stateId = cookies.get("fxaState");
if (stateId && (stateId.search(/^[a-zA-Z0-9_-]{1,255}$/) === -1)) {
if (stateId && (!/^[a-zA-Z0-9_-]{1,255}$/.test(stateId))) {
const err = new Error("Bad stateId in confirm-login");
next(err);
return;
Expand Down

0 comments on commit d2f5d77

Please sign in to comment.