Middleware and decorator for processing TLSv1.3 early data requests in Starlette
Project description
starlette-early-data
Middleware and decorator for processing TLSv1.3 early data requests in Starlette
Install: pip install starlette-early-data
What this package can do:
- Detect if request is early data and mark it (
request.state.early_data = True
) - Deny all early data requests (pass
deny_all=True
toadd_middleware
) - Deny early data requests to specific endpoints (use decorator
@deny_early_data
)
Example (test.py
):
import uvicorn
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from starlette_early_data import EarlyDataMiddleware, deny_early_data
app = Starlette()
app.add_middleware(EarlyDataMiddleware, deny_all=False)
@app.route("/")
async def home(request: Request) -> PlainTextResponse:
return PlainTextResponse("Always OK if deny_all=False")
@app.route("/security_risk")
@deny_early_data
async def security_risk(request: Request) -> PlainTextResponse:
return PlainTextResponse("Security action done after handshake")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080)
Send request to http://127.0.0.1:8080/security_risk
with header Early-Data=1
and you will get 425.
Request to http://127.0.0.1:8080/
with the same header will only return 425 if you pass deny_all=True
to app.add_middleware(...)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for starlette-early-data-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e86ce0b9eb32236eebee30e1c3f679f022517b907efd911ec270c128ca7d6e7 |
|
MD5 | 86d4ba06d532048255666b4f30436686 |
|
BLAKE2b-256 | 796a418a6e9a137ad4620f7f08dad7721d2d14a1e926793c20e5273e64665931 |
Close
Hashes for starlette_early_data-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ae4a3df501d42867e0daeebe5b7eb252ae74780ee70a83c08c07d7d066aa09f |
|
MD5 | 9a4084e9123c5dd26e5f7d50b3b60c66 |
|
BLAKE2b-256 | 8ce5536135d1bc8ddb086d20c951001b8a0a83328bafdd483224c69d79b8aa77 |