Skip to content

fix(service): require authentication for push/repo/user read APIs and trim file-sink push list (sfind-0d184eca) - #27

Open
devin-ai-integration[bot] wants to merge 5 commits into
mainfrom
devin/sfind-0d184eca-require-auth-push-reads
Open

devin-ai-integration[bot] wants to merge 5 commits into
mainfrom
devin/sfind-0d184eca-require-auth-push-reads

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Description

Fixes code scan finding sfind-0d184eca06e84568b1b702489eaf0f34 (high): GET /api/v1/push and GET /api/v1/push/:id answered anonymous requests, exposing full diffs, commit messages, author emails and the secret literals recorded by scanDiff.

Root cause: src/service/routes/index.ts mounted the push, repo and user routers behind jwtAuthHandler() only, which calls next() when the JWT apiAuthentication method is disabled (the default in proxy.config.json). The read handlers in push.ts never check req.user.

Fix:

  • New ensureAuthenticated middleware (src/service/routes/middleware.ts): passes a passport session (req.isAuthenticated()) or a req.user set by an earlier handler (e.g. JWT); otherwise returns 401 { message: 'Authentication required' }.
  • Mounted after jwtAuthHandler() on /api/v1/push, /api/v1/repo and /api/v1/user, so protection no longer depends on the optional JWT method.
  • File (neDB) sink: getPushes now applies the same field projection as the Mongo adapter, so the list no longer returns steps (diff / scan output), user, userEmail or attestation. The full document is still available from GET /api/v1/push/:id to authenticated users. The dashboard list only reads commitData, repo, branch, url, commitTo and id, all of which are kept.
  • UI: removed the public "open source activity feed" / "scroll through projects" links from Login.tsx; they would now hit 401 and bounce back to login.

API contract change

  • GET /api/v1/push, GET /api/v1/push/:id, GET /api/v1/repo[/:id] and GET /api/v1/user[/:id] now require an authenticated session (or a valid JWT when enabled). Anonymous calls get 401.
  • The 401 body on write routes in these routers changes from Not logged in / You are not authorised to perform this action. to Authentication required.
  • With the file sink, git-proxy-cli ls no longer shows attestation, autoApproved or lastStep in list output, matching the existing Mongo behaviour.

Tests

  • test/services/routes/middleware.test.ts (unit + router).
  • test/testPush.test.ts: anonymous list/detail return 401; authenticated list omits steps/user/userEmail/attestation; detail returns the full push.
  • test/testDb.test.ts: list projection test; create-push now checked via getPush.
  • npx vitest --run test/testDb.test.ts test/testPush.test.ts test/testRepoApi.test.ts test/services/routes/middleware.test.ts test/db test/ui/git-push.test.ts: 214 passed, 45 skipped. Full vitest failures are limited to the known ConfigLoader/plugin/Docker e2e/experimental suites that also fail on main.

How to verify

  1. npm run server, then curl -i http://localhost:8080/api/v1/push with no cookie returns 401.
  2. Log in (POST /api/auth/login) and repeat with the connect.sid cookie: 200 with the list, without steps/user/userEmail/attestation.

Related Issue

Code scan finding sfind-0d184eca06e84568b1b702489eaf0f34.

Checklist

General

Documentation

  • Documentation has been added/updated for any new features

Configuration

  • If configuration schema (config.schema.json) was modified: N/A

Tests

  • Tests have been added/updated for new functionality
  • Unit tests pass (npm test)
  • Linting and formatting pass (npm run lint and npm run format:check)
  • Type checks pass (npm run check-types) (except pre-existing errors in AttestationInfo.tsx)

Devin-Org: engineering

Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/a3684abf498d4cbcb15511543f17a602
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/a3684abf498d4cbcb15511543f17a602?variant=devin
Requested by: @schaudhry123


Devin Review

Status Commit
⚪ Not started —

Run Devin Review

Enable auto-review to review your pull requests automatically.

Devin Review (Staging)


Devin Review

GET /api/v1/push and /api/v1/push/:id (and the repo/user routers) were
mounted behind jwtAuthHandler only, which calls next() when JWT API auth
is disabled (the shipped default). Add ensureAuthenticated after it so an
authenticated session or req.user is always required.

Finding: sfind-0d184eca06e84568b1b702489eaf0f34

Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…d (sfind-0d184eca)

Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

…ead APIs require auth

Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

Verificação (antes/depois)

O npm install não roda nesta VM: o registry.npmjs.org está bloqueado pela política de rede. Por isso a suíte vitest do repositório não foi executada. Para cobrir isso, montei um harness HTTP que usa o src/service/routes/push.ts, o jwtAuthHandler e o ensureAuthenticated reais de cada checkout, montados como no src/service/routes/index.ts.

  • Config simulada igual à padrão: autenticação JWT da API desativada.
  • O db é um stub com uma push bloqueada cujo diff e cujo scanDiff contêm uma AWS key fake.
  • Sessão logada simulada com req.user e isAuthenticated().
== before (origin/main): ensureAuthenticated mounted on /api/v1/push: false
anon   GET /api/v1/push?blocked=true     -> 200 LEAKS secret+diff
anon   GET /api/v1/push/:id              -> 200 LEAKS secret+diff
logged GET /api/v1/push?blocked=true     -> 200 LEAKS secret+diff
logged GET /api/v1/push/:id              -> 200 LEAKS secret+diff
== after (this PR): ensureAuthenticated mounted on /api/v1/push: true
anon   GET /api/v1/push?blocked=true     -> 401 no secret {"message":"Authentication required"}
anon   GET /api/v1/push/:id              -> 401 no secret {"message":"Authentication required"}
logged GET /api/v1/push?blocked=true     -> 200 LEAKS secret+diff
logged GET /api/v1/push/:id              -> 200 LEAKS secret+diff

(No caso logado, "LEAKS" só indica que o usuário autenticado continua recebendo os dados completos, que é o comportamento esperado.)

prettier --check passou nos arquivos alterados.

Ainda não testado:

  • npm test, lint e check-types.
  • Login real via passport e o fluxo de UI, que precisam das dependências instaladas.

Written by Devin

…sink's push list

Co-Authored-By: Samir Chaudhry <samir@cognition.ai>
@devin-ai-integration devin-ai-integration Bot changed the title fix(service): require authentication for GET /api/v1/push and other read API endpoints (sfind-0d184eca) fix(service): require authentication for push/repo/user read APIs and trim file-sink push list (sfind-0d184eca) Nov 17, 2026
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

Custom reviewers

  • 🧪 Test 2 reviewer: no findings · View
  • 🚩 TD Enterprise Architecture: no findings · View
  • 👁️ TD Information Security: no findings · View
  • 🧠 TD French Language (Bill 96): no findings · View
  • ⏱️ TD API Contracts: 2 findings · View
  • 🧹 Henry's Style Guide: no findings · View

Devin Review

Comment thread src/db/file/pushes.ts
if (!query) query = defaultPushQuery;
return new Promise((resolve, reject) => {
db.find(query)
.projection(pushListProjection)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ TD API Contracts: Push list drops existing v1 fields

For file-sink lists, getPushes changes v1 records from full actions to summaries without attestation, autoApproved, or lastStep. getGitPushes still prints these fields, so CLI users now receive undefined instead of approval and diagnostic data. Dropping existing response fields within v1 violates §4 compatibility.

View in Devin Review · Custom reviewer

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

if (sessionAuthed || req.user) {
return next();
}
res.status(401).send({ message: 'Authentication required' });

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ TD API Contracts: Authentication errors omit required problem details

For unauthenticated push, repository, and user requests, ensureAuthenticated returns application/json containing only {"message":"Authentication required"}. §4 requires RFC 9457 application/problem+json with a <DOMAIN>-<4 digits> code and correlationId. API clients receive neither the required error code nor a correlation identifier.

View in Devin Review · Custom reviewer

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

github-advanced-security[bot]

This comment was marked as resolved.

Co-Authored-By: Samir Chaudhry <samir@cognition.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant