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.
276
+
277
+
__Note__: Regardless of the configuration specified, Secure cookies are only enabled for HTTPS requests.
278
+
279
+
#### Boolean-based configuration
280
+
281
+
Boolean-based configuration is intended to globally enable or disable a specific cookie attribute.
282
+
283
+
```ruby
284
+
config.cookies = {
285
+
secure:true, # mark all cookies as Secure
286
+
httponly:false, # do not mark any cookies as HttpOnly
287
+
}
288
+
```
289
+
290
+
#### Hash-based configuration
291
+
292
+
Hash-based configuration allows for fine-grained control.
293
+
294
+
```ruby
295
+
config.cookies = {
296
+
secure: { except: ['_guest'] }, # mark all but the `_guest` cookie as Secure
297
+
httponly: { only: ['_rails_session'] }, # only mark the `_rails_session` cookie as HttpOnly
298
+
}
299
+
```
300
+
301
+
#### SameSite cookie configuration
302
+
303
+
SameSite cookies permit either `Strict` or `Lax` enforcement mode options.
304
+
305
+
```ruby
306
+
config.cookies = {
307
+
samesite: {
308
+
strict:true# mark all cookies as SameSite=Strict
309
+
}
310
+
}
311
+
```
312
+
313
+
`Strict` and `Lax` enforcement modes can also be specified using a Hash.
314
+
315
+
```ruby
316
+
config.cookies = {
317
+
samesite: {
318
+
strict: { only: ['_rails_session'] },
319
+
lax: { only: ['_guest'] }
320
+
}
321
+
}
322
+
```
323
+
267
324
### Using with Sinatra
268
325
269
326
Here's an example using SecureHeaders for Sinatra applications:
0 commit comments