npm install helmetBasic Express Usage
To use a particular middleware application-wide, just use it from your app.Make sure it is listed before app.router.
If you just want to use the default-level policies, all you need to do is:
Defaults are semi-configurable too. If you wanted all the defaults but wanted your own xframe options you could do this:
Content Security PolicyThe is pretty much required reading if you want to do anything with CSP.
Browser SupportCurrently there is CSP support in Firefox and experimental support in Chrome. Both X-Content-Security-Policy and X-WebKit-CSPheaders are set by Helmet.
There are two different ways to build CSP policies with Helmet.
Using policy()policy() eats a JSON blob (including the output of it's own toJSON() function) to create a policy. By defaulthelmet has a defaultPolicy that looks like,kids bmx helmets;
Content-Security-Policy: default-src 'self'
To override this and create a new policy you could do something like
Using add()The same thing could be accomplished using add() since the defaultPolicy default-src is already 'self':
Reporting ViolationsCSP can report violations back to a specified URL. You can either set the report-uri using policy() or add() or use the reportTo() helper function.
HTTP Strict Transport SecurityThis middleware adds the Strict-Transport-Security header to the response.
Basic UsageTo use the default header of Strict-Transport-Security: maxAge=15768000:
To adjust other values for maxAge and to include subdomains:
X-FRAME-OPTIONSxFrame is a lot more straight forward than CSP. It has three modes. DENY, SAMEORIGIN,snowboarding helmets, ALLOW-FROM. If your app does not need to be framed (and most don't) you can use the default DENY.
Browser SupportHere is an example for both SAMEORIGIN and ALLOW-FROM:
X-XSS-PROTECTIONThe following example sets the X-XSS-PROTECTION: 1; mode=block header:
X-Content-Type-OptionsThe following example sets the X-Content-Type-Options header to it's only and default option, nosniff:
Cache-ControlThe following example sets the Cache-Control header to no-store,vintage motorcycle helmets, no-cache. This is not configurable at this time.
To Be Implemented
No comments:
Post a Comment