Skip to content

Commit a5806e7

Browse files
committed
fix: handle localhost images in SongPage component to prevent Next.js 15 private IP errors
- Implemented logic to disable image optimization for localhost URLs, addressing security concerns related to CVE-2025-55173. - Added comments for clarity on the workaround and its implications for development versus production environments.
1 parent 0de0449 commit a5806e7

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

apps/frontend/src/modules/song/components/SongPage.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ export async function SongPage({ id }: { id: string }) {
6464
console.error('Failed to retrieve suggested songs');
6565
}
6666

67+
// Check if the image is from localhost to avoid Next.js 15 private IP errors
68+
// Next.js 15 blocks images from private IPs (localhost, 127.0.0.1, ::1) for security reasons.
69+
// This is related to CVE-2025-55173 security vulnerability.
70+
// Sources:
71+
// - https://nextjs.org/blog/next-15 (Next.js 15 release notes)
72+
// - https://advisories.gitlab.com/pkg/npm/next/CVE-2025-55173/ (Security advisory)
73+
// - https://github.com/vercel/next.js/discussions/50617 (GitHub discussion)
74+
// - https://learnspace.blog/blog/the-right-way-to-handle-images-in-next-js-15
75+
// Workaround: Use unoptimized={true} for localhost images to bypass the optimization API
76+
// which triggers the private IP check. This only affects development; production images
77+
// from external sources will still be optimized.
78+
const isLocalhost =
79+
song.thumbnailUrl.startsWith('http://localhost') ||
80+
song.thumbnailUrl.startsWith('http://127.0.0.1') ||
81+
song.thumbnailUrl.startsWith('http://[::1]');
82+
6783
return (
6884
<>
6985
<div className='grid grid-cols-8 gap-12'>
@@ -72,9 +88,10 @@ export async function SongPage({ id }: { id: string }) {
7288
{/* TODO: implement loading https://github.com/vercel/next.js/discussions/50617 */}
7389
<picture className='bg-zinc-800 aspect-[5/3] rounded-xl'>
7490
<Image
91+
unoptimized={isLocalhost}
92+
alt='Song thumbnail'
7593
width={1280}
7694
height={720}
77-
alt='Song thumbnail'
7895
src={song.thumbnailUrl}
7996
className='w-full h-full rounded-xl'
8097
/>

0 commit comments

Comments
 (0)