Repository navigation
fix(oidc): persist OIDC subject and avoid email local-part username collisions - #43
Open
devin-ai-integration[bot] wants to merge 3 commits into
Open
devin-ai-integration[bot] wants to merge 3 commits into
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
…ollisions (bug) createUser dropped the oidcId it was given, so findUserByOIDC never matched: repeat OIDC logins failed with 'user X already exists' and any identity with a matching email local part could claim a username first and lock the rightful owner out. - db.createUser stores oidcId for OIDC accounts - handleUserAuthentication resolves by subject first, rejects email_verified=false, refuses to bind to existing non-OIDC accounts by email, binds legacy OIDC accounts (password null, no oidcId) on exact email match, and suffixes the username with a hash of the subject when the local part is taken - deserializeUser falls back to a username lookup for non-OIDC sessions Refs: sfind-b275e4805c77462cbcb7852798cac2fb
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
4 of 9 tasks
Author
|
CI on 404ff08: The |
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
Corrige o achado de code scan
sfind-b275e4805c77462cbcb7852798cac2fb(low): contas OIDC eram identificadas apenas pela parte local do e-mail e osub(subject) do provedor nunca era salvo.Causa raiz:
db.createUserrecebiaoidcIdmas não o gravava no registro (o campo se perdeu na conversão para TypeScript). Por issofindUserByOIDC(sub)nunca encontrava ninguém, e:user <x> already exists(HTTP 500 no fluxo misto local+OIDC);alice@partner.example) podia criar a contaaliceprimeiro e bloquear a dona legítima (alice@acme.example).Mudanças
src/db/index.ts–createUsergravaoidcIdquando informado (registros de usuários locais ficam iguais, sem o campo).src/service/passport/oidc.ts–handleUserAuthentication:subprimeiro e devolve a conta encontrada (login repetido funciona);sub; rejeita criação de conta quando o provedor enviaemail_verified: false;password === null, semoidcId) são vinculadas aosubquando o e-mail bate exatamente, para não trancar usuários existentes;getAvailableUsername: usa a parte local se estiver livre; caso contrário usa<local>-<8 hex de sha256(sub)>, então uma segunda identidade recebe um username distinto em vez de erro.{ oidcId }para contas OIDC e{ username }para as demais (serializeSessionId/deserializeSessionId). Um username local nunca é resolvido como osubde outra conta, e vice-versa. IDs string (sessões antigas) continuam resolvendo só porfindUserByOIDC, como nomain.oidcId,password === null) por e-mail exigeemail_verified: true; sem a claim, retorna "already exists" e o [REDACTED SECRET] precisa vincular manualmente.Mudança de comportamento / contrato (sinalizado): nenhuma rota de API mudou. O username gerado para um novo usuário OIDC passa a ter sufixo quando a parte local já está em uso (antes: erro). Logins OIDC com
email_verified: falsenão criam mais conta.Risco residual: a parte local continua sendo "first come, first served" para o username sem sufixo – quem logar primeiro com
alice@…fica comalice. A dona legítima não fica mais trancada (recebealice-xxxxxxxx) e o e-mail real aparece na conta, mas [REDACTED SECRET]s devem conferir o e-mail antes de conceder permissões por username. Usar o e-mail completo como username eliminaria isso, mas mudaria todos os usernames OIDC; deixei fora do escopo.Related Issue
Code scan finding
sfind-b275e4805c77462cbcb7852798cac2fb(scanscan-70082f73b42b43fda8ae0a7ecbe7fedf). Não há issue no GitHub.Como testar
npm test -- test/testOidc.test.ts test/testDb.test.tstestDb:createUser(..., oidcId)persiste osubefindUserByOIDCo encontra; usuários locais não ganhamoidcId.testOidc(novo bloco "OIDC user identity binding"): login repetido resolve a mesma conta; segunda identidade com mesma parte local recebealice-<hash>; não toma username nem e-mail de conta local; vincula conta legada só comemail_verified: true; IDs de sessão local/OIDC não colidem; rejeitaemail_verified: falsee perfil semsub.Verificação local feita: este ambiente não tem acesso ao registry do npm, então
npm ci/npm test/npm run lint/check-typesnão rodaram aqui – ficam para o CI. Rodei um harness vitest isolado (vitest emprestado de outro repo) com osrc/db/index.tsreal e um sink em memória:oidcId, o 2º login retornauser alice already exists, e a vítima é bloqueada depois quealice@partner.exampleloga primeiro.email_verifiedna vinculação legada) – registro{"username":"alice",…,"oidcId":"sub-alice"}, 2º login resolve a mesma conta, segunda identidade viraalice-2de72856, criação de usuário local inalterada.prettier --checkpassa nos arquivos alterados. Hooks do husky (commitlint + lint) não rodaram localmente pelo mesmo motivo.Checklist
General
Documentation
Configuration
config.schema.json) was modified: (não modificado)Tests
npm test) – pendente no CI (npm indisponível localmente)npm run lintandnpm run format:check) – prettier ok localmente; eslint pendente no CInpm run check-types) – pendente no CICI (404ff08):
test/testOidc.test.ts(19 testes) etest/testDb.test.tspassam em todas as matrizes Ubuntu e no Windows; Linting, CodeQL, e2e (vitest/cypress) passam. As únicas falhas são 2 testes emtest/ConfigLoader.test.ts(loadRemoteConfigvia git/http), que baixam oproxy.config.jsonao vivo definos/git-proxy@maine falham comInvalid value for key "sink": o arquivo upstream não bate com o schema deste fork. Não tem relação com este PR. O jobbuild-ubuntu (24.x, 8.0)também falhou porque o containermongo:8.0não subiu.Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/66bb0bcb0719460bb35e8fd615cbd11f
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/66bb0bcb0719460bb35e8fd615cbd11f?variant=devin
Devin Review