-
Notifications
You must be signed in to change notification settings - Fork 389
Add a new config option for cookie name #891
Comments
Some more findings: The previously proposed solution will not work as is - because it uses signed cookies.
app.get('/auth/login', (req, res) => {
const sessionData = {
// sessionId: '123456789',
nonce: 'abcdefg',
// other properties...
};
const serializedData = JSON.stringify(sessionData);
const mac = generateMAC(serializedData);
// Set the cookie with the MAC
res.cookie('__session', serializedData + ':' + mac);
}) And verify like this (hypothetical code): app.get('/auth/callback', (req, res) => {
const cookieValue = req.cookies.__session;
// Extract the serialized data and MAC
const separatorIndex = cookieValue.lastIndexOf(':');
const serializedData = cookieValue.slice(0, separatorIndex);
const storedMAC = cookieValue.slice(separatorIndex + 1);
// Verify the MAC
const computedMAC = generateMAC(serializedData);
if (computedMAC === storedMAC) {
// MAC is valid
const sessionData = JSON.parse(serializedData);
// Access the values
const sessionId = sessionData.sessionId;
const nonce = sessionData.nonce;
// other properties...
// Perform necessary operations with the session data
res.send('Example endpoint');
} else {
// MAC is invalid
res.status(401).send('Invalid MAC');
}
}); More context in I'm not using this package. Only added it for reference since it's a problem many packages have. |
This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days. |
We are closing this issue because it has been inactive for a few months. If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines Thank you! |
Overview/summary
This library uses fixed/static cookie names (defined as
STATE_COOKIE_NAME
) to validate state (nonce).The same goes session cookie name - but let's stick to the state (nonce) cookie for now.
When deploying to Firebase, cookie state validation fails.
The reason is that Firebase strips every cookie name, but only the
__session
cookie is allowed to pass through. (Reference)Proposed solution
Add a config option named
stateCookieName
, which will be used instead of the default state cookie nameNote
The suggested solution will work for embedded apps only as it requires only one cookie (state cookie) for validating nonce.
Sessions are handled via JWT.
For non-embedded apps, it requires a separate cookie for the session as well. So not sure if it will work in the Firebase context.
While we're at it, we can just expose both cookie names (
SESSION_COOKIE_NAME
andSTATE_COOKIE_NAME
) to be configurable.The text was updated successfully, but these errors were encountered: