@@ -135,7 +135,9 @@ describe('Validation Utils', () => {
135135 } ) ;
136136 const { request : secured , onError } = cloneRequestAndPatchHeaders ( req , allowedHosts ) ;
137137
138- expect ( secured . headers . get ( 'host' ) ) . toBeNull ( ) ;
138+ expect ( ( ) => secured . headers . get ( 'host' ) ) . toThrowError (
139+ 'Header "host" with value "evil.com" is not allowed.' ,
140+ ) ;
139141 await expectAsync ( onError ) . toBeResolvedTo (
140142 jasmine . objectContaining ( {
141143 message : jasmine . stringMatching ( 'Header "host" with value "evil.com" is not allowed' ) ,
@@ -157,7 +159,9 @@ describe('Validation Utils', () => {
157159 } ) ;
158160 const { request : secured , onError } = cloneRequestAndPatchHeaders ( req , allowedHosts ) ;
159161
160- expect ( secured . headers . get ( 'x-forwarded-host' ) ) . toBeNull ( ) ;
162+ expect ( ( ) => secured . headers . get ( 'x-forwarded-host' ) ) . toThrowError (
163+ 'Header "x-forwarded-host" with value "evil.com" is not allowed.' ,
164+ ) ;
161165 await expectAsync ( onError ) . toBeResolvedTo (
162166 jasmine . objectContaining ( {
163167 message : jasmine . stringMatching (
@@ -175,5 +179,62 @@ describe('Validation Utils', () => {
175179
176180 expect ( secured . headers . get ( 'accept' ) ) . toBe ( 'application/json' ) ;
177181 } ) ;
182+
183+ it ( 'should validate headers when iterating with entries()' , async ( ) => {
184+ const req = new Request ( 'http://example.com' , {
185+ headers : { 'host' : 'evil.com' } ,
186+ } ) ;
187+ const { request : secured , onError } = cloneRequestAndPatchHeaders ( req , allowedHosts ) ;
188+
189+ expect ( ( ) => {
190+ for ( const _ of secured . headers . entries ( ) ) {
191+ // access the header to trigger the validation
192+ }
193+ } ) . toThrowError ( 'Header "host" with value "evil.com" is not allowed.' ) ;
194+
195+ await expectAsync ( onError ) . toBeResolvedTo (
196+ jasmine . objectContaining ( {
197+ message : jasmine . stringMatching ( 'Header "host" with value "evil.com" is not allowed.' ) ,
198+ } ) ,
199+ ) ;
200+ } ) ;
201+
202+ it ( 'should validate headers when iterating with values()' , async ( ) => {
203+ const req = new Request ( 'http://example.com' , {
204+ headers : { 'host' : 'evil.com' } ,
205+ } ) ;
206+ const { request : secured , onError } = cloneRequestAndPatchHeaders ( req , allowedHosts ) ;
207+
208+ expect ( ( ) => {
209+ for ( const _ of secured . headers . values ( ) ) {
210+ // access the header to trigger the validation
211+ }
212+ } ) . toThrowError ( 'Header "host" with value "evil.com" is not allowed.' ) ;
213+
214+ await expectAsync ( onError ) . toBeResolvedTo (
215+ jasmine . objectContaining ( {
216+ message : jasmine . stringMatching ( 'Header "host" with value "evil.com" is not allowed.' ) ,
217+ } ) ,
218+ ) ;
219+ } ) ;
220+
221+ it ( 'should validate headers when iterating with for...of' , async ( ) => {
222+ const req = new Request ( 'http://example.com' , {
223+ headers : { 'host' : 'evil.com' } ,
224+ } ) ;
225+ const { request : secured , onError } = cloneRequestAndPatchHeaders ( req , allowedHosts ) ;
226+
227+ expect ( ( ) => {
228+ for ( const _ of secured . headers ) {
229+ // access the header to trigger the validation
230+ }
231+ } ) . toThrowError ( 'Header "host" with value "evil.com" is not allowed.' ) ;
232+
233+ await expectAsync ( onError ) . toBeResolvedTo (
234+ jasmine . objectContaining ( {
235+ message : jasmine . stringMatching ( 'Header "host" with value "evil.com" is not allowed.' ) ,
236+ } ) ,
237+ ) ;
238+ } ) ;
178239 } ) ;
179240} ) ;
0 commit comments