krakenjs / lusca

Application security for express apps.
Other
1.79k stars 123 forks source link

Features found in helmet, not in lusca? #42

Closed gavinengel closed 9 years ago

gavinengel commented 9 years ago

I was just reviewing the features of helmetjs: https://www.npmjs.org/package/helmet

I see these features which don't appear to be a part of lusca. If that's true, are there plans to add them? Or perhaps is the recommended solution to simply use both lusca and helmet?

aredridel commented 9 years ago

Those are so delightfully compartmentalized, I'd say just use those!

gavinengel commented 9 years ago

@aredridel Good point. Do you feel it's worthwhile to cover my bases by using both the helmet modules and lusca for an average REST API? I'm wondering if I should even bother unless a need arises. I prefer to use Strongloop's Loopback, by the way.

aredridel commented 9 years ago

Both are good, both cover different cases: Write down a quick security model. Decide what attacks you need to mitigate, and mitigate them. Without context, it's really hard to do security. It's not a checklist. I don't think there's an "average" API.

You also have to investigate the costs of these things.

aredridel commented 9 years ago

One thing that neither set of modules addresses: rate limiting. That can be one of your biggest friends in designing a stable, resilient, secure API.

gavinengel commented 9 years ago

Wow. I thank you for that! Your notes are extremely helpful.

I was reviewing a slightly different solution of using a separate gateway to sit in front of any number of APIs (I suppose for people not using CloudFlare...) This way the security concerns can be addressed in a single project instead of inside every node REST API (and I suppose existing APIs written in other languages). Here is one example: https://github.com/strongloop/loopback-gateway

Aside from the user authentication in that project, I'd guess other features seem like they could be easily added to just about any other node framework. They include the rate limiter feature you mentioned in your last comment, too.

A final question if you wouldn't mind: Do you think it would be a bad idea to put the lusca/helmet packages on such a gateway instead of the APIs themselves?

aredridel commented 9 years ago

Not at all: just be aware of what security tasks require the application's knowledge. CSRF, for example, means the application has to pass a value with a request that an unrelated page can't guess, but a related one can include for verification.

XSS attack mitigation requires deep knowledge to fight well -- right down to what the expected output is in a given part of a page (html attribute, text, script, json -- there are so many escaping rules!) and whether or not that's restricted or not (came from the app or an end user) that doing it as a gateway is impossible, and even the middleware-based approaches are weak (lusca just triggers some IE headers to help out, doesn't even try to mitigate general cases)

X-frame options restrict your application. If your application fits within those constraints, the constraints can be applied outside -- but if part of your application needs to alter those options? You'll want them in app.

hidePoweredBy and p3p and hsts are good candidates for applying company-wide, and so a gateway makes a lot of sense.

gavinengel commented 9 years ago

Thanks again for your advice today.

aredridel commented 9 years ago

You are welcome! Good luck, and write down what you decide and why: it'll help you improve your security in the future if you have that as a reference.