Skip to content

Commit 84c8a02

Browse files
authored
feat(fetch): remove CORB checks (nodejs#1461)
1 parent d023b2d commit 84c8a02

File tree

3 files changed

+2
-100
lines changed

3 files changed

+2
-100
lines changed

lib/fetch/index.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const {
3131
coarsenedSharedCurrentTime,
3232
createDeferredPromise,
3333
isBlobLike,
34-
CORBCheck,
3534
sameOrigin,
3635
isCancelled,
3736
isAborted
@@ -588,18 +587,8 @@ async function mainFetch (fetchParams, recursive = false) {
588587
// 2. Set request’s response tainting to "opaque".
589588
request.responseTainting = 'opaque'
590589

591-
// 3. Let noCorsResponse be the result of running scheme fetch given
592-
// fetchParams.
593-
const noCorsResponse = await schemeFetch(fetchParams)
594-
595-
// 4. If noCorsResponse is a filtered response or the CORB check with
596-
// request and noCorsResponse returns allowed, then return noCorsResponse.
597-
if (noCorsResponse.status === 0 || CORBCheck(request, noCorsResponse) === 'allowed') {
598-
return noCorsResponse
599-
}
600-
601-
// 5. Return a new response whose status is noCorsResponse’s status.
602-
return makeResponse({ status: noCorsResponse.status })
590+
// 3. Return the result of running scheme fetch given fetchParams.
591+
return await schemeFetch(fetchParams)
603592
}
604593

605594
// request’s current URL’s scheme is not an HTTP(S) scheme

lib/fetch/util.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -317,47 +317,6 @@ function sameOrigin (A, B) {
317317
return false
318318
}
319319

320-
// https://fetch.spec.whatwg.org/#corb-check
321-
function CORBCheck (request, response) {
322-
// 1. If request’s initiator is "download", then return allowed.
323-
if (request.initiator === 'download') {
324-
return 'allowed'
325-
}
326-
327-
// 2. If request’s current URL’s scheme is not an HTTP(S) scheme, then return allowed.
328-
if (!/^https?$/.test(request.currentURL.scheme)) {
329-
return 'allowed'
330-
}
331-
332-
// 3. Let mimeType be the result of extracting a MIME type from response’s header list.
333-
const mimeType = response.headersList.get('content-type')
334-
335-
// 4. If mimeType is failure, then return allowed.
336-
if (mimeType === '') {
337-
return 'allowed'
338-
}
339-
340-
// 5. If response’s status is 206 and mimeType is a CORB-protected MIME type, then return blocked.
341-
342-
const isCORBProtectedMIME =
343-
(/^text\/html\b/.test(mimeType) ||
344-
/^application\/javascript\b/.test(mimeType) ||
345-
/^application\/xml\b/.test(mimeType)) && !/^application\/xml\+svg\b/.test(mimeType)
346-
347-
if (response.status === 206 && isCORBProtectedMIME) {
348-
return 'blocked'
349-
}
350-
351-
// 6. If determine nosniff with response’s header list is true and mimeType is a CORB-protected MIME type or its essence is "text/plain", then return blocked.
352-
// https://fetch.spec.whatwg.org/#determinenosniff
353-
if (response.headersList.get('x-content-type-options') && isCORBProtectedMIME) {
354-
return 'blocked'
355-
}
356-
357-
// 7. Return allowed.
358-
return 'allowed'
359-
}
360-
361320
function createDeferredPromise () {
362321
let res
363322
let rej
@@ -430,7 +389,6 @@ module.exports = {
430389
isFileLike,
431390
isValidReasonPhrase,
432391
sameOrigin,
433-
CORBCheck,
434392
normalizeMethod,
435393
serializeJavascriptValueToJSONString
436394
}

test/fetch/util.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -113,48 +113,3 @@ test('sameOrigin', (t) => {
113113

114114
t.end()
115115
})
116-
117-
test('CORBCheck', (t) => {
118-
const allowedRequests = [{
119-
initiator: 'download',
120-
currentURL: { scheme: '' }
121-
}, {
122-
initiator: '',
123-
currentURL: { scheme: 'https' }
124-
}
125-
]
126-
127-
const response = { headersList: { get () { return '' } } }
128-
129-
allowedRequests.forEach((request) => {
130-
t.ok(util.CORBCheck(request, response))
131-
})
132-
133-
t.ok(util.CORBCheck({
134-
initiator: '',
135-
currentURL: { scheme: '' }
136-
}, response))
137-
138-
const protectedResponses = [{
139-
status: 206,
140-
headersList: { get () { return 'text/html' } }
141-
}, {
142-
status: 206,
143-
headersList: { get () { return 'application/javascript' } }
144-
}, {
145-
status: 206,
146-
headersList: { get () { return 'application/xml' } }
147-
}, {
148-
status: 218,
149-
headersList: { get (type) { return type === 'content-type' ? 'text/html' : 'x-content-type-options' } }
150-
}]
151-
152-
protectedResponses.forEach(response => {
153-
t.equal(util.CORBCheck({
154-
initiator: '',
155-
currentURL: { scheme: 'https' }
156-
}, response), 'blocked')
157-
})
158-
159-
t.end()
160-
})

0 commit comments

Comments
 (0)