Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
53915c4
chore(build): clean up pyproject.toml for 2.0.0
cak Sep 28, 2025
bc89714
fix: specify type for params in Secure class constructor
cak Sep 28, 2025
c33dd0f
fix(headers): expose cached headers as immutable Mapping
cak Oct 25, 2025
6f737bb
fix(headers): clarify sync errors and add safe fallback
cak Oct 25, 2025
acafd8c
chore(build): clean up pyproject.toml for Ruff and setuptools
cak Oct 26, 2025
119b319
style(secure): apply Ruff-driven refactors and import sorting
cak Oct 26, 2025
1424067
Preserve multi-valued headers in setters
cak Oct 26, 2025
b90f1b9
fix(headers): robust error handling in setting headers
cak Oct 26, 2025
fab44bf
secure: validate header names/values before write
cak Oct 26, 2025
d7d73d8
refactor(headers): streamline validation and normalization logic
cak Oct 29, 2025
edd5c19
headers: add deduplicate_headers() and simplify header_items()
cak Nov 8, 2025
0b33484
headers: add allowlist_headers(
cak Nov 8, 2025
af6d0aa
Fix internal header invariants and normalization pipeline
cak Dec 9, 2025
eb7b916
refactor: enforce synchronous header setting in set_headers()
cak Dec 9, 2025
a17dfd8
refactor: enforce async-only header setting in apply_headers()
cak Dec 9, 2025
8930356
refactor: remove runtime_checkable decorator from protocol classes
cak Dec 9, 2025
4cc4c4f
fix: handle duplicate headers during normalization and clarify async …
cak Dec 9, 2025
229c2c5
refactor: improve documentation and type hints for header management …
cak Dec 10, 2025
2a5fbb7
refactor: add noqa comments to suppress linting warnings in header va…
cak Dec 10, 2025
a6f1b38
refactor: enhance error handling and validation logic in Secure class…
cak Dec 10, 2025
acd92d0
refactor: streamline Secure class initialization with preset configur…
cak Dec 10, 2025
0e1407d
docs: update README for clarity and consistency, enhancing descriptio…
cak Dec 10, 2025
14d22c9
feat: add new security headers and enhance Secure class with modern p…
cak Dec 11, 2025
6ed8538
feat: enhance Cache-Control header with max-age directive and add req…
cak Dec 11, 2025
b8f7f17
feat: enhance Content Security Policy with additional directives for …
cak Dec 11, 2025
fe60457
feat: add initial uv.lock file for package management
cak Dec 11, 2025
17a8b13
feat: update Cache-Control documentation and enhance directive descri…
cak Dec 11, 2025
418f611
feat: enhance Cross-Origin-Embedder-Policy documentation and add dire…
cak Dec 12, 2025
0a6cb98
feat: refine Cache-Control header implementation and enhance document…
cak Dec 12, 2025
4530530
feat: enhance Content Security Policy implementation with structured …
cak Dec 12, 2025
69b9a10
feat: enhance Cross-Origin-Opener-Policy implementation with improved…
cak Dec 12, 2025
6f027e8
feat: enhance Cross-Origin-Resource-Policy implementation with improv…
cak Dec 13, 2025
b682275
feat: enhance Permissions-Policy implementation with improved validat…
cak Dec 13, 2025
3bdedec
feat: improve Referrer-Policy implementation with enhanced validation…
cak Dec 13, 2025
deddde4
feat: enhance Strict-Transport-Security implementation with structure…
cak Dec 13, 2025
124100f
feat: enhance Cache-Control documentation with improved structure and…
cak Dec 13, 2025
bbf2935
feat: enhance Content-Security-Policy documentation with improved str…
cak Dec 13, 2025
49bfd8e
feat: enhance Cross-Origin-Embedder-Policy documentation with improve…
cak Dec 13, 2025
e9022e6
feat: enhance Cross-Origin-Opener-Policy documentation with improved …
cak Dec 13, 2025
cfd2704
feat: add Cross-Origin-Resource-Policy documentation with purpose, be…
cak Dec 13, 2025
5379d5b
feat: enhance Permissions-Policy documentation with improved clarity,…
cak Dec 13, 2025
44c4cd3
feat: enhance Referrer-Policy documentation with improved clarity, st…
cak Dec 13, 2025
076f0f7
feat: enhance Strict-Transport-Security documentation with improved c…
cak Dec 13, 2025
d11d0fc
feat: enhance X-Content-Type-Options documentation with improved clar…
cak Dec 13, 2025
3667601
feat: enhance XDnsPrefetchControl documentation and improve method cl…
cak Dec 13, 2025
68b90a5
feat: add X-DNS-Prefetch-Control documentation with usage examples an…
cak Dec 13, 2025
9bc6d9c
feat: enhance X-Frame-Options documentation with improved clarity, st…
cak Dec 13, 2025
ba51c1d
feat: enhance X-Frame-Options documentation with improved clarity, st…
cak Dec 13, 2025
4b52ab4
feat: enhance X-Permitted-Cross-Domain-Policies documentation with im…
cak Dec 13, 2025
01b3cc3
feat: add X-Permitted-Cross-Domain-Policies documentation with detail…
cak Dec 13, 2025
86179eb
feat: enhance Cache-Control class with improved directive handling an…
cak Dec 13, 2025
502fbb3
feat: update Secure class to enhance cache handling and permissions p…
cak Dec 13, 2025
472ed11
feat: update usage documentation with enhanced Cache-Control directiv…
cak Dec 13, 2025
b4265d9
feat: add comprehensive unit tests for Secure class header management
cak Dec 13, 2025
4c3689f
test: fix expected Cache-Control header values in unit tests
cak Dec 13, 2025
df81893
feat: add test suite for the top-level secure package
cak Dec 13, 2025
686e027
refactor: simplify header dictionary comprehensions in unit tests
cak Dec 13, 2025
05fda9d
feat: enhance security headers in README with updated Cache-Control a…
cak Dec 13, 2025
18d7f95
feat: implement header item resolution with override support in Secur…
cak Dec 13, 2025
5c2c9b6
feat: add validation and normalization tests for custom headers in Se…
cak Dec 13, 2025
16d5750
docs: clarify header normalization process in README
cak Dec 13, 2025
c73e7a9
feat: add header value normalization to various headers for improved …
cak Dec 13, 2025
c1b025b
feat: add unit tests for header consistency and validation in test_he…
cak Dec 13, 2025
c0f3c2e
feat: update documentation for v2.0.0 migration, including package na…
cak Dec 13, 2025
af8e86e
feat: add additional security headers validation in TestSecure class
cak Dec 13, 2025
7421c19
feat: enhance header tests with additional assertions and new test ca…
cak Dec 13, 2025
a388684
feat: update MockResponseAwaitableSetHeader to return Awaitable in se…
cak Dec 13, 2025
63ded3a
feat: update CHANGELOG for v2.0.0 release, detailing breaking changes…
cak Dec 13, 2025
6b80c8d
feat: update security presets to include a new BALANCED option and re…
cak Dec 13, 2025
3b77267
feat: update documentation to reflect changes in presets and defaults…
cak Dec 13, 2025
e9220e8
feat: update tests to validate Balanced preset defaults and exclusion…
cak Dec 13, 2025
b1ee387
feat: add SecureASGIMiddleware and SecureWSGIMiddleware for enhanced …
cak Dec 14, 2025
ca8bdd9
feat: refactor multi_ok parameter to use Iterable for SecureASGIMiddl…
cak Dec 14, 2025
44a5e64
feat: add middleware documentation for SecureWSGIMiddleware and Secur…
cak Dec 14, 2025
3c4d12f
feat: update per-file ignores in Ruff configuration for tests to enha…
cak Dec 14, 2025
239001f
feat: add unit tests for Secure header management, validating header …
cak Dec 14, 2025
4c4f2bb
move middleware tests into /middleware
cak Dec 14, 2025
b9251b4
feat: reorganize imports in __init__.py for better readability and ma…
cak Dec 14, 2025
1babaf4
feat: improve string representation of headers in Secure class for cl…
cak Dec 14, 2025
671f1fd
feat: add tests for string representation normalization and package e…
cak Dec 14, 2025
d5162f8
feat: add default value fields to security headers for consistency an…
cak Dec 14, 2025
1b6f76c
feat: enhance documentation and structure of CustomHeader class for c…
cak Dec 14, 2025
6c8ce01
feat: add expected header names and support for clear resets in heade…
cak Dec 14, 2025
18ffc96
feat: update documentation with migration notes for v2.0.0 release an…
cak Dec 14, 2025
2c37884
feat: update __all__ exports to include XDnsPrefetchControl and XPerm…
cak Dec 14, 2025
bf04383
feat: add unit tests for package exports in secure, headers, and midd…
cak Dec 14, 2025
f6caa29
feat: add linting step to CI workflow using ruff
cak Dec 14, 2025
d4e3691
feat: format default header value in ContentSecurityPolicy docstring …
cak Dec 14, 2025
1701d37
feat: refactor field definitions for XPermittedCrossDomainPolicies cl…
cak Dec 14, 2025
56e17e1
feat: add CrossOriginResourcePolicy to imports and exports for consis…
cak Dec 14, 2025
dd27fd8
feat: add CrossOriginResourcePolicy to secure package exports test
cak Dec 14, 2025
303900a
feat: enhance middleware documentation and normalize header handling
cak Dec 15, 2025
0256594
feat: enhance ASGI typing and add middleware factory method for compa…
cak Dec 15, 2025
50490bb
feat: improve header setting logic for response objects and enhance e…
cak Dec 15, 2025
49f065c
feat: refine ASGI typing aliases and enhance middleware documentation
cak Dec 15, 2025
71ed91e
feat: add FastAPI and Flask middleware examples to README
cak Dec 15, 2025
b6a3b78
feat: refine ASGI typing aliases and improve header normalization fun…
cak Dec 15, 2025
0055fb1
feat: enhance WSGI typing aliases and improve header normalization in…
cak Dec 15, 2025
826e7c0
feat: refine ASGI typing aliases and enhance ASGIApp definition
cak Dec 15, 2025
47b7b37
feat: add Shiny ASGI middleware example to README
cak Dec 15, 2025
37c4120
feat: refine ASGI typing aliases and improve middleware type handling
cak Dec 15, 2025
58e67eb
fix: update Secure instantiation in aiohttp example for clarity
cak Dec 15, 2025
43ba24d
fix: update ResponseProtocol definition to use TypeAlias for clarity
cak Dec 15, 2025
5f719a7
fix: correct license declaration and update classifiers in pyproject.…
cak Dec 15, 2025
175b6bc
fix: enhance type casting for response headers handling in Secure class
cak Dec 15, 2025
d166640
fix: add Dash and Shiny framework integration guides to README
cak Dec 15, 2025
bf974f1
fix: update configuration guide to clarify default security headers a…
cak Dec 15, 2025
53ceed7
fix: add Dash and Shiny framework integration examples to documentation
cak Dec 15, 2025
79a72d0
fix: update installation guide to include `uv` installation instructions
cak Dec 15, 2025
609f56e
fix: correct reference to secure.MULTI_OK in middleware documentation
cak Dec 15, 2025
120da9f
docs: add contributing guidelines for project contributions
cak Dec 15, 2025
3aa7ab3
docs: add Code of Conduct to outline community expectations and behavior
cak Dec 15, 2025
25c5da7
docs: enhance security header documentation by removing content refer…
cak Dec 15, 2025
eb9a8ef
docs: add Cross-Origin-Resource-Policy and additional security header…
cak Dec 15, 2025
0cc3d78
fix: update version to 2.0.0rc1 and adjust license format in pyprojec…
cak Dec 16, 2025
ce8ac36
fix: correct license format and add missing classifier for MIT License
cak Dec 16, 2025
cd030aa
fix: remove redundant classifier for MIT License in pyproject.toml
cak Dec 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install toolchain
run: pip install ruff
- name: Unit tests
run: python -m unittest tests/*/*.py
- name: Lint
run: ruff check secure tests
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Placeholder for upcoming changes.

## [2.0.0] - 2025-12-13

### Breaking Changes

- The `Secure` API now requires Python 3.10+ and uses the new builder-style header modules with full typing; this release replaces the previous legacy surface and removes the older cookie-centric helpers.

### Added

- Comprehensive validation pipeline helpers (`allowlist_headers`, `deduplicate_headers`, `validate_and_normalize_headers`) and typed presets for `Secure`.
- New header builder coverage for modern headers (CSP, Permissions Policy, COEP, etc.) with deterministic outputs.
- Async-safe `set_headers_async` support for both method-call and mapping-style response objects plus helper mocks and contract tests.

### Testing

- Added full contract tests for the header builders along with end-to-end coverage for `Secure` usage and response integration.

### Docs

- Expanded README with usage examples, advanced pipeline guidance, and updated framework integration references.

## [1.0.1] - 2024-10-18

### Fixed
Expand Down
38 changes: 38 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Code of Conduct

This Code of Conduct applies to all `secure` community spaces.

## Our Pledge

We’re committed to a welcoming, safe, equitable community for everyone. Treat others with respect and assume good faith.

## Expected Behavior

- Be kind, constructive, and professional.
- Respect different viewpoints and experiences.
- Take responsibility for your actions and help repair harm.
- Give and accept feedback gracefully.

## Unacceptable Behavior

- Harassment, threats, or hate/discrimination.
- Personal attacks, sexualized behavior, or stereotyping.
- Sharing someone’s private information without consent.
- Impersonation, misleading identity, or evasions of enforcement.
- Spam/promotional content outside community norms.

## Reporting

Report issues to **caleb@typeerror.com**. Maintainers will review reports promptly and handle them as confidentially as possible.

## Enforcement

Maintainers may take action appropriate to the situation, including warnings, temporary limits, suspension, or a permanent ban.

## Scope

Applies in project spaces (issues, PRs, discussions, chats) and when representing the project publicly.

## Attribution

Adapted from the Contributor Covenant v3.0: https://www.contributor-covenant.org/version/3/0/
64 changes: 64 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Contributing

Thanks for helping make `secure` better. The following guidance keeps contributions aligned with the project’s release-quality standards.

## Development environment

1. Create a virtual environment and activate it:
```bash
python -m venv .venv
source .venv/bin/activate
```
2. Install the package in editable mode so local changes are picked up automatically:
```bash
pip install -e .
```
3. Install the tooling used by the project:
```bash
pip install ruff
```
_Optional:_ `uv` is the package manager used by the project for releases; you can use `uv add ...` to manage dependencies, but it is not required for local development.

## Running tests, linting, and formatting

- **Run unit tests:** `python -m unittest tests/*/*.py`
- **Run the linter:** `ruff check`
- **Apply formatting / fix issues:** `ruff format`

Run these commands before opening a pull request. If you rely on a different Python version, keep it within the supported range (Python 3.10+).

## Adding a header document

1. Add a new guide under `docs/headers/` named after the header (for example, `docs/headers/example_header.md`).
2. Mirror the structure of the existing header docs:
- Start with a **Purpose** section that explains the header’s intent.
- Describe the **Default behavior** and mention how the builder models that default.
- Show a **Using with `Secure`** example and describe the builder API with method names.
- Include **Resources** / **Attribution** and any security caveats.
3. Link the new document from `docs/README.md` (under the Security Headers list) so readers can discover it easily.
4. Ensure code snippets use the public API (`from secure import ...`), reference the appropriate response types, and avoid framework-specific terminology unless a callout is necessary.

## Adding a framework example

1. Update `docs/frameworks.md`:
- Add the framework to the table of contents.
- Include a short intro describing the framework’s model (WSGI vs ASGI, sync vs async).
- Provide at least one working example showing how to wire `Secure` (middleware, hooks, or response-level helpers).
- Mention the correct response type (`Response`, `JSONResponse`, etc.) or highlight that you are working with the framework’s default response object.
2. If the framework needs extra instructions (e.g., disabling Uvicorn’s `Server` header), document them in the same section.
3. Keep the tone focused on security headers rather than broader framework guidance.

## Commit conventions

- Keep commit messages short (<72 characters) and in the imperative (e.g., `docs: clarify defaults`).
- Prefix doc-only changes with `docs:` so reviewers immediately know the scope.
- Reference any related issue or PR in the description when applicable.
- Run linting/tests before committing to minimize follow-up work.

## Pull request checklist

- [ ] I have run `python -m unittest tests/*/*.py` locally (or a representative suite) and addressed any failures.
- [ ] I have run `ruff check` and `ruff format` (when formatting attr).
- [ ] Documentation updates describe the new behavior (new header docs, framework guidance, etc.).
- [ ] If applicable, I have updated the release notes/CHANGELOG entry for new user-visible behavior.
- [ ] My changes follow the project’s security and contribution guidelines (this document).
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

Loading
Loading