swarmauri_middleware_securityheaders 0.8.0.dev47__tar.gz → 0.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swarmauri_middleware_securityheaders-0.11.0/NOTICE +7 -0
- swarmauri_middleware_securityheaders-0.11.0/PKG-INFO +394 -0
- swarmauri_middleware_securityheaders-0.11.0/README.md +366 -0
- {swarmauri_middleware_securityheaders-0.8.0.dev47 → swarmauri_middleware_securityheaders-0.11.0}/pyproject.toml +59 -9
- {swarmauri_middleware_securityheaders-0.8.0.dev47 → swarmauri_middleware_securityheaders-0.11.0}/swarmauri_middleware_securityheaders/SecurityHeadersMiddleware.py +3 -2
- swarmauri_middleware_securityheaders-0.8.0.dev47/PKG-INFO +0 -122
- swarmauri_middleware_securityheaders-0.8.0.dev47/README.md +0 -95
- {swarmauri_middleware_securityheaders-0.8.0.dev47 → swarmauri_middleware_securityheaders-0.11.0}/LICENSE +0 -0
- {swarmauri_middleware_securityheaders-0.8.0.dev47 → swarmauri_middleware_securityheaders-0.11.0}/swarmauri_middleware_securityheaders/__init__.py +0 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_middleware_securityheaders
|
|
3
|
+
Version: 0.11.0
|
|
4
|
+
Summary: Middleware for adding security headers to HTTP responses
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: NOTICE
|
|
8
|
+
Keywords: swarmauri,sdk,standards,middleware,securityheaders,security
|
|
9
|
+
Author: Jacob Stewart
|
|
10
|
+
Author-email: jacob@swarmauri.com
|
|
11
|
+
Requires-Python: >=3.10,<3.15
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Requires-Dist: starlette
|
|
23
|
+
Requires-Dist: swarmauri_base
|
|
24
|
+
Requires-Dist: swarmauri_core
|
|
25
|
+
Requires-Dist: swarmauri_standard
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# swarmauri_middleware_securityheaders
|
|
29
|
+
|
|
30
|
+
<!-- readme-standards:begin branding -->
|
|
31
|
+
<p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
|
|
32
|
+
<p align="center"><strong>swarmauri_middleware_securityheaders</strong></p>
|
|
33
|
+
<p align="center">Middleware for adding security headers to HTTP responses</p>
|
|
34
|
+
<p align="center">
|
|
35
|
+
<a href="https://pypi.org/project/swarmauri_middleware_securityheaders/"><img alt="pypi: swarmauri_middleware_securityheaders" src="https://img.shields.io/pypi/v/swarmauri_middleware_securityheaders?labelColor=1E293B&color=1D4ED8"></a>
|
|
36
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml"><img alt="Source version: 0.11.0" src="https://img.shields.io/static/v1?label=Source%20version&message=0.11.0&labelColor=1E293B&color=4338CA"></a>
|
|
37
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml"><img alt="Python: >=3.10,<3.15" src="https://img.shields.io/static/v1?label=Python&message=%3E%3D3.10%2C%3C3.15&labelColor=1E293B&color=0F766E"></a>
|
|
38
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml"><img alt="Layer: standards" src="https://img.shields.io/static/v1?label=Layer&message=standards&labelColor=1E293B&color=6D28D9"></a>
|
|
39
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&message=active&labelColor=1E293B&color=166534"></a>
|
|
40
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&message=Apache-2.0&labelColor=1E293B&color=86198F"></a>
|
|
41
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&message=attribution&labelColor=1E293B&color=86198F"></a>
|
|
42
|
+
</p>
|
|
43
|
+
<p align="center">
|
|
44
|
+
<a href="https://pypi.org/project/swarmauri_middleware_securityheaders/"><img alt="Monthly PyPI downloads: swarmauri_middleware_securityheaders" src="https://img.shields.io/pypi/dm/swarmauri_middleware_securityheaders?labelColor=1E293B&color=0E7490"></a>
|
|
45
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md"><img alt="README hits: swarmauri_middleware_securityheaders" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md.svg?label=README%20hits&labelColor=1E293B&color=0E7490"></a>
|
|
46
|
+
</p>
|
|
47
|
+
<p align="center">
|
|
48
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&message=CI%20gate&labelColor=1E293B&color=1D4ED8"></a>
|
|
49
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&message=example%20source&labelColor=1E293B&color=0F766E"></a>
|
|
50
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&message=not%20certified&labelColor=1E293B&color=92400E"></a>
|
|
51
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&message=repository%20policy&labelColor=1E293B&color=4338CA"></a>
|
|
52
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&message=source%20and%20CI&labelColor=1E293B&color=6D28D9"></a>
|
|
53
|
+
</p>
|
|
54
|
+
<p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
|
|
55
|
+
<!-- readme-standards:end branding -->
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Overview
|
|
60
|
+
|
|
61
|
+
### Summary
|
|
62
|
+
|
|
63
|
+
Middleware for adding security-focused HTTP headers to Starlette responses, helping shield applications from common web vulnerabilities.
|
|
64
|
+
|
|
65
|
+
`SecurityHeadersMiddleware` ensures every response produced by your Starlette
|
|
66
|
+
application carries the following headers and values:
|
|
67
|
+
|
|
68
|
+
- `Content-Security-Policy`: `default-src 'self'; script-src 'self'
|
|
69
|
+
https://cdn.example.com; style-src 'self' https://cdn.example.com; img-src
|
|
70
|
+
'self' https://images.example.com; font-src 'self'
|
|
71
|
+
https://fonts.example.com`
|
|
72
|
+
- `X-Content-Type-Options`: `nosniff`
|
|
73
|
+
- `X-Frame-Options`: `DENY`
|
|
74
|
+
- `X-XSS-Protection`: `1; mode=block`
|
|
75
|
+
- `Strict-Transport-Security`: `max-age=31536000; includeSubDomains; preload`
|
|
76
|
+
- `Referrer-Policy`: `same-origin`
|
|
77
|
+
- `Permissions-Policy`: `interest-cohort=(), geolocation=(self),
|
|
78
|
+
microphone=(), camera=(), magnetometer=(), gyroscope=(), speaker=(self),
|
|
79
|
+
vibrate=(), payment=()`
|
|
80
|
+
|
|
81
|
+
These defaults provide a strong baseline for many applications. Update the
|
|
82
|
+
middleware if you need to tailor the directives (for example, to change the
|
|
83
|
+
allowed host names in the Content Security Policy).
|
|
84
|
+
|
|
85
|
+
### Why This Package
|
|
86
|
+
|
|
87
|
+
`swarmauri_middleware_securityheaders` isolates this responsibility: Middleware for adding security headers to HTTP responses. Its [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py) exposes `SecurityHeadersMiddleware`, allowing consumers to select this package without treating adjacent packages as part of its public contract.
|
|
88
|
+
|
|
89
|
+
### When to Use
|
|
90
|
+
|
|
91
|
+
Choose `swarmauri_middleware_securityheaders` when your integration needs middleware for adding security headers to HTTP responses. Match the imports below to your application boundary and install its declared dependencies before using the example.
|
|
92
|
+
|
|
93
|
+
### Features
|
|
94
|
+
|
|
95
|
+
- `SecurityHeadersMiddleware`: Middleware that adds secure HTTP headers to responses.
|
|
96
|
+
|
|
97
|
+
### Non-Goals
|
|
98
|
+
|
|
99
|
+
`swarmauri_middleware_securityheaders` owns middleware for adding security headers to HTTP responses. Its imports do not by themselves configure credentials, deploy a service, or certify the behavior of its consumers. Dependencies and neighboring packages retain their own documented responsibilities.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Getting Started
|
|
104
|
+
|
|
105
|
+
### Prerequisites
|
|
106
|
+
|
|
107
|
+
Python `>=3.10,<3.15` is required. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) declares runtime dependencies including `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. Read the example’s inputs and service requirements before execution.
|
|
108
|
+
|
|
109
|
+
### Installation
|
|
110
|
+
|
|
111
|
+
#### uv
|
|
112
|
+
|
|
113
|
+
<!-- readme-standards:begin installation.uv -->
|
|
114
|
+
```bash
|
|
115
|
+
uv add swarmauri_middleware_securityheaders
|
|
116
|
+
```
|
|
117
|
+
<!-- readme-standards:end installation.uv -->
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
uv add swarmauri_middleware_securityheaders
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### pip
|
|
124
|
+
|
|
125
|
+
<!-- readme-standards:begin installation.pip -->
|
|
126
|
+
```bash
|
|
127
|
+
python -m pip install swarmauri_middleware_securityheaders
|
|
128
|
+
```
|
|
129
|
+
<!-- readme-standards:end installation.pip -->
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
pip install swarmauri-middleware-securityheaders
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### Poetry
|
|
136
|
+
|
|
137
|
+
<!-- readme-standards:begin installation.poetry -->
|
|
138
|
+
```bash
|
|
139
|
+
poetry add swarmauri_middleware_securityheaders
|
|
140
|
+
```
|
|
141
|
+
<!-- readme-standards:end installation.poetry -->
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
poetry add swarmauri_middleware_securityheaders
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Quick Start
|
|
148
|
+
|
|
149
|
+
#### Example
|
|
150
|
+
|
|
151
|
+
<!-- readme-standards:begin example.quick-start -->
|
|
152
|
+
Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/docs/readme/quick_start.py).
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from starlette.applications import Starlette
|
|
156
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
157
|
+
from starlette.requests import Request
|
|
158
|
+
from starlette.responses import JSONResponse
|
|
159
|
+
from swarmauri_middleware_securityheaders import SecurityHeadersMiddleware
|
|
160
|
+
|
|
161
|
+
app = Starlette()
|
|
162
|
+
security_middleware = SecurityHeadersMiddleware(app)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
async def apply_security_headers(request: Request, call_next):
|
|
166
|
+
return await security_middleware.dispatch(request, call_next)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
app.add_middleware(BaseHTTPMiddleware, dispatch=apply_security_headers)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
async def read_root(_request):
|
|
173
|
+
return JSONResponse({"status": "ok"})
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
app.add_route("/", read_root)
|
|
177
|
+
```
|
|
178
|
+
<!-- readme-standards:end example.quick-start -->
|
|
179
|
+
|
|
180
|
+
#### Expected Result
|
|
181
|
+
|
|
182
|
+
The example demonstrates the documented `swarmauri_middleware_securityheaders` source boundary or workflow. Complete its required configuration first. README CI checks the maintained source’s syntax and declarations; it does not claim that external services or the application workflow were exercised.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Usage
|
|
187
|
+
|
|
188
|
+
### Common Workflows
|
|
189
|
+
|
|
190
|
+
<!-- readme-standards:begin example.usage -->
|
|
191
|
+
Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/docs/readme/usage.py).
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from starlette.applications import Starlette
|
|
195
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
196
|
+
from starlette.requests import Request
|
|
197
|
+
from starlette.responses import JSONResponse
|
|
198
|
+
from swarmauri_middleware_securityheaders import SecurityHeadersMiddleware
|
|
199
|
+
|
|
200
|
+
app = Starlette()
|
|
201
|
+
security_middleware = SecurityHeadersMiddleware(app)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
async def apply_security_headers(request: Request, call_next):
|
|
205
|
+
return await security_middleware.dispatch(request, call_next)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
app.add_middleware(BaseHTTPMiddleware, dispatch=apply_security_headers)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
async def read_root(_request):
|
|
212
|
+
return JSONResponse({"status": "ok"})
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
app.add_route("/", read_root)
|
|
216
|
+
```
|
|
217
|
+
<!-- readme-standards:end example.usage -->
|
|
218
|
+
|
|
219
|
+
This pattern instantiates the middleware once and reuses its `dispatch` method
|
|
220
|
+
with Starlette’s `BaseHTTPMiddleware` so that every response includes
|
|
221
|
+
the security headers listed above.
|
|
222
|
+
|
|
223
|
+
### Configuration
|
|
224
|
+
|
|
225
|
+
Configure `swarmauri_middleware_securityheaders` through the APIs in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py); its [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) describes installation requirements, not an implicit service configuration. No additional package-global configuration contract is inferred from dependencies.
|
|
226
|
+
|
|
227
|
+
### Error Handling
|
|
228
|
+
|
|
229
|
+
The inspected `swarmauri_middleware_securityheaders` source does not establish a package-wide exception hierarchy. Preserve errors from its declared dependencies and validate inputs using the specific public contract in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py).
|
|
230
|
+
|
|
231
|
+
### Best Practices
|
|
232
|
+
|
|
233
|
+
Use the explicit `swarmauri_middleware_securityheaders` imports documented below and keep collaborator configuration with the caller. Run the package’s relevant tests after changing `SecurityHeadersMiddleware`; an import or successful installation alone does not establish its runtime guarantees.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Package Boundary
|
|
238
|
+
|
|
239
|
+
### What It Owns
|
|
240
|
+
|
|
241
|
+
`swarmauri_middleware_securityheaders` is located in `standards` and owns middleware for adding security headers to HTTP responses. Source-declared APIs include `SecurityHeadersMiddleware`. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) records its direct dependency boundary.
|
|
242
|
+
|
|
243
|
+
### Public API and Import Surfaces
|
|
244
|
+
|
|
245
|
+
Import namespace: `swarmauri_middleware_securityheaders`.
|
|
246
|
+
|
|
247
|
+
Source-declared exports or types: `SecurityHeadersMiddleware`.
|
|
248
|
+
|
|
249
|
+
Inspect [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py) for exact signatures; this inventory does not designate every internal module as stable.
|
|
250
|
+
|
|
251
|
+
### Entry Points
|
|
252
|
+
|
|
253
|
+
<!-- readme-standards:begin entry-points -->
|
|
254
|
+
- `swarmauri.middlewares` → `SecurityHeadersMiddleware` → `swarmauri_middleware_securityheaders:SecurityHeadersMiddleware`
|
|
255
|
+
<!-- readme-standards:end entry-points -->
|
|
256
|
+
|
|
257
|
+
### Injected Dependencies
|
|
258
|
+
|
|
259
|
+
The direct installation dependencies of `swarmauri_middleware_securityheaders` are `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. These declarations do not imply automatic provider selection. Pass collaborators through the explicit constructors or call signatures in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py).
|
|
260
|
+
|
|
261
|
+
### Protocol Consumers
|
|
262
|
+
|
|
263
|
+
No direct package-manifest dependency on `swarmauri_middleware_securityheaders` was found in the audited three-repository inventory. External consumers may still use its documented imports or commands.
|
|
264
|
+
|
|
265
|
+
### Extensions
|
|
266
|
+
|
|
267
|
+
For `swarmauri_middleware_securityheaders`, use the source-declared public interfaces (`SecurityHeadersMiddleware`) when composing or extending behavior. Its entry-point section below is authoritative for registered plugins; no additional extension loader is inferred from the package name.
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Operations and Readiness
|
|
272
|
+
|
|
273
|
+
### Operational Requirements
|
|
274
|
+
|
|
275
|
+
Operate `swarmauri_middleware_securityheaders` according to its actual entry points and collaborators. The dependency and Python requirements in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) are prerequisites; deployment topology, credentials, and readiness remain the responsibility of the consuming application unless explicitly documented above.
|
|
276
|
+
|
|
277
|
+
### Health and Observability
|
|
278
|
+
|
|
279
|
+
This README does not establish a standalone health endpoint for `swarmauri_middleware_securityheaders`. Observe the concrete caller’s results, exceptions, and existing test reports. An application that embeds this package must define its own health and telemetry contract.
|
|
280
|
+
|
|
281
|
+
### Security and Resource Limits
|
|
282
|
+
|
|
283
|
+
Apply the input, credential, and resource constraints implemented in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py). The `swarmauri_middleware_securityheaders` README gate is a documentation check, not a security review or a substitute for the implementation’s limits and caller authorization.
|
|
284
|
+
|
|
285
|
+
### Compatibility
|
|
286
|
+
|
|
287
|
+
This source version of `swarmauri_middleware_securityheaders` declares Python `>=3.10,<3.15`. Consult its dependency constraints before upgrading. Source-version and registry-version badges have separate meanings; this migration makes no additional platform or interoperability certification claim.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Verification
|
|
292
|
+
|
|
293
|
+
### Tests
|
|
294
|
+
|
|
295
|
+
Run `python -m pytest tests/unit/test_readme_sources.py` from the `swarmauri_middleware_securityheaders` package directory for the maintained example source checks (Python compilation and non-Python file presence). Existing package tests include:
|
|
296
|
+
|
|
297
|
+
- [tests/test_readme_example.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/test_readme_example.py)
|
|
298
|
+
- [tests/i9n/test_i9n__init__.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/i9n/test_i9n__init__.py)
|
|
299
|
+
- [tests/unit/test_SecurityHeadersMiddleware.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/unit/test_SecurityHeadersMiddleware.py)
|
|
300
|
+
|
|
301
|
+
The repository README gate also checks the required heading tree, metadata, managed fragments, and referenced files.
|
|
302
|
+
|
|
303
|
+
### Certification Status
|
|
304
|
+
|
|
305
|
+
No external certification is asserted for `swarmauri_middleware_securityheaders` by this documentation migration. README conformance, example syntax, runtime tests, and protocol or security certification are distinct evidence scopes.
|
|
306
|
+
|
|
307
|
+
### Evidence
|
|
308
|
+
|
|
309
|
+
The [README standards CI](https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml) records mechanical documentation results for its tested commit. The [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py) and example sources support the package-boundary description; external runtime behavior requires its own test evidence.
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## FAQ
|
|
314
|
+
|
|
315
|
+
### Why
|
|
316
|
+
|
|
317
|
+
**Why select this package?** `swarmauri_middleware_securityheaders` provides middleware for adding security headers to HTTP responses; use its own API boundary rather than assuming neighboring packages are bundled or configured automatically.
|
|
318
|
+
|
|
319
|
+
### How
|
|
320
|
+
|
|
321
|
+
**How do I start?** Install or synchronize the environment under Getting Started, follow the maintained example for `swarmauri_middleware_securityheaders`, and consult [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py) for the exact types and signatures involved.
|
|
322
|
+
|
|
323
|
+
### When
|
|
324
|
+
|
|
325
|
+
**When should I validate an upgrade?** Recheck `swarmauri_middleware_securityheaders` whenever its source version, declared collaborators, configuration, or caller changes. Run relevant behavioral tests in addition to the README gate before promotion.
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## Documentation and Related Packages
|
|
330
|
+
|
|
331
|
+
### More Documentation
|
|
332
|
+
|
|
333
|
+
The [repository contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md), [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py), and [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) provide the supporting context for `swarmauri_middleware_securityheaders`. The [README policy](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md) defines the common document structure.
|
|
334
|
+
|
|
335
|
+
### Related Packages
|
|
336
|
+
|
|
337
|
+
- [swarmauri_base](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/20-bases/swarmauri_base/README.md): Reusable Swarmauri base classes, mixins, and dynamic Pydantic component models for composable intelligence infrastructure.
|
|
338
|
+
- [swarmauri_core](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/10-interfaces/swarmauri_core/README.md): Core interface contracts and shared types for Swarmauri composable intelligence infrastructure components.
|
|
339
|
+
- [swarmauri_standard](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/30-standard-kernel/swarmauri_standard/README.md): First-party Swarmauri standard components for agents, tools, parsers, vectors, model adapters, and composable intelligence workflows.
|
|
340
|
+
|
|
341
|
+
### Project Links
|
|
342
|
+
|
|
343
|
+
<!-- readme-standards:begin project-links -->
|
|
344
|
+
- [pypi: swarmauri_middleware_securityheaders](https://pypi.org/project/swarmauri_middleware_securityheaders/)
|
|
345
|
+
<!-- readme-standards:end project-links -->
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## Contributing
|
|
350
|
+
|
|
351
|
+
### How to Contribute
|
|
352
|
+
|
|
353
|
+
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md) that will help you get started.
|
|
354
|
+
|
|
355
|
+
### Development Setup
|
|
356
|
+
|
|
357
|
+
Work from the `pkgs/40-standards/swarmauri_middleware_securityheaders` checkout. Synchronize its declared development environment with uv, then run the relevant package tests and `python -m pytest tests/unit/test_readme_sources.py`. The repository’s dedicated README job installs `readme-standards==0.1.3` without resolving unrelated runtime packages.
|
|
358
|
+
|
|
359
|
+
### Notes for Maintainers
|
|
360
|
+
|
|
361
|
+
Edit authored prose directly in this `swarmauri_middleware_securityheaders` README. Update source examples in `docs/readme/`, then run `readme-standards render --root . --write` from the package directory and review the diff. Required headings and generated blocks come from package-guide-v1.
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## Governance
|
|
366
|
+
|
|
367
|
+
### Ownership and Decision Making
|
|
368
|
+
|
|
369
|
+
Changes to `swarmauri_middleware_securityheaders` follow the maintainer review process of [swarmauri/swarmauri-sdk](https://github.com/swarmauri/swarmauri-sdk) and its contribution guide. Author attribution remains in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml); this README does not assign new publishing or administrative authority.
|
|
370
|
+
|
|
371
|
+
### Standards and Policies
|
|
372
|
+
|
|
373
|
+
`swarmauri_middleware_securityheaders` follows the versioned [package-guide-v1 outline](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md). All fixed headings, hierarchy, order, separators, and package-specific branding are checked by CI; reviewers assess the accuracy and usefulness of authored claims.
|
|
374
|
+
|
|
375
|
+
### Lifecycle and Migration
|
|
376
|
+
|
|
377
|
+
The `swarmauri_middleware_securityheaders` source version is `0.11.0`.
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## License and Attribution
|
|
382
|
+
|
|
383
|
+
### License
|
|
384
|
+
|
|
385
|
+
<!-- readme-standards:begin license -->
|
|
386
|
+
Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/LICENSE).
|
|
387
|
+
<!-- readme-standards:end license -->
|
|
388
|
+
|
|
389
|
+
### Notices
|
|
390
|
+
|
|
391
|
+
<!-- readme-standards:begin notices -->
|
|
392
|
+
See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/NOTICE) for attribution.
|
|
393
|
+
<!-- readme-standards:end notices -->
|
|
394
|
+
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# swarmauri_middleware_securityheaders
|
|
2
|
+
|
|
3
|
+
<!-- readme-standards:begin branding -->
|
|
4
|
+
<p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
|
|
5
|
+
<p align="center"><strong>swarmauri_middleware_securityheaders</strong></p>
|
|
6
|
+
<p align="center">Middleware for adding security headers to HTTP responses</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_middleware_securityheaders/"><img alt="pypi: swarmauri_middleware_securityheaders" src="https://img.shields.io/pypi/v/swarmauri_middleware_securityheaders?labelColor=1E293B&color=1D4ED8"></a>
|
|
9
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml"><img alt="Source version: 0.11.0" src="https://img.shields.io/static/v1?label=Source%20version&message=0.11.0&labelColor=1E293B&color=4338CA"></a>
|
|
10
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml"><img alt="Python: >=3.10,<3.15" src="https://img.shields.io/static/v1?label=Python&message=%3E%3D3.10%2C%3C3.15&labelColor=1E293B&color=0F766E"></a>
|
|
11
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml"><img alt="Layer: standards" src="https://img.shields.io/static/v1?label=Layer&message=standards&labelColor=1E293B&color=6D28D9"></a>
|
|
12
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&message=active&labelColor=1E293B&color=166534"></a>
|
|
13
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&message=Apache-2.0&labelColor=1E293B&color=86198F"></a>
|
|
14
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&message=attribution&labelColor=1E293B&color=86198F"></a>
|
|
15
|
+
</p>
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://pypi.org/project/swarmauri_middleware_securityheaders/"><img alt="Monthly PyPI downloads: swarmauri_middleware_securityheaders" src="https://img.shields.io/pypi/dm/swarmauri_middleware_securityheaders?labelColor=1E293B&color=0E7490"></a>
|
|
18
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md"><img alt="README hits: swarmauri_middleware_securityheaders" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md.svg?label=README%20hits&labelColor=1E293B&color=0E7490"></a>
|
|
19
|
+
</p>
|
|
20
|
+
<p align="center">
|
|
21
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&message=CI%20gate&labelColor=1E293B&color=1D4ED8"></a>
|
|
22
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&message=example%20source&labelColor=1E293B&color=0F766E"></a>
|
|
23
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&message=not%20certified&labelColor=1E293B&color=92400E"></a>
|
|
24
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&message=repository%20policy&labelColor=1E293B&color=4338CA"></a>
|
|
25
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&message=source%20and%20CI&labelColor=1E293B&color=6D28D9"></a>
|
|
26
|
+
</p>
|
|
27
|
+
<p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
|
|
28
|
+
<!-- readme-standards:end branding -->
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Overview
|
|
33
|
+
|
|
34
|
+
### Summary
|
|
35
|
+
|
|
36
|
+
Middleware for adding security-focused HTTP headers to Starlette responses, helping shield applications from common web vulnerabilities.
|
|
37
|
+
|
|
38
|
+
`SecurityHeadersMiddleware` ensures every response produced by your Starlette
|
|
39
|
+
application carries the following headers and values:
|
|
40
|
+
|
|
41
|
+
- `Content-Security-Policy`: `default-src 'self'; script-src 'self'
|
|
42
|
+
https://cdn.example.com; style-src 'self' https://cdn.example.com; img-src
|
|
43
|
+
'self' https://images.example.com; font-src 'self'
|
|
44
|
+
https://fonts.example.com`
|
|
45
|
+
- `X-Content-Type-Options`: `nosniff`
|
|
46
|
+
- `X-Frame-Options`: `DENY`
|
|
47
|
+
- `X-XSS-Protection`: `1; mode=block`
|
|
48
|
+
- `Strict-Transport-Security`: `max-age=31536000; includeSubDomains; preload`
|
|
49
|
+
- `Referrer-Policy`: `same-origin`
|
|
50
|
+
- `Permissions-Policy`: `interest-cohort=(), geolocation=(self),
|
|
51
|
+
microphone=(), camera=(), magnetometer=(), gyroscope=(), speaker=(self),
|
|
52
|
+
vibrate=(), payment=()`
|
|
53
|
+
|
|
54
|
+
These defaults provide a strong baseline for many applications. Update the
|
|
55
|
+
middleware if you need to tailor the directives (for example, to change the
|
|
56
|
+
allowed host names in the Content Security Policy).
|
|
57
|
+
|
|
58
|
+
### Why This Package
|
|
59
|
+
|
|
60
|
+
`swarmauri_middleware_securityheaders` isolates this responsibility: Middleware for adding security headers to HTTP responses. Its [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py) exposes `SecurityHeadersMiddleware`, allowing consumers to select this package without treating adjacent packages as part of its public contract.
|
|
61
|
+
|
|
62
|
+
### When to Use
|
|
63
|
+
|
|
64
|
+
Choose `swarmauri_middleware_securityheaders` when your integration needs middleware for adding security headers to HTTP responses. Match the imports below to your application boundary and install its declared dependencies before using the example.
|
|
65
|
+
|
|
66
|
+
### Features
|
|
67
|
+
|
|
68
|
+
- `SecurityHeadersMiddleware`: Middleware that adds secure HTTP headers to responses.
|
|
69
|
+
|
|
70
|
+
### Non-Goals
|
|
71
|
+
|
|
72
|
+
`swarmauri_middleware_securityheaders` owns middleware for adding security headers to HTTP responses. Its imports do not by themselves configure credentials, deploy a service, or certify the behavior of its consumers. Dependencies and neighboring packages retain their own documented responsibilities.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Getting Started
|
|
77
|
+
|
|
78
|
+
### Prerequisites
|
|
79
|
+
|
|
80
|
+
Python `>=3.10,<3.15` is required. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) declares runtime dependencies including `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. Read the example’s inputs and service requirements before execution.
|
|
81
|
+
|
|
82
|
+
### Installation
|
|
83
|
+
|
|
84
|
+
#### uv
|
|
85
|
+
|
|
86
|
+
<!-- readme-standards:begin installation.uv -->
|
|
87
|
+
```bash
|
|
88
|
+
uv add swarmauri_middleware_securityheaders
|
|
89
|
+
```
|
|
90
|
+
<!-- readme-standards:end installation.uv -->
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
uv add swarmauri_middleware_securityheaders
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### pip
|
|
97
|
+
|
|
98
|
+
<!-- readme-standards:begin installation.pip -->
|
|
99
|
+
```bash
|
|
100
|
+
python -m pip install swarmauri_middleware_securityheaders
|
|
101
|
+
```
|
|
102
|
+
<!-- readme-standards:end installation.pip -->
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pip install swarmauri-middleware-securityheaders
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Poetry
|
|
109
|
+
|
|
110
|
+
<!-- readme-standards:begin installation.poetry -->
|
|
111
|
+
```bash
|
|
112
|
+
poetry add swarmauri_middleware_securityheaders
|
|
113
|
+
```
|
|
114
|
+
<!-- readme-standards:end installation.poetry -->
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
poetry add swarmauri_middleware_securityheaders
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Quick Start
|
|
121
|
+
|
|
122
|
+
#### Example
|
|
123
|
+
|
|
124
|
+
<!-- readme-standards:begin example.quick-start -->
|
|
125
|
+
Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/docs/readme/quick_start.py).
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from starlette.applications import Starlette
|
|
129
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
130
|
+
from starlette.requests import Request
|
|
131
|
+
from starlette.responses import JSONResponse
|
|
132
|
+
from swarmauri_middleware_securityheaders import SecurityHeadersMiddleware
|
|
133
|
+
|
|
134
|
+
app = Starlette()
|
|
135
|
+
security_middleware = SecurityHeadersMiddleware(app)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
async def apply_security_headers(request: Request, call_next):
|
|
139
|
+
return await security_middleware.dispatch(request, call_next)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
app.add_middleware(BaseHTTPMiddleware, dispatch=apply_security_headers)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
async def read_root(_request):
|
|
146
|
+
return JSONResponse({"status": "ok"})
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
app.add_route("/", read_root)
|
|
150
|
+
```
|
|
151
|
+
<!-- readme-standards:end example.quick-start -->
|
|
152
|
+
|
|
153
|
+
#### Expected Result
|
|
154
|
+
|
|
155
|
+
The example demonstrates the documented `swarmauri_middleware_securityheaders` source boundary or workflow. Complete its required configuration first. README CI checks the maintained source’s syntax and declarations; it does not claim that external services or the application workflow were exercised.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Usage
|
|
160
|
+
|
|
161
|
+
### Common Workflows
|
|
162
|
+
|
|
163
|
+
<!-- readme-standards:begin example.usage -->
|
|
164
|
+
Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/docs/readme/usage.py).
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from starlette.applications import Starlette
|
|
168
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
169
|
+
from starlette.requests import Request
|
|
170
|
+
from starlette.responses import JSONResponse
|
|
171
|
+
from swarmauri_middleware_securityheaders import SecurityHeadersMiddleware
|
|
172
|
+
|
|
173
|
+
app = Starlette()
|
|
174
|
+
security_middleware = SecurityHeadersMiddleware(app)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
async def apply_security_headers(request: Request, call_next):
|
|
178
|
+
return await security_middleware.dispatch(request, call_next)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
app.add_middleware(BaseHTTPMiddleware, dispatch=apply_security_headers)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
async def read_root(_request):
|
|
185
|
+
return JSONResponse({"status": "ok"})
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
app.add_route("/", read_root)
|
|
189
|
+
```
|
|
190
|
+
<!-- readme-standards:end example.usage -->
|
|
191
|
+
|
|
192
|
+
This pattern instantiates the middleware once and reuses its `dispatch` method
|
|
193
|
+
with Starlette’s `BaseHTTPMiddleware` so that every response includes
|
|
194
|
+
the security headers listed above.
|
|
195
|
+
|
|
196
|
+
### Configuration
|
|
197
|
+
|
|
198
|
+
Configure `swarmauri_middleware_securityheaders` through the APIs in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py); its [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) describes installation requirements, not an implicit service configuration. No additional package-global configuration contract is inferred from dependencies.
|
|
199
|
+
|
|
200
|
+
### Error Handling
|
|
201
|
+
|
|
202
|
+
The inspected `swarmauri_middleware_securityheaders` source does not establish a package-wide exception hierarchy. Preserve errors from its declared dependencies and validate inputs using the specific public contract in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py).
|
|
203
|
+
|
|
204
|
+
### Best Practices
|
|
205
|
+
|
|
206
|
+
Use the explicit `swarmauri_middleware_securityheaders` imports documented below and keep collaborator configuration with the caller. Run the package’s relevant tests after changing `SecurityHeadersMiddleware`; an import or successful installation alone does not establish its runtime guarantees.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Package Boundary
|
|
211
|
+
|
|
212
|
+
### What It Owns
|
|
213
|
+
|
|
214
|
+
`swarmauri_middleware_securityheaders` is located in `standards` and owns middleware for adding security headers to HTTP responses. Source-declared APIs include `SecurityHeadersMiddleware`. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) records its direct dependency boundary.
|
|
215
|
+
|
|
216
|
+
### Public API and Import Surfaces
|
|
217
|
+
|
|
218
|
+
Import namespace: `swarmauri_middleware_securityheaders`.
|
|
219
|
+
|
|
220
|
+
Source-declared exports or types: `SecurityHeadersMiddleware`.
|
|
221
|
+
|
|
222
|
+
Inspect [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py) for exact signatures; this inventory does not designate every internal module as stable.
|
|
223
|
+
|
|
224
|
+
### Entry Points
|
|
225
|
+
|
|
226
|
+
<!-- readme-standards:begin entry-points -->
|
|
227
|
+
- `swarmauri.middlewares` → `SecurityHeadersMiddleware` → `swarmauri_middleware_securityheaders:SecurityHeadersMiddleware`
|
|
228
|
+
<!-- readme-standards:end entry-points -->
|
|
229
|
+
|
|
230
|
+
### Injected Dependencies
|
|
231
|
+
|
|
232
|
+
The direct installation dependencies of `swarmauri_middleware_securityheaders` are `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. These declarations do not imply automatic provider selection. Pass collaborators through the explicit constructors or call signatures in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py).
|
|
233
|
+
|
|
234
|
+
### Protocol Consumers
|
|
235
|
+
|
|
236
|
+
No direct package-manifest dependency on `swarmauri_middleware_securityheaders` was found in the audited three-repository inventory. External consumers may still use its documented imports or commands.
|
|
237
|
+
|
|
238
|
+
### Extensions
|
|
239
|
+
|
|
240
|
+
For `swarmauri_middleware_securityheaders`, use the source-declared public interfaces (`SecurityHeadersMiddleware`) when composing or extending behavior. Its entry-point section below is authoritative for registered plugins; no additional extension loader is inferred from the package name.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Operations and Readiness
|
|
245
|
+
|
|
246
|
+
### Operational Requirements
|
|
247
|
+
|
|
248
|
+
Operate `swarmauri_middleware_securityheaders` according to its actual entry points and collaborators. The dependency and Python requirements in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) are prerequisites; deployment topology, credentials, and readiness remain the responsibility of the consuming application unless explicitly documented above.
|
|
249
|
+
|
|
250
|
+
### Health and Observability
|
|
251
|
+
|
|
252
|
+
This README does not establish a standalone health endpoint for `swarmauri_middleware_securityheaders`. Observe the concrete caller’s results, exceptions, and existing test reports. An application that embeds this package must define its own health and telemetry contract.
|
|
253
|
+
|
|
254
|
+
### Security and Resource Limits
|
|
255
|
+
|
|
256
|
+
Apply the input, credential, and resource constraints implemented in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py). The `swarmauri_middleware_securityheaders` README gate is a documentation check, not a security review or a substitute for the implementation’s limits and caller authorization.
|
|
257
|
+
|
|
258
|
+
### Compatibility
|
|
259
|
+
|
|
260
|
+
This source version of `swarmauri_middleware_securityheaders` declares Python `>=3.10,<3.15`. Consult its dependency constraints before upgrading. Source-version and registry-version badges have separate meanings; this migration makes no additional platform or interoperability certification claim.
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Verification
|
|
265
|
+
|
|
266
|
+
### Tests
|
|
267
|
+
|
|
268
|
+
Run `python -m pytest tests/unit/test_readme_sources.py` from the `swarmauri_middleware_securityheaders` package directory for the maintained example source checks (Python compilation and non-Python file presence). Existing package tests include:
|
|
269
|
+
|
|
270
|
+
- [tests/test_readme_example.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/test_readme_example.py)
|
|
271
|
+
- [tests/i9n/test_i9n__init__.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/i9n/test_i9n__init__.py)
|
|
272
|
+
- [tests/unit/test_SecurityHeadersMiddleware.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/unit/test_SecurityHeadersMiddleware.py)
|
|
273
|
+
|
|
274
|
+
The repository README gate also checks the required heading tree, metadata, managed fragments, and referenced files.
|
|
275
|
+
|
|
276
|
+
### Certification Status
|
|
277
|
+
|
|
278
|
+
No external certification is asserted for `swarmauri_middleware_securityheaders` by this documentation migration. README conformance, example syntax, runtime tests, and protocol or security certification are distinct evidence scopes.
|
|
279
|
+
|
|
280
|
+
### Evidence
|
|
281
|
+
|
|
282
|
+
The [README standards CI](https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml) records mechanical documentation results for its tested commit. The [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py) and example sources support the package-boundary description; external runtime behavior requires its own test evidence.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## FAQ
|
|
287
|
+
|
|
288
|
+
### Why
|
|
289
|
+
|
|
290
|
+
**Why select this package?** `swarmauri_middleware_securityheaders` provides middleware for adding security headers to HTTP responses; use its own API boundary rather than assuming neighboring packages are bundled or configured automatically.
|
|
291
|
+
|
|
292
|
+
### How
|
|
293
|
+
|
|
294
|
+
**How do I start?** Install or synchronize the environment under Getting Started, follow the maintained example for `swarmauri_middleware_securityheaders`, and consult [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py) for the exact types and signatures involved.
|
|
295
|
+
|
|
296
|
+
### When
|
|
297
|
+
|
|
298
|
+
**When should I validate an upgrade?** Recheck `swarmauri_middleware_securityheaders` whenever its source version, declared collaborators, configuration, or caller changes. Run relevant behavioral tests in addition to the README gate before promotion.
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Documentation and Related Packages
|
|
303
|
+
|
|
304
|
+
### More Documentation
|
|
305
|
+
|
|
306
|
+
The [repository contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md), [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/swarmauri_middleware_securityheaders/__init__.py), and [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml) provide the supporting context for `swarmauri_middleware_securityheaders`. The [README policy](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md) defines the common document structure.
|
|
307
|
+
|
|
308
|
+
### Related Packages
|
|
309
|
+
|
|
310
|
+
- [swarmauri_base](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/20-bases/swarmauri_base/README.md): Reusable Swarmauri base classes, mixins, and dynamic Pydantic component models for composable intelligence infrastructure.
|
|
311
|
+
- [swarmauri_core](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/10-interfaces/swarmauri_core/README.md): Core interface contracts and shared types for Swarmauri composable intelligence infrastructure components.
|
|
312
|
+
- [swarmauri_standard](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/30-standard-kernel/swarmauri_standard/README.md): First-party Swarmauri standard components for agents, tools, parsers, vectors, model adapters, and composable intelligence workflows.
|
|
313
|
+
|
|
314
|
+
### Project Links
|
|
315
|
+
|
|
316
|
+
<!-- readme-standards:begin project-links -->
|
|
317
|
+
- [pypi: swarmauri_middleware_securityheaders](https://pypi.org/project/swarmauri_middleware_securityheaders/)
|
|
318
|
+
<!-- readme-standards:end project-links -->
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Contributing
|
|
323
|
+
|
|
324
|
+
### How to Contribute
|
|
325
|
+
|
|
326
|
+
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md) that will help you get started.
|
|
327
|
+
|
|
328
|
+
### Development Setup
|
|
329
|
+
|
|
330
|
+
Work from the `pkgs/40-standards/swarmauri_middleware_securityheaders` checkout. Synchronize its declared development environment with uv, then run the relevant package tests and `python -m pytest tests/unit/test_readme_sources.py`. The repository’s dedicated README job installs `readme-standards==0.1.3` without resolving unrelated runtime packages.
|
|
331
|
+
|
|
332
|
+
### Notes for Maintainers
|
|
333
|
+
|
|
334
|
+
Edit authored prose directly in this `swarmauri_middleware_securityheaders` README. Update source examples in `docs/readme/`, then run `readme-standards render --root . --write` from the package directory and review the diff. Required headings and generated blocks come from package-guide-v1.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## Governance
|
|
339
|
+
|
|
340
|
+
### Ownership and Decision Making
|
|
341
|
+
|
|
342
|
+
Changes to `swarmauri_middleware_securityheaders` follow the maintainer review process of [swarmauri/swarmauri-sdk](https://github.com/swarmauri/swarmauri-sdk) and its contribution guide. Author attribution remains in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/pyproject.toml); this README does not assign new publishing or administrative authority.
|
|
343
|
+
|
|
344
|
+
### Standards and Policies
|
|
345
|
+
|
|
346
|
+
`swarmauri_middleware_securityheaders` follows the versioned [package-guide-v1 outline](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md). All fixed headings, hierarchy, order, separators, and package-specific branding are checked by CI; reviewers assess the accuracy and usefulness of authored claims.
|
|
347
|
+
|
|
348
|
+
### Lifecycle and Migration
|
|
349
|
+
|
|
350
|
+
The `swarmauri_middleware_securityheaders` source version is `0.11.0`.
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## License and Attribution
|
|
355
|
+
|
|
356
|
+
### License
|
|
357
|
+
|
|
358
|
+
<!-- readme-standards:begin license -->
|
|
359
|
+
Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/LICENSE).
|
|
360
|
+
<!-- readme-standards:end license -->
|
|
361
|
+
|
|
362
|
+
### Notices
|
|
363
|
+
|
|
364
|
+
<!-- readme-standards:begin notices -->
|
|
365
|
+
See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/NOTICE) for attribution.
|
|
366
|
+
<!-- readme-standards:end notices -->
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_middleware_securityheaders"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.11.0"
|
|
4
4
|
description = "Middleware for adding security headers to HTTP responses"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
repository = "http://github.com/swarmauri/swarmauri-sdk/pkgs/pkgs/swarmauri_middleware_securityheaders/"
|
|
8
|
-
requires-python = ">=3.10,<3.
|
|
8
|
+
requires-python = ">=3.10,<3.15"
|
|
9
9
|
classifiers = [
|
|
10
|
-
"License :: OSI Approved :: Apache Software License",
|
|
11
10
|
"Natural Language :: English",
|
|
12
|
-
"Programming Language :: Python :: 3.10",
|
|
13
|
-
"Programming Language :: Python :: 3.11",
|
|
14
|
-
"Programming Language :: Python :: 3.12",
|
|
15
|
-
"Programming Language :: Python :: 3.13",
|
|
16
11
|
"Development Status :: 3 - Alpha",
|
|
17
12
|
"Programming Language :: Python",
|
|
18
13
|
"Programming Language :: Python :: 3",
|
|
19
14
|
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
20
|
]
|
|
21
21
|
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
22
22
|
dependencies = [
|
|
23
|
-
"
|
|
23
|
+
"starlette",
|
|
24
24
|
"swarmauri_core",
|
|
25
25
|
"swarmauri_base",
|
|
26
26
|
"swarmauri_standard",
|
|
@@ -33,6 +33,7 @@ keywords = [
|
|
|
33
33
|
'securityheaders',
|
|
34
34
|
'security',
|
|
35
35
|
]
|
|
36
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
36
37
|
|
|
37
38
|
[tool.uv.sources]
|
|
38
39
|
swarmauri_core = { workspace = true }
|
|
@@ -60,6 +61,54 @@ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
|
|
|
60
61
|
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
|
61
62
|
asyncio_default_fixture_loop_scope = "function"
|
|
62
63
|
|
|
64
|
+
[tool.readme_standards]
|
|
65
|
+
policy = "package-guide-v1"
|
|
66
|
+
readme = "README.md"
|
|
67
|
+
brand = "swarmauri"
|
|
68
|
+
brand_catalog = "../../../tools/readme/brands.toml"
|
|
69
|
+
repository = "https://github.com/swarmauri/swarmauri-sdk"
|
|
70
|
+
ref = "master"
|
|
71
|
+
package_path = "pkgs/40-standards/swarmauri_middleware_securityheaders"
|
|
72
|
+
layer = "standards"
|
|
73
|
+
lifecycle = "active"
|
|
74
|
+
license_file = "LICENSE"
|
|
75
|
+
notice_file = "NOTICE"
|
|
76
|
+
|
|
77
|
+
[tool.readme_standards.distributions.pypi]
|
|
78
|
+
name = "swarmauri_middleware_securityheaders"
|
|
79
|
+
published = true
|
|
80
|
+
|
|
81
|
+
[tool.readme_standards.examples.quick_start]
|
|
82
|
+
source = "docs/readme/quick_start.py"
|
|
83
|
+
test = "tests/unit/test_readme_sources.py"
|
|
84
|
+
language = "python"
|
|
85
|
+
expected_exit_code = 0
|
|
86
|
+
|
|
87
|
+
[tool.readme_standards.examples.usage]
|
|
88
|
+
source = "docs/readme/usage.py"
|
|
89
|
+
test = "tests/unit/test_readme_sources.py"
|
|
90
|
+
language = "python"
|
|
91
|
+
expected_exit_code = 0
|
|
92
|
+
|
|
93
|
+
[tool.readme_standards.statuses.readme]
|
|
94
|
+
label = "CI gate"
|
|
95
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
|
|
96
|
+
|
|
97
|
+
[tool.readme_standards.statuses.tests]
|
|
98
|
+
label = "example source"
|
|
99
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/tests/unit/test_readme_sources.py"
|
|
100
|
+
|
|
101
|
+
[tool.readme_standards.statuses.certification]
|
|
102
|
+
label = "not certified"
|
|
103
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_securityheaders/README.md#certification-status"
|
|
104
|
+
|
|
105
|
+
[tool.readme_standards.statuses.governance]
|
|
106
|
+
label = "repository policy"
|
|
107
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"
|
|
108
|
+
|
|
109
|
+
[tool.readme_standards.statuses.evidence]
|
|
110
|
+
label = "source and CI"
|
|
111
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
|
|
63
112
|
[build-system]
|
|
64
113
|
requires = ["poetry-core>=1.0.0"]
|
|
65
114
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -72,11 +121,12 @@ dev = [
|
|
|
72
121
|
"pytest-xdist>=3.6.1",
|
|
73
122
|
"pytest-json-report>=1.5.0",
|
|
74
123
|
"python-dotenv",
|
|
75
|
-
"
|
|
124
|
+
"httpx>=0.27",
|
|
76
125
|
"flake8>=7.0",
|
|
77
126
|
"pytest-timeout>=2.3.1",
|
|
78
127
|
"ruff>=0.9.9",
|
|
79
128
|
"pytest-benchmark>=4.0.0",
|
|
129
|
+
"readme-standards==0.1.3; python_version >= \"3.11\"",
|
|
80
130
|
]
|
|
81
131
|
|
|
82
132
|
[project.entry-points.'swarmauri.middlewares']
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
from typing import Callable
|
|
3
3
|
|
|
4
|
-
from
|
|
5
|
-
from
|
|
4
|
+
from starlette.requests import Request
|
|
5
|
+
from starlette.responses import Response
|
|
6
|
+
from starlette.middleware import Middleware
|
|
6
7
|
|
|
7
8
|
logger = logging.getLogger(__name__)
|
|
8
9
|
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: swarmauri_middleware_securityheaders
|
|
3
|
-
Version: 0.8.0.dev47
|
|
4
|
-
Summary: Middleware for adding security headers to HTTP responses
|
|
5
|
-
License-Expression: Apache-2.0
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Keywords: swarmauri,sdk,standards,middleware,securityheaders,security
|
|
8
|
-
Author: Jacob Stewart
|
|
9
|
-
Author-email: jacob@swarmauri.com
|
|
10
|
-
Requires-Python: >=3.10,<3.13
|
|
11
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
-
Classifier: Natural Language :: English
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
-
Classifier: Development Status :: 3 - Alpha
|
|
18
|
-
Classifier: Programming Language :: Python
|
|
19
|
-
Classifier: Programming Language :: Python :: 3
|
|
20
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
-
Requires-Dist: fastapi
|
|
22
|
-
Requires-Dist: swarmauri_base
|
|
23
|
-
Requires-Dist: swarmauri_core
|
|
24
|
-
Requires-Dist: swarmauri_standard
|
|
25
|
-
Description-Content-Type: text/markdown
|
|
26
|
-
|
|
27
|
-

|
|
28
|
-
|
|
29
|
-
<p align="center">
|
|
30
|
-
<a href="https://pypi.org/project/swarmauri-middleware-securityheaders/">
|
|
31
|
-
<img src="https://img.shields.io/pypi/dm/swarmauri-middleware-securityheaders" alt="PyPI - Downloads"/>
|
|
32
|
-
</a>
|
|
33
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_securityheaders/">
|
|
34
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_securityheaders.svg"/>
|
|
35
|
-
</a>
|
|
36
|
-
<a href="https://pypi.org/project/swarmauri-middleware-securityheaders/">
|
|
37
|
-
<img src="https://img.shields.io/pypi/pyversions/swarmauri-middleware-securityheaders" alt="PyPI - Python Version"/>
|
|
38
|
-
</a>
|
|
39
|
-
<a href="https://pypi.org/project/swarmauri-middleware-securityheaders/">
|
|
40
|
-
<img src="https://img.shields.io/pypi/l/swarmauri-middleware-securityheaders" alt="PyPI - License"/>
|
|
41
|
-
</a>
|
|
42
|
-
<a href="https://pypi.org/project/swarmauri-middleware-securityheaders/">
|
|
43
|
-
<img src="https://img.shields.io/pypi/v/swarmauri-middleware-securityheaders?label=swarmauri-middleware-securityheaders&color=green" alt="PyPI - swarmauri-middleware-securityheaders"/>
|
|
44
|
-
</a>
|
|
45
|
-
</p>
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
# Swarmauri Middleware Security Headers
|
|
50
|
-
|
|
51
|
-
Middleware for adding security-focused HTTP headers to FastAPI responses, helping shield applications from common web vulnerabilities.
|
|
52
|
-
|
|
53
|
-
## What it does
|
|
54
|
-
|
|
55
|
-
`SecurityHeadersMiddleware` ensures every response produced by your FastAPI
|
|
56
|
-
application carries the following headers and values:
|
|
57
|
-
|
|
58
|
-
- `Content-Security-Policy`: `default-src 'self'; script-src 'self'
|
|
59
|
-
https://cdn.example.com; style-src 'self' https://cdn.example.com; img-src
|
|
60
|
-
'self' https://images.example.com; font-src 'self'
|
|
61
|
-
https://fonts.example.com`
|
|
62
|
-
- `X-Content-Type-Options`: `nosniff`
|
|
63
|
-
- `X-Frame-Options`: `DENY`
|
|
64
|
-
- `X-XSS-Protection`: `1; mode=block`
|
|
65
|
-
- `Strict-Transport-Security`: `max-age=31536000; includeSubDomains; preload`
|
|
66
|
-
- `Referrer-Policy`: `same-origin`
|
|
67
|
-
- `Permissions-Policy`: `interest-cohort=(), geolocation=(self),
|
|
68
|
-
microphone=(), camera=(), magnetometer=(), gyroscope=(), speaker=(self),
|
|
69
|
-
vibrate=(), payment=()`
|
|
70
|
-
|
|
71
|
-
These defaults provide a strong baseline for many applications. Update the
|
|
72
|
-
middleware if you need to tailor the directives (for example, to change the
|
|
73
|
-
allowed host names in the Content Security Policy).
|
|
74
|
-
|
|
75
|
-
## Installation
|
|
76
|
-
|
|
77
|
-
### pip
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
pip install swarmauri-middleware-securityheaders
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Poetry
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
poetry add swarmauri_middleware_securityheaders
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### uv
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
uv add swarmauri_middleware_securityheaders
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## Usage
|
|
96
|
-
|
|
97
|
-
```python
|
|
98
|
-
from fastapi import FastAPI, Request
|
|
99
|
-
from swarmauri_middleware_securityheaders import SecurityHeadersMiddleware
|
|
100
|
-
|
|
101
|
-
app = FastAPI()
|
|
102
|
-
security_middleware = SecurityHeadersMiddleware(app)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
@app.middleware("http")
|
|
106
|
-
async def apply_security_headers(request: Request, call_next):
|
|
107
|
-
return await security_middleware.dispatch(request, call_next)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
@app.get("/")
|
|
111
|
-
async def read_root() -> dict[str, str]:
|
|
112
|
-
return {"status": "ok"}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
This pattern instantiates the middleware once and reuses its `dispatch` method
|
|
116
|
-
within FastAPI's `@app.middleware("http")` hook so that every response includes
|
|
117
|
-
the security headers listed above.
|
|
118
|
-
|
|
119
|
-
## Want to help?
|
|
120
|
-
|
|
121
|
-
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md) that will help you get started.
|
|
122
|
-
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<a href="https://pypi.org/project/swarmauri-middleware-securityheaders/">
|
|
5
|
-
<img src="https://img.shields.io/pypi/dm/swarmauri-middleware-securityheaders" alt="PyPI - Downloads"/>
|
|
6
|
-
</a>
|
|
7
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_securityheaders/">
|
|
8
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_securityheaders.svg"/>
|
|
9
|
-
</a>
|
|
10
|
-
<a href="https://pypi.org/project/swarmauri-middleware-securityheaders/">
|
|
11
|
-
<img src="https://img.shields.io/pypi/pyversions/swarmauri-middleware-securityheaders" alt="PyPI - Python Version"/>
|
|
12
|
-
</a>
|
|
13
|
-
<a href="https://pypi.org/project/swarmauri-middleware-securityheaders/">
|
|
14
|
-
<img src="https://img.shields.io/pypi/l/swarmauri-middleware-securityheaders" alt="PyPI - License"/>
|
|
15
|
-
</a>
|
|
16
|
-
<a href="https://pypi.org/project/swarmauri-middleware-securityheaders/">
|
|
17
|
-
<img src="https://img.shields.io/pypi/v/swarmauri-middleware-securityheaders?label=swarmauri-middleware-securityheaders&color=green" alt="PyPI - swarmauri-middleware-securityheaders"/>
|
|
18
|
-
</a>
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
# Swarmauri Middleware Security Headers
|
|
24
|
-
|
|
25
|
-
Middleware for adding security-focused HTTP headers to FastAPI responses, helping shield applications from common web vulnerabilities.
|
|
26
|
-
|
|
27
|
-
## What it does
|
|
28
|
-
|
|
29
|
-
`SecurityHeadersMiddleware` ensures every response produced by your FastAPI
|
|
30
|
-
application carries the following headers and values:
|
|
31
|
-
|
|
32
|
-
- `Content-Security-Policy`: `default-src 'self'; script-src 'self'
|
|
33
|
-
https://cdn.example.com; style-src 'self' https://cdn.example.com; img-src
|
|
34
|
-
'self' https://images.example.com; font-src 'self'
|
|
35
|
-
https://fonts.example.com`
|
|
36
|
-
- `X-Content-Type-Options`: `nosniff`
|
|
37
|
-
- `X-Frame-Options`: `DENY`
|
|
38
|
-
- `X-XSS-Protection`: `1; mode=block`
|
|
39
|
-
- `Strict-Transport-Security`: `max-age=31536000; includeSubDomains; preload`
|
|
40
|
-
- `Referrer-Policy`: `same-origin`
|
|
41
|
-
- `Permissions-Policy`: `interest-cohort=(), geolocation=(self),
|
|
42
|
-
microphone=(), camera=(), magnetometer=(), gyroscope=(), speaker=(self),
|
|
43
|
-
vibrate=(), payment=()`
|
|
44
|
-
|
|
45
|
-
These defaults provide a strong baseline for many applications. Update the
|
|
46
|
-
middleware if you need to tailor the directives (for example, to change the
|
|
47
|
-
allowed host names in the Content Security Policy).
|
|
48
|
-
|
|
49
|
-
## Installation
|
|
50
|
-
|
|
51
|
-
### pip
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
pip install swarmauri-middleware-securityheaders
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Poetry
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
poetry add swarmauri_middleware_securityheaders
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### uv
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
uv add swarmauri_middleware_securityheaders
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Usage
|
|
70
|
-
|
|
71
|
-
```python
|
|
72
|
-
from fastapi import FastAPI, Request
|
|
73
|
-
from swarmauri_middleware_securityheaders import SecurityHeadersMiddleware
|
|
74
|
-
|
|
75
|
-
app = FastAPI()
|
|
76
|
-
security_middleware = SecurityHeadersMiddleware(app)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
@app.middleware("http")
|
|
80
|
-
async def apply_security_headers(request: Request, call_next):
|
|
81
|
-
return await security_middleware.dispatch(request, call_next)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
@app.get("/")
|
|
85
|
-
async def read_root() -> dict[str, str]:
|
|
86
|
-
return {"status": "ok"}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
This pattern instantiates the middleware once and reuses its `dispatch` method
|
|
90
|
-
within FastAPI's `@app.middleware("http")` hook so that every response includes
|
|
91
|
-
the security headers listed above.
|
|
92
|
-
|
|
93
|
-
## Want to help?
|
|
94
|
-
|
|
95
|
-
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md) that will help you get started.
|
|
File without changes
|