This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 2 files changed +18
-1
lines changed
src/http/gateway/resources
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ module.exports = {
76
76
// add trailing slash for directories with implicit index.html
77
77
return h . redirect ( `${ path } /` ) . permanent ( true )
78
78
}
79
+ if ( request . headers [ 'service-worker' ] === 'script' ) {
80
+ // Disallow Service Worker registration on /ipfs scope
81
+ // https://github.com/ipfs/go-ipfs/issues/4025
82
+ if ( path . match ( / ^ \/ i p [ n f ] s \/ [ ^ / ] + $ / ) ) throw Boom . badRequest ( 'navigator.serviceWorker: registration is not allowed for this scope' )
83
+ }
79
84
80
85
// Support If-None-Match & Etag (Conditional Requests from RFC7232)
81
86
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ describe('HTTP Gateway', function () {
105
105
expect ( res . headers . suborigin ) . to . equal ( undefined )
106
106
} )
107
107
108
- it ( '400 for request with invalid argument' , async ( ) => {
108
+ it ( 'returns 400 for request with invalid argument' , async ( ) => {
109
109
const res = await gateway . inject ( {
110
110
method : 'GET' ,
111
111
url : '/ipfs/invalid'
@@ -118,6 +118,18 @@ describe('HTTP Gateway', function () {
118
118
expect ( res . headers . suborigin ) . to . equal ( undefined )
119
119
} )
120
120
121
+ it ( 'returns 400 for service worker registration outside of an IPFS content root' , async ( ) => {
122
+ const res = await gateway . inject ( {
123
+ method : 'GET' ,
124
+ url : '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o?filename=sw.js' ,
125
+ headers : { 'Service-Worker' : 'script' }
126
+ } )
127
+
128
+ // Expect 400 Bad Request
129
+ // https://github.com/ipfs/go-ipfs/issues/4025#issuecomment-342250616
130
+ expect ( res . statusCode ) . to . equal ( 400 )
131
+ } )
132
+
121
133
it ( 'valid CIDv0' , async ( ) => {
122
134
const res = await gateway . inject ( {
123
135
method : 'GET' ,
You can’t perform that action at this time.
0 commit comments