11import type { Duplex } from 'stream'
22import type { IncomingMessage , ServerResponse } from 'webpack-dev-server'
33import { parseUrl } from '../../../lib/url'
4- import net from 'net'
54import { warnOnce } from '../../../build/output/log'
65import { isCsrfOriginAllowed } from '../../app-render/csrf-protection'
76
@@ -36,8 +35,7 @@ export const blockCrossSite = (
3635 req : IncomingMessage ,
3736 res : ServerResponse | Duplex ,
3837 allowedDevOrigins : string [ ] | undefined ,
39- hostname : string | undefined ,
40- activePort : string
38+ hostname : string | undefined
4139) : boolean => {
4240 // in the future, these will be blocked by default when allowed origins aren't configured.
4341 // for now, we warn when allowed origins aren't configured
@@ -52,7 +50,7 @@ export const blockCrossSite = (
5250 allowedOrigins . push ( hostname )
5351 }
5452
55- // only process _next URLs when
53+ // only process _next URLs
5654 if ( ! req . url ?. includes ( '/_next' ) ) {
5755 return false
5856 }
@@ -73,16 +71,8 @@ export const blockCrossSite = (
7371
7472 if ( parsedOrigin ) {
7573 const originLowerCase = parsedOrigin . hostname . toLowerCase ( )
76- const isMatchingPort = parsedOrigin . port === activePort
77- const isIpRequest =
78- net . isIPv4 ( originLowerCase ) || net . isIPv6 ( originLowerCase )
7974
80- if (
81- // allow requests if direct IP and matching port and
82- // allow if any of the allowed origins match
83- ! ( isIpRequest && isMatchingPort ) &&
84- ! isCsrfOriginAllowed ( originLowerCase , allowedOrigins )
85- ) {
75+ if ( ! isCsrfOriginAllowed ( originLowerCase , allowedOrigins ) ) {
8676 return warnOrBlockRequest ( res , originLowerCase , mode )
8777 }
8878 }
0 commit comments