Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Cookie leaking between domains #1199

Open
sami-sweng opened this issue Dec 17, 2019 · 1 comment
Open

Cookie leaking between domains #1199

sami-sweng opened this issue Dec 17, 2019 · 1 comment

Comments

@sami-sweng
Copy link

sami-sweng commented Dec 17, 2019

If domain-a tries to set a cookie for domain-b, the cookie shouldn't actually be set and sent to domain-b, when the browser does a call there.

Here is a sample displaying the issue.

setupServer(testClient);


// ---------- Setup server

function setupServer(callback) {
    const express = require('express');
    const app = express();

    app.get('/api/v1/test-set-cookies', function (req, res) {
        res.append('Set-Cookie', 'my-precious-cookie=my-secret-info-hehehe; path=/; HttpOnly; Domain=.domain-b.com');

        res.json({ ok: true });
    });

    app.get('/api/v1/test-get-cookies', function (req, res) {
        console.log('test-get-cookies', req.headers);

        res.json(req.headers);
    });

    const server = app.listen('8080', function () {
        console.log(server.address());
        callback();
    });
}


// ----------------- Test client

async function testClient() {
    const assert = require('assert');

    const Browser = require('zombie');

    const browser = new Browser({
        waitDuration: '30s',
        debug: true,
        runScripts: true
    });

    await browser.visit('http://www.domain-a.com:8080/api/v1/test-set-cookies');

    await browser.visit('http://www.domain-b.com:8080/api/v1/test-get-cookies');

    assert.equal(browser.text('body').includes('my-secret-info-hehehe'), false);
}

The sample requires express and obviously zombie.

It also requires adding

127.0.0.1 www.domain-a.com
127.0.0.1 www.domain-b.com

in /etc/hosts.


Notes:

  1. Running the server part only and making the two requests in either Chrome or Firefox doesn't display this behavior. This is what made me believe that Zombie might be too permissive.
  2. The sample should be transformable to a test case pretty easily.
@sami-sweng
Copy link
Author

sami-sweng commented Dec 17, 2019

I believe that what value for Domain would make a cookie be accepted or rejected is refined in the RFC 2675

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant