@@ -30,7 +30,8 @@ const {
3030 crossOriginResourcePolicyCheck,
3131 determineRequestsReferrer,
3232 coarsenedSharedCurrentTime,
33- createDeferredPromise
33+ createDeferredPromise,
34+ sameOrigin
3435} = require ( './util' )
3536const { kState, kHeaders, kGuard, kRealm } = require ( './symbols' )
3637const { AbortError } = require ( '../core/errors' )
@@ -480,7 +481,7 @@ async function mainFetch (fetchParams, recursive = false) {
480481 request . localURLsOnly &&
481482 ! / ^ ( a b o u t | b l o b | d a t a ) : / . test ( requestCurrentURL ( request ) . protocol )
482483 ) {
483- return makeNetworkError ( 'local URLs only' )
484+ response = makeNetworkError ( 'local URLs only' )
484485 }
485486
486487 // 4. Run report Content Security Policy violations for request.
@@ -493,7 +494,7 @@ async function mainFetch (fetchParams, recursive = false) {
493494 // be blocked as mixed content, or should request be blocked by Content
494495 // Security Policy returns blocked, then set response to a network error.
495496 if ( requestBadPort ( request ) === 'blocked' ) {
496- return makeNetworkError ( 'bad port' )
497+ response = makeNetworkError ( 'bad port' )
497498 }
498499 // TODO: should fetching request be blocked as mixed content?
499500 // TODO: should request be blocked by Content Security Policy?
@@ -938,7 +939,7 @@ async function httpRedirectFetch (fetchParams, response) {
938939 if (
939940 request . mode === 'cors' &&
940941 ( locationURL . username || locationURL . password ) &&
941- request . origin !== locationURL . origin
942+ ! sameOrigin ( request , locationURL )
942943 ) {
943944 return makeNetworkError ( 'cross origin not allowed for request mode "cors"' )
944945 }
@@ -964,17 +965,7 @@ async function httpRedirectFetch (fetchParams, response) {
964965 return makeNetworkError ( )
965966 }
966967
967- // 12. If locationURL’s origin is not same origin with request’s current URL’s
968- // origin and request’s origin is not same origin with request’s current
969- // URL’s origin, then set request’s tainted origin flag.
970- if (
971- locationURL . origin !== requestCurrentURL ( request ) . origin &&
972- request . origin !== locationURL . origin
973- ) {
974- request . taintedOrigin = true
975- }
976-
977- // 13. If one of the following is true
968+ // 12. If one of the following is true
978969 // - actualResponse’s status is 301 or 302 and request’s method is `POST`
979970 // - actualResponse’s status is 303 and request’s method is not `GET` or `HEAD`
980971 if (
@@ -994,36 +985,36 @@ async function httpRedirectFetch (fetchParams, response) {
994985 }
995986 }
996987
997- // 14 . If request’s body is non-null, then set request’s body to the first return
988+ // 13 . If request’s body is non-null, then set request’s body to the first return
998989 // value of safely extracting request’s body’s source.
999990 if ( request . body != null ) {
1000991 assert ( request . body . source )
1001992 request . body = safelyExtractBody ( request . body . source ) [ 0 ]
1002993 }
1003994
1004- // 15 . Let timingInfo be fetchParams’s timing info.
995+ // 14 . Let timingInfo be fetchParams’s timing info.
1005996 const timingInfo = fetchParams . timingInfo
1006997
1007- // 16 . Set timingInfo’s redirect end time and post-redirect start time to the
998+ // 15 . Set timingInfo’s redirect end time and post-redirect start time to the
1008999 // coarsened shared current time given fetchParams’s cross-origin isolated
10091000 // capability.
10101001 timingInfo . redirectEndTime = timingInfo . postRedirectStartTime =
10111002 coarsenedSharedCurrentTime ( fetchParams . crossOriginIsolatedCapability )
10121003
1013- // 17 . If timingInfo’s redirect start time is 0, then set timingInfo’s
1004+ // 16 . If timingInfo’s redirect start time is 0, then set timingInfo’s
10141005 // redirect start time to timingInfo’s start time.
10151006 if ( timingInfo . redirectStartTime === 0 ) {
10161007 timingInfo . redirectStartTime = timingInfo . startTime
10171008 }
10181009
1019- // 18 . Append locationURL to request’s URL list.
1010+ // 17 . Append locationURL to request’s URL list.
10201011 request . urlList . push ( locationURL )
10211012
1022- // 19 . Invoke set request’s referrer policy on redirect on request and
1013+ // 18 . Invoke set request’s referrer policy on redirect on request and
10231014 // actualResponse.
10241015 setRequestReferrerPolicyOnRedirect ( request , actualResponse )
10251016
1026- // 20 . Return the result of running main fetch given fetchParams and true.
1017+ // 19 . Return the result of running main fetch given fetchParams and true.
10271018 return mainFetch . call ( this , fetchParams , true )
10281019}
10291020
0 commit comments