You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-2Lines changed: 59 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ The gem will automatically apply several headers that are related to security.
15
15
- X-Permitted-Cross-Domain-Policies - [Restrict Adobe Flash Player's access to data](https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html)
16
16
- Public Key Pinning - Pin certificate fingerprints in the browser to prevent man-in-the-middle attacks due to compromised Certificate Authorities. [Public Key Pinning Specification](https://tools.ietf.org/html/rfc7469)
17
17
18
-
It can also mark all http cookies with the secure attribute (when configured to do so).
18
+
It can also mark all http cookies with the Secure, HttpOnly and SameSite attributes (when configured to do so).
19
19
20
20
`secure_headers` is a library with a global config, per request overrides, and rack middleware that enables you customize your application settings.
21
21
@@ -31,7 +31,13 @@ All `nil` values will fallback to their default values. `SecureHeaders::OPT_OUT`
31
31
32
32
```ruby
33
33
SecureHeaders::Configuration.default do |config|
34
-
config.secure_cookies =true# mark all cookies as "secure"
SecureHeaders supports `Secure`, `HttpOnly` and [`SameSite`](https://tools.ietf.org/html/draft-west-first-party-cookies-07) cookies. These can be defined in the form of a boolean, or as a Hash for more refined configuration.
334
+
335
+
__Note__: Regardless of the configuration specified, Secure cookies are only enabled for HTTPS requests.
336
+
337
+
#### Boolean-based configuration
338
+
339
+
Boolean-based configuration is intended to globally enable or disable a specific cookie attribute.
340
+
341
+
```ruby
342
+
config.cookies = {
343
+
secure: true, # mark all cookies as Secure
344
+
httponly: false, # do not mark any cookies as HttpOnly
345
+
}
346
+
```
347
+
348
+
#### Hash-based configuration
349
+
350
+
Hash-based configuration allows for fine-grained control.
351
+
352
+
```ruby
353
+
config.cookies = {
354
+
secure: { except: ['_guest'] }, # mark all but the `_guest` cookie as Secure
355
+
httponly: { only: ['_rails_session'] }, # only mark the `_rails_session` cookie as HttpOnly
356
+
}
357
+
```
358
+
359
+
#### SameSite cookie configuration
360
+
361
+
SameSite cookies permit either `Strict` or `Lax` enforcement mode options.
362
+
363
+
```ruby
364
+
config.cookies = {
365
+
samesite: {
366
+
strict:true# mark all cookies as SameSite=Strict
367
+
}
368
+
}
369
+
```
370
+
371
+
`Strict` and `Lax` enforcement modes can also be specified using a Hash.
372
+
373
+
```ruby
374
+
config.cookies = {
375
+
samesite: {
376
+
strict: { only: ['_rails_session'] },
377
+
lax: { only: ['_guest'] }
378
+
}
379
+
}
380
+
```
381
+
325
382
### Using with Sinatra
326
383
327
384
Here's an example using SecureHeaders for Sinatra applications:
0 commit comments