Unverified Commit 333c30b8 authored by Steven's avatar Steven Committed by GitHub

fix(next/image): swap dependencies (#85419)

Swapping `is-local-address` for `ipaddr.js`
parent c72b4263
......@@ -270,8 +270,8 @@
"icss-utils": "5.1.0",
"ignore-loader": "0.1.2",
"image-size": "1.2.1",
"ipaddr.js": "2.2.0",
"is-docker": "2.0.0",
"is-local-address": "2.2.2",
"is-wsl": "2.2.0",
"jest-worker": "27.5.1",
"json5": "2.2.3",
......
Copyright (C) 2011-2017 whitequark <whitequark@whitequark.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
This diff is collapsed.
{"name":"ipaddr.js","main":"ipaddr.js","author":"whitequark <whitequark@whitequark.org>","license":"MIT"}
(()=>{"use strict";var e={555:(e,f,a)=>{e.exports=e=>a(276)(e)||a(628)(e)},276:e=>{const f=["0(?:\\.\\d{1,3}){3}","10(?:\\.\\d{1,3}){3}","127(?:\\.\\d{1,3}){3}","169\\.254\\.(?:[1-9]|1?\\d\\d|2[0-4]\\d|25[0-4])\\.\\d{1,3}","172\\.(?:1[6-9]|2\\d|3[01])(?:\\.\\d{1,3}){2}","192\\.(?:0\\.0(?:\\.\\d{1,3})|0\\.2(?:\\.\\d{1,3})|168(?:\\.\\d{1,3}){2})","100\\.(?:6[4-9]|[7-9]\\d|1[01]\\d|12[0-7])(?:\\.\\d{1,3}){2}","198\\.(?:1[89](?:\\.\\d{1,3}){2}|51\\.100(?:\\.\\d{1,3}))","203\\.0\\.113(?:\\.\\d{1,3})","22[4-9](?:\\.\\d{1,3}){3}|23[0-9](?:\\.\\d{1,3}){3}","24[0-9](?:\\.\\d{1,3}){3}|25[0-5](?:\\.\\d{1,3}){3}","localhost"];const a=new RegExp(`^(${f.join("|")})$`);e.exports=a.test.bind(a);e.exports.regex=a},628:e=>{const f=[/^::f{4}:0?([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/,/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/,/^100:(:[0-9a-fA-F]{0,4}){0,6}$/,/^2001:(:[0-9a-fA-F]{0,4}){0,6}$/,/^2001:1[0-9a-fA-F]:([0-9a-fA-F]{0,4}:){0,7}[0-9a-fA-F]{0,4}$/,/^2001:2[0-9a-fA-F]?:([0-9a-fA-F]{0,4}:){0,7}[0-9a-fA-F]{0,4}$/,/^2001:db8:([0-9a-fA-F]{0,4}:){0,7}[0-9a-fA-F]{0,4}$/,/^3fff:([0-9a-fA-F]{0,4}:){0,7}[0-9a-fA-F]{0,4}$/,/^f[b-d][0-9a-fA-F]{2}:([0-9a-fA-F]{0,4}:){0,7}[0-9a-fA-F]{0,4}$/i,/^fe[8-9a-bA-B][0-9a-fA-F]:/i,/^ff([0-9a-fA-F]{2,2}):/i,/^ff00:([0-9a-fA-F]{0,4}:){0,7}[0-9a-fA-F]{0,4}$/,/^::1?$/,/^fec0:([0-9a-fA-F]{0,4}:){0,7}[0-9a-fA-F]{0,4}$/i,/^2002:([0-9a-fA-F]{0,4}:){0,7}[0-9a-fA-F]{0,4}$/];const a=new RegExp(`^(${f.map((e=>e.source)).join("|")})$`);e.exports=e=>{if(e.startsWith("[")&&e.endsWith("]")){e=e.slice(1,-1)}return a.test(e)};e.exports.regex=a}};var f={};function __nccwpck_require__(a){var r=f[a];if(r!==undefined){return r.exports}var d=f[a]={exports:{}};var t=true;try{e[a](d,d.exports,__nccwpck_require__);t=false}finally{if(t)delete f[a]}return d.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var a=__nccwpck_require__(555);module.exports=a})();
\ No newline at end of file
{"name":"is-local-address","main":"index.js","author":{"email":"josefrancisco.verdu@gmail.com","name":"Kiko Beats","url":"https://kikobeats.com"},"license":"MIT"}
......@@ -6,7 +6,6 @@ import contentDisposition from 'next/dist/compiled/content-disposition'
import imageSizeOf from 'next/dist/compiled/image-size'
import { detector } from 'next/dist/compiled/image-detector/detector.js'
import isAnimated from 'next/dist/compiled/is-animated'
import isLocalAddress from 'next/dist/compiled/is-local-address'
import { join } from 'path'
import nodeUrl, { type UrlWithParsedQuery } from 'url'
......@@ -28,6 +27,7 @@ import { sendEtagResponse } from './send-payload'
import { getContentType, getExtension } from './serve-static'
import * as Log from '../build/output/log'
import isError from '../lib/is-error'
import { isPrivateIp } from './is-private-ip'
import { parseUrl } from '../lib/url'
import type { CacheControl } from './lib/cache-control'
import { InvariantError } from '../shared/lib/invariant-error'
......@@ -724,7 +724,7 @@ export async function fetchExternalImage(
}).catch((_) => [{ address: hostname }])
ips = records.map((record) => record.address)
}
const privateIps = ips.filter((ip) => isLocalAddress(ip))
const privateIps = ips.filter((ip) => isPrivateIp(ip))
if (privateIps.length > 0) {
Log.error(
'upstream image',
......
import { isPrivateIp } from './is-private-ip'
describe('isPrivateIp', () => {
it('should return true for private ip addresses', () => {
expect(isPrivateIp('127.0.0.0')).toBe(true)
expect(isPrivateIp('127.0.0.1')).toBe(true)
expect(isPrivateIp('127.0.0.01')).toBe(true)
expect(isPrivateIp('127.0.0.001')).toBe(true)
expect(isPrivateIp('0.0.0.0')).toBe(true)
expect(isPrivateIp('10.0.0.0')).toBe(true)
expect(isPrivateIp('10.244.0.0')).toBe(true)
expect(isPrivateIp('192.168.0.0')).toBe(true)
expect(isPrivateIp('192.168.0.1')).toBe(true)
expect(isPrivateIp('192.168.0.01')).toBe(true)
expect(isPrivateIp('172.16.0.0')).toBe(true)
expect(isPrivateIp('172.16.0.1')).toBe(true)
expect(isPrivateIp('172.16.0.01')).toBe(true)
expect(isPrivateIp('192.168.0.1')).toBe(true)
expect(isPrivateIp('192.168.0.01')).toBe(true)
expect(isPrivateIp('169.254.169.254')).toBe(true)
expect(isPrivateIp('::')).toBe(true)
expect(isPrivateIp('::1')).toBe(true)
expect(isPrivateIp('::ffff:0.0.0.0')).toBe(true)
expect(isPrivateIp('::ffff:127.0.0.1')).toBe(true)
expect(isPrivateIp('::ffff:7f00:1')).toBe(true)
expect(isPrivateIp(new URL('http://0x7f000001').hostname)).toBe(true)
expect(isPrivateIp('2001:2f:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(true)
expect(isPrivateIp('[2001:2f:ffff:ffff:ffff:ffff:ffff:ffff]')).toBe(true)
expect(isPrivateIp('2002::')).toBe(true)
expect(isPrivateIp('ff00::')).toBe(true)
})
it('should return false for public ip addresses', () => {
expect(isPrivateIp('76.76.21.21')).toBe(false)
expect(isPrivateIp('157.240.14.35')).toBe(false)
expect(isPrivateIp('8.8.8.8')).toBe(false)
expect(isPrivateIp('1.1.1.1')).toBe(false)
expect(isPrivateIp('::ffff:8.8.8.8')).toBe(false)
expect(isPrivateIp('::ffff:1.1.1.1')).toBe(false)
expect(isPrivateIp('2001:4860:4860::8888')).toBe(false)
expect(isPrivateIp('2606:4700:4700::1111')).toBe(false)
})
it('should return false for domains', () => {
expect(isPrivateIp('vercel.com')).toBe(false)
expect(isPrivateIp('www.vercel.com')).toBe(false)
expect(isPrivateIp('nextjs.org')).toBe(false)
expect(isPrivateIp('docs.nextjs.org')).toBe(false)
})
})
import ipaddr from 'next/dist/compiled/ipaddr.js'
export function isPrivateIp(ip: string): boolean {
if (ip.startsWith('[') && ip.endsWith(']')) {
ip = ip.slice(1, -1)
}
if (!ipaddr.isValid(ip)) {
return false
}
try {
let addr = ipaddr.parse(ip)
if (addr.kind() === 'ipv6' && (addr as ipaddr.IPv6).isIPv4MappedAddress()) {
addr = (addr as ipaddr.IPv6).toIPv4Address()
}
const range = addr.range()
return range !== 'unicast'
} catch (e) {
return false
}
}
......@@ -1218,12 +1218,12 @@ export async function ncc_is_animated(task, opts) {
.ncc({ packageName: 'is-animated', externals })
.target('src/compiled/is-animated')
}
externals['is-local-address'] = 'next/dist/compiled/is-local-address'
export async function ncc_is_local_address(task, opts) {
externals['ipaddr.js'] = 'next/dist/compiled/ipaddr.js'
export async function ncc_ipaddr_js(task, opts) {
await task
.source(relative(__dirname, require.resolve('is-local-address')))
.ncc({ packageName: 'is-local-address', externals })
.target('src/compiled/is-local-address')
.source(relative(__dirname, require.resolve('ipaddr.js')))
.ncc({ packageName: 'ipaddr.js', externals })
.target('src/compiled/ipaddr.js')
}
externals['is-docker'] = 'next/dist/compiled/is-docker'
export async function ncc_is_docker(task, opts) {
......@@ -2248,7 +2248,7 @@ export async function ncc(task, opts) {
'ncc_http_proxy',
'ncc_ignore_loader',
'ncc_is_animated',
'ncc_is_local_address',
'ncc_ipaddr_js',
'ncc_is_docker',
'ncc_is_wsl',
'ncc_json5',
......
......@@ -860,8 +860,9 @@ declare module 'next/dist/compiled/is-animated' {
export default function isAnimated(buffer: Buffer): boolean
}
declare module 'next/dist/compiled/is-local-address' {
export default function isLocalAddress(ip: string): boolean
declare module 'next/dist/compiled/ipaddr.js' {
import * as m from 'ipaddr.js'
export = m
}
declare module 'next/dist/compiled/@opentelemetry/api' {
......
This diff is collapsed.
......@@ -142,8 +142,8 @@ const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
"/node_modules/next/dist/compiled/fresh/index.js",
"/node_modules/next/dist/compiled/image-detector/detector.js",
"/node_modules/next/dist/compiled/image-size/index.js",
"/node_modules/next/dist/compiled/ipaddr.js/ipaddr.js",
"/node_modules/next/dist/compiled/is-animated/index.js",
"/node_modules/next/dist/compiled/is-local-address/index.js",
"/node_modules/next/dist/compiled/jsonwebtoken/index.js",
"/node_modules/next/dist/compiled/nanoid/index.cjs",
"/node_modules/next/dist/compiled/next-server/app-page-turbo-experimental.runtime.prod.js",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment