Skip to content

fix: use unoptimized prop for HTTP images instead of open proxy#824

Merged
thostetler merged 1 commit intoadsabs:masterfrom
thostetler:fix/next-image-unoptimized-http
Mar 10, 2026
Merged

fix: use unoptimized prop for HTTP images instead of open proxy#824
thostetler merged 1 commit intoadsabs:masterfrom
thostetler:fix/next-image-unoptimized-http

Conversation

@thostetler
Copy link
Member

Reverts the http://** wildcard in images.remotePatterns added in #823.
The wildcard exposed _next/image as an SSRF-capable outbound proxy,
allowing arbitrary server-side fetches to any host.

  • Removed http protocol entry from remotePatterns (HTTPS-only)
  • Added unoptimized prop to NextImage on graphics page for http:// thumbnails, bypassing the server-side optimizer while still rendering correctly

Reverts the http://** wildcard in remotePatterns which exposed the
_next/image endpoint as an SSRF-capable outbound proxy. HTTP-only
thumbnails on the graphics page now render with unoptimized prop,
bypassing server-side fetch while still displaying correctly.
@thostetler thostetler marked this pull request as ready for review March 10, 2026 18:36
Copilot AI review requested due to automatic review settings March 10, 2026 18:36
@thostetler thostetler merged commit fca9bc0 into adsabs:master Mar 10, 2026
6 checks passed
@thostetler thostetler deleted the fix/next-image-unoptimized-http branch March 10, 2026 18:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Security-focused change to reduce SSRF exposure through Next.js’ _next/image optimizer by removing the HTTP remote pattern and adjusting the graphics page to render HTTP thumbnails without using the server-side optimizer.

Changes:

  • Removed http from images.remotePatterns (HTTPS-only).
  • Updated the abstract graphics page to set unoptimized for http:// thumbnails.

Reviewed changes

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

File Description
src/pages/abs/[id]/graphics.tsx Conditionally bypasses Next.js image optimization for HTTP thumbnails via unoptimized.
next.config.mjs Removes the http wildcard entry from images.remotePatterns.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +97 to +98
width="150"
height="150"
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

next/image expects numeric width/height props. Passing them as strings works against the component’s contract and can mask type issues (especially since build type-checking is disabled). Use numbers for these props to match ImageProps and avoid runtime surprises.

Suggested change
width="150"
height="150"
width={150}
height={150}

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +101
alt={figure.figure_label}
unoptimized={figure.images[0].thumbnail.startsWith('http://')}
/>
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Setting unoptimized for http:// thumbnails avoids the server-side optimizer, but it also shifts fetching to the browser as mixed-content on HTTPS pages, which can be blocked by some browser/security settings and result in broken thumbnails. Consider adding an explicit fallback (e.g., placeholder/"image unavailable" state) when the thumbnail fails to load so the UI remains usable.

Copilot uses AI. Check for mistakes.
Comment on lines 164 to 165
hostname: '**',
},
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

images.remotePatterns still allows https for hostname: '**', which means the Next.js image optimizer endpoint can still be used to trigger server-side fetches to arbitrary HTTPS hosts (SSRF risk remains, even if HTTP is removed). Consider restricting remotePatterns to an allowlist of known thumbnail hosts (or switching to a custom loader/proxy with explicit validation) so _next/image can’t be used as a general outbound fetcher.

Suggested change
hostname: '**',
},
hostname: 'scixplorer.org',
},
{
protocol: 'https',
hostname: '*.scixplorer.org',
},

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.9%. Comparing base (969405a) to head (702b8aa).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #824     +/-   ##
========================================
- Coverage    61.9%   61.9%   -0.0%     
========================================
  Files         317     317             
  Lines       36549   36549             
  Branches     1642    1642             
========================================
- Hits        22621   22614      -7     
- Misses      13891   13898      +7     
  Partials       37      37             

see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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