Skip to content

refactor: Modernize SDK architecture, harden security, and enable O(1) routing#130

Open
skupriienko wants to merge 26 commits into
masterfrom
refine-client
Open

refactor: Modernize SDK architecture, harden security, and enable O(1) routing#130
skupriienko wants to merge 26 commits into
masterfrom
refine-client

Conversation

@skupriienko
Copy link
Copy Markdown
Collaborator

@skupriienko skupriienko commented May 26, 2026

Links:

Jira

Actions:

  • Core SDK & Routing Architecture:

    • O(1) Registry Routing: Implemented an immutable ROUTE_MAP registry, eliminating dynamic __getattr__ overhead and enabling efficient, static endpoint resolution.
    • TemplateContentBuilder: Added a fluent builder for Content API payloads with built-in schema validation (Fail-Fast pattern).
    • Pagination Stability: Fixed infinite loop edge-cases in .stream() generators by ensuring empty data blocks trigger termination.
  • Security & Developer Experience (DX):

    • Path Traversal Mitigation (CWE-22): Hardened Endpoint._build_url with centralized sanitize_segment to neutralize directory traversal attempts in dynamic URI parameters.
    • Context Manager Enforcement: Strong promotion of with Client(...) as client: to mitigate CWE-772 (Missing Resource Release).
    • SSRF Guardrails: Implemented strict domain anchoring in Config.validate_config_url.
    • Enterprise Fuzzing: Integrated Atheris (libFuzzer) to expose edge-case parsing exceptions.
  • Unit & Integration Tests:

    • Registry-First Testing: Added a comprehensive, parameterized test suite for 40+ endpoints ensuring full parity with legacy routing logic.
    • Performance Benchmarks: Integrated pytest-benchmark and cold-boot profiling to ensure SDK startup latency remains within strictly defined thresholds (<0.1s).
    • CI/CD Hardening: Segregated testing topologies (Unit/Integration/Regression) to ensure clean CI execution.
  • CI/CD, Linting & Repository Management:

    • Defense in Depth: Integrated GitHub CodeQL, Google OSV-Scanner, and Semgrep (OWASP Top 10 ruleset) for automated security auditing.
    • Linting Resolution: Resolved all D10x, DOC201, and PLC0415 errors, enforcing strict Google-style documentation and import placement.
    • Supply Chain: Decoupled pip-audit into a standalone strict job.
  • Documentation & Samples:

    • README Overhaul: Modernized all code snippets to enforce safe memory/socket management via Context Managers.
    • Release Prep: Synchronized CHANGELOG.md with 1.7.0 updates, updated PERFORMANCE.md with new benchmarks, and bumped version to 1.7.0.

@skupriienko skupriienko self-assigned this May 26, 2026
@skupriienko skupriienko marked this pull request as ready for review May 26, 2026 12:21
@skupriienko skupriienko reopened this May 26, 2026
@skupriienko skupriienko reopened this May 26, 2026
Comment thread .github/workflows/security.yml Fixed
Comment thread .github/workflows/security.yml Fixed
Comment thread .github/workflows/security.yml Fixed
Comment thread .github/workflows/security.yml Fixed
Comment thread tests/unit/test_client.py Fixed
Comment thread tests/unit/test_client.py Fixed
Comment thread tests/unit/test_client.py Fixed
Comment thread tests/unit/test_client.py Fixed
Comment thread mailjet_rest/types.py Fixed
Comment thread mailjet_rest/types.py Fixed
Comment thread mailjet_rest/types.py Fixed
Comment thread mailjet_rest/types.py Fixed
Comment thread mailjet_rest/types.py Fixed
Comment thread mailjet_rest/types.py Fixed
Comment thread .github/workflows/security.yml Fixed
skupriienko and others added 4 commits May 26, 2026 16:13
…ntain permissions'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread mailjet_rest/client.py Fixed
Comment thread tests/fuzz/fuzz_builder.py Fixed
Comment thread tests/fuzz/fuzz_client.py Fixed
Comment thread tests/fuzz/fuzz_guardrails.py Fixed
Comment thread tests/unit/test_client.py Fixed
Comment thread tests/fuzz/fuzz_core.py Fixed
skupriienko and others added 3 commits May 26, 2026 17:43
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Comment thread tests/unit/test_client.py Fixed
…rpolation

This modernization transitions the SDK from a dynamic __getattr__
resolution mechanism to an immutable, O(1) Registry-First architecture,
improving cold-boot performance and establishing strict API boundaries.

Security (CWE-22):
- Mitigated Path Traversal vulnerabilities in Endpoint._build_url.
  Dynamic URI template variables (e.g., {id}, {action_id}) are now
  strictly sanitized via urllib.parse.quote(safe=) prior to regex
  interpolation.

Architecture & DX:
- Added mailjet_rest/routes.py containing an immutable MappingProxyType
  registry defining exact API versions and paths for all resources.
- Introduced TemplateContentBuilder with fail-fast Boundary Parsing
  to enforce schema correctness before network execution.
- Removed legacy _DYNAMIC_ENDPOINTS tuple, completely decoupling
  the Client from hardcoded resource lists.

Testing:
- Deployed a data-driven, parameterized test suite covering 50+
  registry combinations, proving 100% parity with legacy routing logic
  and explicit separation between Content API (v1) and Email API (v3).
- feat(routing): implement O(1) registry-based routing with safe URI interpolation
- feat(security): mitigate CWE-22 (Path Traversal) via centralized segment sanitization
- feat(builders): add TemplateContentBuilder for structured Content API payloads
- fix(linting): resolve all docstring and import grouping lint errors
- refactor: centralize types and constants in types.py to reduce boot-time overhead
- test: expand test suite with parameterization for registry parity and security
Comment thread mailjet_rest/types.py Dismissed
Comment thread mailjet_rest/types.py Dismissed
Comment thread mailjet_rest/types.py Dismissed
Comment thread mailjet_rest/types.py Dismissed
Comment thread mailjet_rest/types.py Dismissed
Comment thread mailjet_rest/types.py Dismissed
@skupriienko skupriienko changed the title Harden security workflows and packaging refactor: Modernize SDK architecture, harden security, and enable O(1) routing May 28, 2026
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.

2 participants