@@ -179,6 +179,39 @@ describe('Authentication API (OIDC)', () => {
179179 } )
180180 } )
181181
182+ describe ( 'with that cookie and a non-matching origin' , ( ) => {
183+ let response
184+ before ( done => {
185+ alice . get ( '/private-for-alice.txt' )
186+ . set ( 'Cookie' , cookie )
187+ . set ( 'Origin' , bobServerUri )
188+ . end ( ( err , res ) => {
189+ response = res
190+ done ( err )
191+ } )
192+ } )
193+
194+ it ( 'should return a 403' , ( ) => {
195+ expect ( response ) . to . have . property ( 'status' , 403 )
196+ } )
197+ } )
198+
199+ describe ( 'without that cookie and a non-matching origin' , ( ) => {
200+ let response
201+ before ( done => {
202+ alice . get ( '/private-for-alice.txt' )
203+ . set ( 'Origin' , bobServerUri )
204+ . end ( ( err , res ) => {
205+ response = res
206+ done ( err )
207+ } )
208+ } )
209+
210+ it ( 'should return a 401' , ( ) => {
211+ expect ( response ) . to . have . property ( 'status' , 401 )
212+ } )
213+ } )
214+
182215 describe ( 'with that cookie but without origin' , ( ) => {
183216 let response
184217 before ( done => {
@@ -195,6 +228,19 @@ describe('Authentication API (OIDC)', () => {
195228 } )
196229 } )
197230
231+ describe ( 'with that cookie, private resource and no origin set' , ( ) => {
232+ before ( done => {
233+ alice . get ( '/private-for-alice.txt' )
234+ . set ( 'Cookie' , cookie )
235+ . end ( ( err , res ) => {
236+ response = res
237+ done ( err )
238+ } )
239+ } )
240+
241+ it ( 'should return a 200' , ( ) => expect ( response ) . to . have . property ( 'status' , 200 ) )
242+ } )
243+
198244 // How Mallory might set their cookie:
199245 describe ( 'with malicious cookie but without origin' , ( ) => {
200246 let response
@@ -296,8 +342,8 @@ describe('Authentication API (OIDC)', () => {
296342 } )
297343 } )
298344
299- it ( 'should return a 403 ' , ( ) => {
300- expect ( response ) . to . have . property ( 'status' , 403 ) // TODO: Should be 401?
345+ it ( 'should return a 401 ' , ( ) => {
346+ expect ( response ) . to . have . property ( 'status' , 401 )
301347 } )
302348 } )
303349
@@ -315,8 +361,8 @@ describe('Authentication API (OIDC)', () => {
315361 } )
316362 } )
317363
318- it ( 'should return a 403 ' , ( ) => {
319- expect ( response ) . to . have . property ( 'status' , 403 )
364+ it ( 'should return a 401 ' , ( ) => {
365+ expect ( response ) . to . have . property ( 'status' , 401 )
320366 } )
321367 } )
322368
@@ -333,8 +379,8 @@ describe('Authentication API (OIDC)', () => {
333379 } )
334380 } )
335381
336- it ( 'should return a 403 ' , ( ) => {
337- expect ( response ) . to . have . property ( 'status' , 403 )
382+ it ( 'should return a 401 ' , ( ) => {
383+ expect ( response ) . to . have . property ( 'status' , 401 )
338384 } )
339385 } )
340386
@@ -356,7 +402,24 @@ describe('Authentication API (OIDC)', () => {
356402 } )
357403 } )
358404
359- // Authenticated but origin not OK
405+ describe ( 'with malicious cookie and our origin' , ( ) => {
406+ let response
407+ before ( done => {
408+ var malcookie = cookie . replace ( / c o n n e c t \. s i d = ( \S + ) / , 'connect.sid=l33th4x0rzp0wn4g3;' )
409+ alice . get ( '/private-for-alice.txt' )
410+ . set ( 'Cookie' , malcookie )
411+ . set ( 'Origin' , aliceServerUri )
412+ . end ( ( err , res ) => {
413+ response = res
414+ done ( err )
415+ } )
416+ } )
417+
418+ it ( 'should return a 401' , ( ) => {
419+ expect ( response ) . to . have . property ( 'status' , 401 )
420+ } )
421+ } )
422+
360423 describe ( 'with malicious cookie and a non-matching origin' , ( ) => {
361424 let response
362425 before ( done => {
@@ -370,8 +433,8 @@ describe('Authentication API (OIDC)', () => {
370433 } )
371434 } )
372435
373- it ( 'should return a 403 ' , ( ) => {
374- expect ( response ) . to . have . property ( 'status' , 403 )
436+ it ( 'should return a 401 ' , ( ) => {
437+ expect ( response ) . to . have . property ( 'status' , 401 )
375438 } )
376439 } )
377440 } )
0 commit comments