Skip to content

Commit

Permalink
Merge pull request #1757 from ShiraNagen/cookies-domains
Browse files Browse the repository at this point in the history
Send cookies to allowed domains
  • Loading branch information
titanism authored Jan 18, 2023
2 parents 759acfc + e98489a commit 93835cb
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 93835cb

Please sign in to comment.