GithubHelp home page GithubHelp logo

Comments (4)

hb9cwp avatar hb9cwp commented on July 21, 2024

Indeed, the RFC states in section 7.2 "An HSTS Host MUST NOT include the STS header field in HTTP responses conveyed over non-secure transport."

However, I can not find an equivalent for req.secure in Connect in order to suggest a fix for the if statement.

from helmet.

EvanHahn avatar EvanHahn commented on July 21, 2024

Here's how req.secure is defined in Express:

req.__defineGetter__('secure', function(){
  return 'https' == this.protocol;
});

And then req.protocol is defined like this:

req.__defineGetter__('protocol', function(){
  var trustProxy = this.app.get('trust proxy');
  if (this.connection.encrypted) return 'https';
  if (!trustProxy) return 'http';
  var proto = this.get('X-Forwarded-Proto') || 'http';
  return proto.split(/\s*,\s*/)[0];
});

So it's a little hairy, because it starts to get more complex.

Any ideas? Maybe we should detect Express and do what we currently do, and if Express isn't there, then do something else.

from helmet.

EvanHahn avatar EvanHahn commented on July 21, 2024

Just wrote isExpress, which might help us.

from helmet.

EvanHahn avatar EvanHahn commented on July 21, 2024

Right now, we have a boolean called isSecure, and if it's true, then it sets the header.

What if we defined it like this:

var isSecure = (req.secure) ||
  (req.connection.encrypted) ||
  (req.headers['front-end-https'] == 'on') ||
  (req.headers['x-forwarded-proto'] == 'https');

Would that be enough?

I also think we should add a force option that skips this detection.

from helmet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.