Skip to content

Commit

Permalink
fix(cookies): send cookies to allowed domains
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiraNagen committed Dec 15, 2022
1 parent 3adc458 commit e98489a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/node/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ Agent.prototype = Object.create(AgentBase.prototype);

Agent.prototype._saveCookies = function (res) {
const cookies = res.headers['set-cookie'];
if (cookies) this.jar.setCookies(cookies);
if (cookies) {
const url = parse(res.request?.url || '')
this.jar.setCookies(cookies, url.hostname, url.pathname);
}
};

/**
Expand Down
10 changes: 10 additions & 0 deletions test/node/agency.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ describe('request', () => {
assert.strictEqual(res.text, 'jar');
}));

it('should not share cookies between domains', () => {
assert.equal(agent4.get('https://google.com').cookies, "");
});

it('should send cookies to allowed domain with a different path', () => {
const postRequest = agent4.post(`${base}/x/y/z`)
const cookiesNames = postRequest.cookies.split(';').map(cookie => cookie.split('=')[0])
cookiesNames.should.eql(['cookie', ' connect.sid']);
});

it('should not share cookies', (done) => {
agent2.get(`${base}/dashboard`).end((error, res) => {
should.exist(error);
Expand Down

0 comments on commit e98489a

Please sign in to comment.