File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,10 @@ Agent.prototype = Object.create(AgentBase.prototype);
65
65
66
66
Agent . prototype . _saveCookies = function ( res ) {
67
67
const cookies = res . headers [ 'set-cookie' ] ;
68
- if ( cookies ) this . jar . setCookies ( cookies ) ;
68
+ if ( cookies ) {
69
+ const url = parse ( res . request ?. url || '' )
70
+ this . jar . setCookies ( cookies , url . hostname , url . pathname ) ;
71
+ }
69
72
} ;
70
73
71
74
/**
Original file line number Diff line number Diff line change @@ -120,6 +120,16 @@ describe('request', () => {
120
120
assert . strictEqual ( res . text , 'jar' ) ;
121
121
} ) ) ;
122
122
123
+ it ( 'should not share cookies between domains' , ( ) => {
124
+ assert . equal ( agent4 . get ( 'https://google.com' ) . cookies , "" ) ;
125
+ } ) ;
126
+
127
+ it ( 'should send cookies to allowed domain with a different path' , ( ) => {
128
+ const postRequest = agent4 . post ( `${ base } /x/y/z` )
129
+ const cookiesNames = postRequest . cookies . split ( ';' ) . map ( cookie => cookie . split ( '=' ) [ 0 ] )
130
+ cookiesNames . should . eql ( [ 'cookie' , ' connect.sid' ] ) ;
131
+ } ) ;
132
+
123
133
it ( 'should not share cookies' , ( done ) => {
124
134
agent2 . get ( `${ base } /dashboard` ) . end ( ( error , res ) => {
125
135
should . exist ( error ) ;
You can’t perform that action at this time.
0 commit comments