Skip to content

🛡️ Sentinel: [CRITICAL] Fix SSRF in bulk lookup API#205

Open
aicoder2009 wants to merge 1 commit into
mainfrom
sentinel-fix-ssrf-844255265598433692
Open

🛡️ Sentinel: [CRITICAL] Fix SSRF in bulk lookup API#205
aicoder2009 wants to merge 1 commit into
mainfrom
sentinel-fix-ssrf-844255265598433692

Conversation

@aicoder2009

Copy link
Copy Markdown
Owner

🚨 Severity: CRITICAL
💡 Vulnerability: The src/app/api/lookup/bulk/route.ts API route was making a loopback HTTP fetch request to internal API endpoints using request.nextUrl.origin. This hostname is derived dynamically from the user-controllable Host header, leading to a Server-Side Request Forgery (SSRF) vulnerability.
🎯 Impact: An attacker could manipulate the Host header to redirect the server's internal requests to a malicious server, potentially leading to request smuggling, internal network scanning, or bypassing access controls.
🔧 Fix: Modified the route to directly import and invoke the POST handlers from the url, doi, and isbn API routes. We now construct a synthetic NextRequest and pass it directly to the handler functions, completely bypassing network fetch and resolving the SSRF vulnerability while slightly improving performance.
✅ Verification: Ran pnpm test:run to ensure all tests pass. Verified the logic changes manually, ensuring no external fetches are made using user-controllable variables.


PR created automatically by Jules for task 844255265598433692 started by @aicoder2009

Co-authored-by: aicoder2009 <127642633+aicoder2009@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings July 2, 2026 06:53
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
opencitation Ready Ready Preview, Comment Jul 2, 2026 6:54am

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 29de0923-ed78-46cd-b96c-9d70813f322c

📥 Commits

Reviewing files that changed from the base of the PR and between b69285b and a78c87f.

📒 Files selected for processing (3)
  • .jules/sentinel.md
  • src/app/api/lookup/bulk/route.test.ts
  • src/app/api/lookup/bulk/route.ts
 _____________________
< Git gud or git out. >
 ---------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel-fix-ssrf-844255265598433692

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR removes an SSRF-prone loopback fetch() pattern from the bulk lookup API route by invoking internal Next.js route handlers directly, avoiding any dependence on the user-controlled Host header and eliminating internal network calls.

Changes:

  • Refactored POST /api/lookup/bulk to dispatch directly to the url, doi, and isbn route POST handlers via a synthetic NextRequest.
  • Updated bulk-lookup tests to mock the internal route handlers instead of global.fetch.
  • Documented the SSRF incident and prevention guidance in Sentinel notes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/app/api/lookup/bulk/route.ts Replaces loopback fetch(request.nextUrl.origin + ...) with direct handler invocation to eliminate SSRF risk.
src/app/api/lookup/bulk/route.test.ts Switches unit tests from mocking fetch to mocking the imported route handlers.
.jules/sentinel.md Adds an SSRF entry documenting root cause, learning, and prevention pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

expect(data.results[0].data.title).toBe('Example Page');
const [url] = (global.fetch as ReturnType<typeof vi.fn>).mock.calls[0] as [string];
expect(url).toContain('/api/lookup/url');
expect(urlLookup).toHaveBeenCalled();
expect(data.results[0].success).toBe(true);
const [url] = (global.fetch as ReturnType<typeof vi.fn>).mock.calls[0] as [string];
expect(url).toContain('/api/lookup/doi');
expect(doiLookup).toHaveBeenCalled();
expect(data.results[0].success).toBe(true);
const [url] = (global.fetch as ReturnType<typeof vi.fn>).mock.calls[0] as [string];
expect(url).toContain('/api/lookup/isbn');
expect(isbnLookup).toHaveBeenCalled();
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.

2 participants