Repository navigation
bug: load session secret from env, harden session cookie and regenerate session on login (sfind-de582a5d) - #1110
Open
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
…on cookie flags Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Refs: sfind-de582a5dfbdc45fd82bee15f6a1c33ed Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Author
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Corrige o finding
sfind-de582a5d(severidade baixa): oexpress-sessionemapp.js:42-46usava o segredo públicokeyboard cat, cookie só compath, e o login (routes/index.js) marcavaloggedInna sessão já existente sem regenerar o id (session fixation).Mudanças:
session-config.js(novo) +app.js:app.use(session(sessionConfig.sessionOptions(process.env))).secretvem deSESSION_SECRET. O app não sobe se a variável faltar ou tiver menos de 32 caracteres, entãokeyboard caté rejeitado.cookie: { path: '/', httpOnly: true, secure: SESSION_COOKIE_SECURE !== 'false', sameSite: 'lax' },resave: false,saveUninitialized: false,proxy: truequandoSESSION_TRUST_PROXY=true.routes/index.jsloginHandler: depois de validar as credenciais chamareq.session.regenerate(...)e só então setaloggedIn = 1na sessão nova. Em caso de erro, chamanext(err).docker-compose.ymlexigeSESSION_SECRET(${SESSION_SECRET:?...}) e usaSESSION_COOKIE_SECURE=false(porque roda em HTTP puro).app.json(Heroku) gera o segredo e ligaSESSION_TRUST_PROXY. O README foi atualizado.tests/session-config.test.js+npm run test:unit(node --test): 8 testes que cobrem o segredo, as flags do cookie, Secure só em HTTPS/proxy e a troca de sid no login.Mudança operacional / contrato: agora é obrigatório definir
SESSION_SECRET(≥ 32 caracteres) para subir o app. O cookie éSecurepor padrão, então em HTTP local é precisoSESSION_COOKIE_SECURE=false. As rotas HTTP não mudam.Como testar
NODE_OPTIONS=--openssl-legacy-provider npm run test:unit: 8/8 passam. Com oroutes/index.jsdamain, o testelogin regenerates the session id...falha (7/8).app.jscompleto,SESSION_COOKIE_SECURE=false) com um stand-in do Mongo em memória. O mongod 7 da VM não é compatível com o mongoose 4.2.4, então useinode -r memdb.js app.js. Testes feitos comcurl:mainPath=/; HttpOnlyPath=/; HttpOnly; SameSite=LaxGET /saveUninitialized: false)keyboard cat→GET /[REDACTED SECRET]/GET /[REDACTED SECRET]/SESSION_SECRETSESSION_SECRET must be set...Manualmente:
export SESSION_SECRET=$(openssl rand -hex 32) SESSION_COOKIE_SECURE=false; npm start, fazer login em/logincom[REDACTED SECRET]@snyk.ioe confirmar que o cookieconnect.sidmuda e vem comSameSite=Lax.Não testado aqui: o fluxo com MongoDB real (incompatível na VM) e o
npm test(o Snyk CLI precisa de autenticação e rede). O cookieSecureatrás de um proxy TLS real também não foi testado; só viaX-Forwarded-Protono teste unitário.Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/6f8f00c8556a4cbdb48eab536ebf2b7e
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/6f8f00c8556a4cbdb48eab536ebf2b7e?variant=devin
Devin Review