Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential solution for Cookie options(secure) in Local HTTP Environments #982

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function session(options) {
}

// only send secure cookies via https
if (req.session.cookie.secure && !issecure(req, trustProxy)) {
if (req.session.cookie.secure && !issecure(req, trustProxy) && !isRunningLocally()) {
debug('not secured');
return;
}
Expand Down Expand Up @@ -654,6 +654,23 @@ function issecure(req, trustProxy) {
return proto === 'https';
}

/**
* Determine if application is running locally.
*
* @return {Boolean}
* @private
*/

function isRunningLocally() {
if (os.hostname() === 'localhost') {
return true;
}
var interfaces = os.networkInterfaces();
return Object.values(interfaces).flat().some(iface =>
iface.address === '127.0.0.1' || iface.address === '::1'
);
}

/**
* Set cookie on response.
*
Expand Down