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
@@ -154,7 +156,7 @@ If your framework uses a different contract, see the framework specific guides o
154
156
155
157
## Middleware
156
158
157
-
`secure.middleware` re-exports `SecureWSGIMiddleware` and `SecureASGIMiddleware`. Each middleware accepts a `Secure` instance (defaulting to `Secure.with_default_headers()`), overwrites headers by default, and only appends duplicates when a normalized name is included in `multi_ok` (the default `secure.secure.MULTI_OK` includes `Content-Security-Policy`).
159
+
`secure.middleware` re-exports `SecureWSGIMiddleware` and `SecureASGIMiddleware`. Each middleware accepts a `Secure` instance (defaulting to `Secure.with_default_headers()`), overwrites headers by default, and only appends duplicates when a normalized name is included in `multi_ok` (the default `secure.MULTI_OK` includes `Content-Security-Policy`).
Other headers, such as `StrictTransportSecurity`, `CrossOriginOpenerPolicy`, `CrossOriginEmbedderPolicy`, `ReferrerPolicy`, `Server`, and `XFrameOptions`, also have small builder classes that mirror their directive structure.
@@ -387,27 +388,28 @@ For most applications, it is enough to construct a `Secure` instance and call `s
387
388
388
389
```python
389
390
import logging
390
-
import secure
391
+
392
+
from secure importCOMMA_JOIN_OK, DEFAULT_ALLOWED_HEADERS, MULTI_OK, Secure
391
393
392
394
logger = logging.getLogger("secure")
393
395
394
396
secure_headers = (
395
-
secure.Secure.with_default_headers()
397
+
Secure.with_default_headers()
396
398
.allowlist_headers(
397
-
allowed=secure.DEFAULT_ALLOWED_HEADERS,
399
+
allowed=DEFAULT_ALLOWED_HEADERS,
398
400
allow_extra=["X-My-App-Header"],
399
-
on_unexpected="warn", # "raise" (default), "drop", or "warn"
401
+
on_unexpected="warn", # "raise" (default), "drop", or "warn"
400
402
allow_x_prefixed=False,
401
403
logger=logger,
402
404
)
403
405
.deduplicate_headers(
404
-
action="raise", # "raise" (default), "first", "last", or "concat"
405
-
comma_join_ok=secure.COMMA_JOIN_OK,
406
-
multi_ok=secure.MULTI_OK,
406
+
action="raise", # "raise" (default), "first", "last", or "concat"
407
+
comma_join_ok=COMMA_JOIN_OK,
408
+
multi_ok=MULTI_OK,
407
409
logger=logger,
408
410
)
409
411
.validate_and_normalize_headers(
410
-
on_invalid="drop", # "drop" (default), "warn", or "raise"
412
+
on_invalid="drop", # "drop" (default), "warn", or "raise"
411
413
strict=False,
412
414
allow_obs_text=False,
413
415
logger=logger,
@@ -509,6 +511,27 @@ def read_root():
509
511
return {"Hello": "World"}
510
512
```
511
513
514
+
### Starlette
515
+
516
+
#### Recommended: `add_middleware` (ASGI)
517
+
518
+
```python
519
+
from secure import Secure
520
+
from secure.middleware import SecureASGIMiddleware
@@ -631,15 +654,19 @@ This project is licensed under the terms of the [MIT License](https://opensource
631
654
632
655
## Contributing
633
656
634
-
Issues and pull requests are welcome. If you would like to discuss an idea, open an issue on GitHub so we can talk about the design before implementation.
657
+
Issues and pull requests are welcome. If you’d like to discuss an idea, please open a GitHub issue so we can align on the design before implementation. See [CONTRIBUTING](https://github.com/TypeError/secure/blob/main/CONTRIBUTING.md) for details.
658
+
659
+
---
660
+
661
+
## Code of Conduct
635
662
636
-
Repository: <https://github.com/TypeError/secure>
663
+
See [CODE_OF_CONDUCT](https://github.com/TypeError/secure/blob/main/CODE_OF_CONDUCT.md) for our Code of Conduct.
637
664
638
665
---
639
666
640
667
## Changelog
641
668
642
-
See the [CHANGELOG](https://github.com/TypeError/secure/blob/main/CHANGELOG.md) for a detailed list of changes by release.
669
+
See [CHANGELOG](https://github.com/TypeError/secure/blob/main/CHANGELOG.md) for a detailed list of changes by release.
0 commit comments