@@ -135,7 +135,7 @@ import {envIsSupported} from '../testing/utils';
135135 name : 'other' ,
136136 installMode : 'lazy' ,
137137 updateMode : 'lazy' ,
138- urls : [ '/baz.txt' , '/qux.txt' , '/lazy/redirected.txt' ] ,
138+ urls : [ '/baz.txt' , '/qux.txt' , '/lazy/redirected.txt' , '/lazy/cross-origin-redirected.txt' ] ,
139139 patterns : [ ] ,
140140 cacheQueryOptions : { ignoreVary : true } ,
141141 } ,
@@ -220,6 +220,11 @@ import {envIsSupported} from '../testing/utils';
220220 . withStaticFiles ( dist )
221221 . withRedirect ( '/redirected.txt' , '/redirect-target.txt' )
222222 . withRedirect ( '/lazy/redirected.txt' , '/lazy/redirect-target.txt' )
223+ . withRedirect (
224+ '/lazy/cross-origin-redirected.txt' ,
225+ 'https://example.com/lazy/redirect-target.txt' ,
226+ )
227+ . withRedirect ( 'https://example.com/lazy/redirect-target.txt' , '/lazy/redirect-target.txt' )
223228 . withError ( '/error.txt' ) ;
224229
225230 const server = serverBuilderBase . withManifest ( manifest ) . build ( ) ;
@@ -1684,14 +1689,40 @@ import {envIsSupported} from '../testing/utils';
16841689 // Request a redirected, lazy-cached asset (so that it is fetched from the network) and
16851690 // provide headers.
16861691 const reqInit = {
1687- headers : { SomeHeader : 'SomeValue' } ,
1692+ headers : {
1693+ Authorization : 'Bearer secret' ,
1694+ SomeHeader : 'SomeValue' ,
1695+ } ,
16881696 } ;
16891697 expect ( await makeRequest ( scope , '/lazy/redirected.txt' , undefined , reqInit ) ) . toBe (
16901698 'this was a redirect too' ,
16911699 ) ;
16921700
16931701 // Verify that the headers were passed through to the network.
16941702 const [ redirectReq ] = server . getRequestsFor ( '/lazy/redirect-target.txt' ) ;
1703+ expect ( redirectReq . headers . get ( 'Authorization' ) ) . toBe ( 'Bearer secret' ) ;
1704+ expect ( redirectReq . headers . get ( 'SomeHeader' ) ) . toBe ( 'SomeValue' ) ;
1705+ } ) ;
1706+
1707+ it ( 'does not pass sensitive headers through to a different origin' , async ( ) => {
1708+ const reqInit = {
1709+ headers : {
1710+ Authorization : 'Bearer secret' ,
1711+ Cookie : 'session=secret' ,
1712+ 'Proxy-Authorization' : 'Basic secret' ,
1713+ SomeHeader : 'SomeValue' ,
1714+ } ,
1715+ } ;
1716+ expect (
1717+ await makeRequest ( scope , '/lazy/cross-origin-redirected.txt' , undefined , reqInit ) ,
1718+ ) . toBe ( 'this was a redirect too' ) ;
1719+
1720+ const [ redirectReq ] = server . getRequestsFor (
1721+ 'https://example.com/lazy/redirect-target.txt' ,
1722+ ) ;
1723+ expect ( redirectReq . headers . get ( 'Authorization' ) ) . toBeNull ( ) ;
1724+ expect ( redirectReq . headers . get ( 'Cookie' ) ) . toBeNull ( ) ;
1725+ expect ( redirectReq . headers . get ( 'Proxy-Authorization' ) ) . toBeNull ( ) ;
16951726 expect ( redirectReq . headers . get ( 'SomeHeader' ) ) . toBe ( 'SomeValue' ) ;
16961727 } ) ;
16971728
0 commit comments