Repository navigation
fix(auth): build JWT req.user from trusted fields instead of raw token claims - #33
Open
devin-ai-integration[bot] wants to merge 4 commits into
Open
devin-ai-integration[bot] wants to merge 4 commits into
devin-ai-integration[bot] wants to merge 4 commits into
Conversation
The JWT API auth handler assigned the verified token payload directly to req.user, so admin/username claims in the token were trusted for authorization. req.user is now a fresh object: admin starts false and is only set by roleMapping, and username/email come from the user database (matched on the token sub via oidcId). Push approve/reject/cancel return 403 when no linked username is present. Fixes code scan finding sfind-072118d306f4438fa97c4da854ce3f0d. 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)".
|
…bject Addresses Devin Review on #33: createUser accepted an oidcId but dropped it from the stored record, so findUserByOIDC (used by OIDC login and now by the JWT handler) never matched OIDC-created users. Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
|
||
| const app = express(); | ||
| app.use(express.json()); | ||
| app.use(jwtAuthHandler(jwtConfig)); |
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.
Description
Contexto: finding de code scan
sfind-072118d306f4438fa97c4da854ce3f0d(severidade baixa). Com a autenticação JWT da API ativada,jwtAuthHandleratribuía o payload verificado do token direto areq.user. Assim, claims[REDACTED SECRET]: trueouusername: '<aprovador>'no token eram usados porisAdminUsere pelas rotas de approve/reject/cancel de push.assignRolessó adicionavatruee nunca removia um[REDACTED SECRET]vindo do token.O que mudou:
src/service/passport/jwtAuthHandler.ts:req.useragora é um objeto novo{ sub, [REDACTED SECRET]: false }.username/emailvêm do banco (db.findUserByOIDC(sub)), não das claims.[REDACTED SECRET]só viratrueviaroleMapping(assignRoles).src/service/routes/push.ts:/:id/reject,/:id/authorisee/:id/cancelretornam 403 quandoreq.usernão temusername(em vez de quebrar emusername.toLowerCase()).src/db/index.ts:createUseragora persisteoidcId(antes era descartado, entãofindUserByOIDCnunca encontrava usuários criados via OIDC). Contas OIDC já existentes semoidcIdprecisam ser religadas (ex.:updateUser) para usar JWT em approve/reject/cancel.sub→ usuário (findUserByOIDC) só é feito quando oauthorityURLdo JWT é exatamente igual (comparação exata de string, incluindo barra final) ao issuer do login OIDC da UI (openidconnect); umsubsó é único por issuer, então tokens de outro issuer nunca são associados a usuários GitProxy.website/docs/configuration/authentication.mdx: documenta que papéis vêm só doroleMappinge que a identidade é resolvida pelosub→oidcId.test/testJwtAuthHandler.test.ts: tokens RS256 reais assinados com[REDACTED SECRET]: true+username: 'approver'semroleMappingcorrespondente →isAdminUser(req.user) === false, semusername; ePOST /api/v1/push/:id/authoriseretorna 403 sem chamarcanUserApproveRejectPush/authorise. Também cobre resolução via banco, issuer diferente/sem OIDC (sem vínculo) e [REDACTED SECRET] viaroleMapping.test/testDb.test.ts:createUsercomoidcId→findUserByOIDCencontra o usuário.[REDACTED SECRET]/usernameno token perdem esses direitos. Admin deve ser configurado emroleMapping; para aprovar/rejeitar/cancelar pushes, osubdo token precisa estar ligado a um usuário GitProxy (oidcId). Sessões locais/OIDC/AD não mudam.Como testar:
Related Issue
Code scan finding
sfind-072118d306f4438fa97c4da854ce3f0d(sem issue no GitHub).Checklist
General
Documentation
Configuration
config.schema.json) was modified: (não modificado)Tests
npm test) — CI (Mongo 6.0/7.0, Node 22/24): 774 testes passam, incluindo os novos; as 2 falhas são emtest/ConfigLoader.test.ts(loadRemoteConfigcarregaproxy.config.jsondefinos/git-proxymain, que agora temsinkincompatível) e também ocorrem no PR fix(oidc): persist OIDC subject and avoid email local-part username collisions #43. Jobs Mongo 8.0 falham porque o containermongo:8.0não inicia.npm run lintandnpm run format:check) — jobLintingverde no CInpm run check-types) — ver CIDevin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/e1ad79e6e2974f2e9aa6e7137f134960
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/e1ad79e6e2974f2e9aa6e7137f134960?variant=devin
Devin Review