Skip to content

fix(security): harden TLS verification, streaming, redaction, and routing guards - #174

Draft
skupriienko wants to merge 1 commit into
wave-1-tooling-hygienefrom
wave-2-transport-redaction
Draft

skupriienko wants to merge 1 commit into
wave-1-tooling-hygienefrom
wave-2-transport-redaction

Conversation

@skupriienko

@skupriienko skupriienko commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Stack (v1.9.2 Hardening Rollout)

Wave PR Base <- Head Scope
Wave 1 #173 master <- wave-1-tooling-hygiene CRIT-03, CRIT-04, CRIT-05, HIGH-06
-> Wave 2 (This PR) #174 wave-1-tooling-hygiene <- wave-2-transport-redaction CRIT-01, CRIT-02, HIGH-01 (lock), HIGH-02, HIGH-03, HIGH-04 (path), OPT-09
Wave 3 #175 wave-2-transport-redaction <- wave-3-boot-slots-pooling OPT-01..OPT-07, OPT-10, OPT-11, HIGH-01 (warn_unclosed)
Wave 4 #176 wave-3-boot-slots-pooling <- wave-4-builders-semver HIGH-04 (bool/stream), HIGH-05, HIGH-07, OPT-08
Wave 5 #177 wave-4-builders-semver <- wave-5-typing-stateful-tests MOD-02, MOD-04

Merge in order: #173 -> #174 -> #175 -> #176 -> #177.

Note

Stacked PR workflow note: ClusterFuzzLite PR fuzzing runs immediately on all PRs. Workflows scoped to branches: [master] (CI, PR Validation, Continuous Security Verification, CodeQL) trigger automatically after #173 merges into master and GitHub retargets this PR's base branch to master.


Summary

Wave 2 of 5 for v1.9.2 (stacked on #173 / wave-1-tooling-hygiene). Hardens TLS verification with enterprise custom CA bundle support, blocks HTTP redirect credential leakage (allow_redirects=False + fail-closed 3xx handling), secures attachment streaming against symlink/FIFO/TOCTOU hazards (O_NOFOLLOW + os.fstat), redacts formatted tracebacks (record.exc_text), adds thread-safe session initialization, and enforces complete builder and path-segment mediation through SecurityGuard.


Actions

  • Transport TLS, Redirects & Thread-Safe Sessions (mailjet_rest/client.py, mailjet_rest/config.py, CRIT-01, HIGH-01, HIGH-02, OPT-09):
    • Rejected verify=False and verify=None with ValueError + sys.audit events while validating custom CA bundle file and directory paths (CRIT-01).
    • Passed allow_redirects=False explicitly on transport calls and failed closed on 3xx redirect responses with sys.audit telemetry (CRIT-01).
    • Preserved status_code and response_body on 5xx error responses (HIGH-02), added double-checked _session_lock initialization (HIGH-01), and pre-computed SecretAuth Basic headers (OPT-09).
  • Descriptor-Safe Attachment Reads & Redaction (mailjet_rest/utils/guardrails.py, mailjet_rest/builders.py, CRIT-02, HIGH-03, HIGH-04):
    • Closed the /tmp early-return bypass in SecurityGuard.validate_attachment_path and opened validated paths in ChunkedStreamer.encode_file via os.O_NOFOLLOW + os.fstat S_ISREG and byte-cap checks (CRIT-02).
    • Rejected ? and # query/fragment delimiters in SecurityGuard.sanitize_segment, scrubbed record.exc_text, and added __tracebackhide__ = True around auth validation (HIGH-03).
    • Routed MessageBuilder.set_sender() through SecurityGuard.normalize_domain() and MessageBuilder.set_headers() through SecurityGuard.sanitize_headers() (HIGH-04).
  • Deprecation Stacklevel & Security Unit Coverage (mailjet_rest/endpoint.py, mailjet_rest/types.py, tests/unit/test_wave2_security.py):
    • Fixed deprecation warning stacklevel in Endpoint and added unit tests covering TLS verification, custom CAs, redirects, O_NOFOLLOW / FIFO attachment guards, exc_text redaction, and concurrent session setup.

Verification & Testing

  • Verified offline checks across the v1.9.2 stack: ruff check ., ruff format --check ., mypy --strict mailjet_rest, pyright mailjet_rest, slotscheck -m mailjet_rest, bandit -c pyproject.toml -r mailjet_rest, and pytest -n auto -W error tests/unit tests/property tests/regression (including tests/unit/test_wave2_security.py).
  • Live Mailjet API network tests (pytest -m network, samples/smoke_readme_runner.py) were skipped locally due to absent MJ_APIKEY_PUBLIC / MJ_APIKEY_PRIVATE credentials.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant