Repository navigation
fix: authenticate pusher from push credentials instead of commit metadata - #46
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
|
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 |
…sts (security bug)
There was a problem hiding this comment.
Devin Review found 1 new potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| if (anonymous.status !== 401 && anonymous.status !== 403) { | ||
| step.log( | ||
| `${upstream.host} does not require authentication for pushes, cannot verify the pusher`, | ||
| ); | ||
| return null; |
There was a problem hiding this comment.
🟡 Hidden private repositories reject valid pushes
When a configured server returns 404 for anonymous discovery, verifyBasicAuthCredentials rejects the push without checking valid credentials. Private repositories hidden from anonymous users cannot be pushed.
Learn more
The Basic-auth host check uses an anonymous git-receive-pack discovery request before testing the client's credentials. A server can hide a private repository by returning 404 to unauthenticated callers while authenticating the same request with valid Basic credentials. Here, the 404 exits before the authenticated request, so a valid user's push is blocked. The existing permission check treats the resulting null account as an authentication failure.
Example: A self-hosted server maps anonymous 401 responses to 404 for /team/private.git/info/refs, but returns 200 with alice's Basic credentials. With that server listed in basicAuthHosts, Alice's push stops after the 404 instead of reaching the successful authenticated check.
Recommended fix: Allow an anonymous 404 only when a subsequent authenticated request to the same repository returns a valid receive-pack advertisement. Keep rejecting anonymous success and authenticated failure, and test the hidden-private-repository case.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Agreed, this is a valid case. Accepting an anonymous 404 doesn't weaken the check, because the username is still trusted only when the authenticated request returns 200. A server that hides private repos would also return 404 for wrong credentials. The fix is to allow 401/403/404 on the anonymous request, keep rejecting anonymous 2xx and authenticated non-200 responses, and add a test for a hidden private repo. I'm holding further pushes to this PR until the requester replies about CI. This fix will go into the next commit.
Description
Corrige o finding de code scan
sfind-5b09d88d24924f329984167c8e40eaea(medium/high): a identidade do pusher era lida da linhacommitterdo último commit dentro do pack enviado pelo cliente. Qualquer pessoa podia colocar o e-mail de outro usuário permitido no commit e assim (a) passar pelocheckUserPushPermissione (b) aprovar/rejeitar o próprio push no dashboard, além de corromper a trilha de auditoria.O que mudou
parsePushnão define maisaction.user/action.userEmaila partir do committer (apenas registra os metadados do commit no log).src/proxy/processors/pusherIdentity.ts: lê o headerAuthorization(Basic) do push e resolve a conta SCM autenticada:GET https://api.github.com/usercom as credenciais do push →logindo dono do token;gitlab):GET <host>/api/v4/user→username;basicAuthHosts(que validam usuário/senha Basic por conta própria, ex.: htpasswd/LDAP): o proxy confirma que o servidor rejeita acesso anônimo (GET <repo>/info/refs?service=git-receive-packsem credenciais → 401/403) e aceita as credenciais do push (mesma requisição → 200) e só então usa o username do Basic auth. Essa regra tem precedência sobre a regra de GitLab por hostname (mas não sobregithub.com, que sempre usa a API);getVerifiedGitAccount, cache emWeakMapporAction), compartilhado entreresolvePusherecheckUserPushPermission.resolvePusher(logo apósparsePush, antes dos push plugins): resolve o mesmo pusher autenticado e preencheaction.user/action.userEmailpara que plugins vejam uma identidade confiável. Nunca bloqueia; quem aplica a regra é ocheckUserPushPermission. Plugins agora são inseridos apósresolvePusher(splice(2, ...)).checkUserPushPermissionmapeia a conta autenticada (case-insensitive) para o usuário GitProxy viaUser.gitAccount, bloqueia credenciais ausentes/inválidas/rejeitadas e contas duplicadas, verificaisUserPushAllowedcom esse usuário e gravaaction.user/action.userEmaila partir dele.src/service/routes/push.ts: os guards "Cannot approve/reject your own changes" continuam usandopush.userEmail, que agora é o pusher autenticado (só renomeadoscommitterEmail→pusherEmaile mensagens de erro).docs/Processors.mdedocs/Architecture.md.gitAccountigual à conta SCM das credenciais usadas no push; antes bastava o e-mail do committer coincidir. Usuários semgitAccountcorreto passam a ser bloqueados.github.com, GitLab nem listados embasicAuthHostspassam a ser bloqueados, pois o proxy não consegue verificar o dono das credenciais.basicAuthHosts(string[], opcional) emconfig.schema.json/src/config/generated/config.ts;test-e2e.proxy.config.jsonpassa a listargit-server. Não listar servidores que aceitam qualquer username junto com um token./userdo provedor (timeout 10s) uma vez por push.resolvePushere recebemaction.user/action.userEmaildo usuário autenticado, não mais do committer.Related Issue
Finding
sfind-5b09d88d24924f329984167c8e40eaea(scanscan-70082f73b42b43fda8ae0a7ecbe7fedf). Upstream: finos#1400Como testar
alice(gitAccount: alice-gh, aprovadoracanAuthorise) ebob(gitAccount: bob-gh,canPush).alice, configuregit config user.email <email do bob>, faça um commit e push via proxy usando o token daalice.alice(não aobob) e, no dashboard,alicerecebe "Cannot approve your own changes".Testes automatizados:
npx vitest run test/processors/checkUserPushPermission.test.ts test/processors/pusherIdentity.test.ts test/processors/resolvePusher.test.ts test/chain.test.ts test/testParsePush.test.ts test/testCheckUserPushPermission.test.ts test/testPush.test.tsChecklist
General
Documentation
Configuration
config.schema.jsonmodificado (basicAuthHosts);src/config/generated/config.tsatualizado manualmente seguindo o formato do quicktype (o build regenera)npm run generate-config-types) — editados à mão; onpm run buildregeneranpm run gen-schema-doc) —json-schema-for-humansindisponível na VM; seção 24 (basicAuthHosts) adicionada à mão emwebsite/docs/configuration/reference.mdxno formato do gerador (propriedade movida para o fim do schema, sem renumerar seções existentes)Tests
npm test) — rodados localmente apenastest/processors/{checkUserPushPermission,pusherIdentity,resolvePusher}.test.tsetest/testParsePush.test.ts(todos passando); o restante (chain.test,testCheckUserPushPermissioncom DB,testPush) depende do CI, pois o registry npm estava bloqueado na VMnpm run lint/ [ ]npm run check-types— pendentes no CI pelo mesmo motivoDevin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/ae2da50eb6fa428191b67f5332333284
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/ae2da50eb6fa428191b67f5332333284?variant=devin
Devin Review