Skip to content

Remove critical security stubs #279 #302: 2PC phase-2 fanout + voice API JWT validation - #5490

Merged
makr-code merged 2 commits into
developfrom
copilot/remove-critical-security-stubs
Jun 30, 2026
Merged

makr-code merged 2 commits into
developfrom
copilot/remove-critical-security-stubs

Conversation

Copilot AI commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Description

Issue: Stub #279 left remote 2PC participants in PREPARED state when phase-2 RPC transport was missing. Stub #302 accepted any non-empty bearer token without JWT/OIDC validation.

Solution: Replaced both stubs with production-grade implementations enforcing fail-closed, security-first behavior.

Changes

Stub #279 — Distributed Transaction Manager (Phase-2 Remote Decision Fanout)

  • Added constructor validation: if remote_phase1_dispatch is configured, phase-2 RPC transport (phase2_rpc_fn, remote_phase2_dispatch, or getRpcPhase2Fn()) MUST exist
  • Throws std::invalid_argument at startup on misconfiguration (fail-fast)
  • Enhanced error path with CRITICAL-level logging when transport unavailable during phase-2
  • Backward compatible: only validates when remote dispatch is actually configured

Stub #302 — Voice API Handler (**** Validation)**

  • Added thread-safe validator injection: setTokenValidatorFn(TokenValidatorFn) for production JWT/OIDC validators
  • Replaced stub validation with multi-layer fail-closed flow:
    1. Extract Authorization header
    2. Try injected JWT/OIDC validator (with exception handling)
    3. Fall back to AuthMiddleware validation if no validator injected
    4. Reject (401) on any error
  • All error paths explicitly return false (fail-closed); exceptions caught and converted to rejection
  • Added security-level logging (WARN/ERROR) for audit trail

Example Usage (Stub #302)

// At initialization, inject production JWT validator
auto validator = createProductionJWTValidator();
VoiceApiHandler::setTokenValidatorFn([validator](std::string_view token) {
    try {
        auto claims = validator->parseAndValidate(std::string(token));
        return claims.sub != "" && claims.aud == "voice-api";
    } catch (const std::exception& ex) {
        THEMIS_WARN("Token validation failed: {}", ex.what());
        return false;  // Fail-closed
    }
});

Type of Change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Refactoring (non-breaking)
  • Documentation
  • Breaking change (requires MAJOR version bump — see VERSIONING.md)
  • Security fix
  • Other:

Breaking Change Checklist

  • MAJOR version bump planned in VERSION and CMakeLists.txt
  • Migration guide added in docs/migration/
  • Announcement prepared for GitHub Discussions (≥ 2 weeks before release)
  • CHANGELOG ### Removed / ### Changed section updated

Migration Impact: Deployments using remote_phase1_dispatch without phase-2 RPC transport will fail at startup. This is intentional — phase-1 remote dispatch without phase-2 decision fanout violates 2PC semantics and can leave remote participants in PREPARED state indefinitely. Operators must explicitly configure phase-2 RPC bridge (via config or getRpcPhase2Fn()) or disable remote phase-1 dispatch.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • Benchmarks run (if performance-sensitive change)

Test Coverage: 12 comprehensive test cases in tests/security/test_stub_279_302_remediation.cpp

Security Tiering Impact (Required for Runtime Changes)

  • Impacted tier(s):

    • T0 Trusted Core
    • T1 Security & Platform Services
    • T2 Data Plane Engines
    • T3 Interface & Protocol Edge
    • T4 Managed Extension Runtime
    • T5 Plugin Boundary
    • N/A (docs-only / non-runtime)
  • Trust-boundary crossings documented in PR description

  • Boundary controls validated for affected T3/T4/T5 paths

    • T3/Voice API: JWT/OIDC validation enforced; all auth failures return 401 (fail-closed)
    • T1/Transaction: Phase-2 transport validation enforced at startup; configuration errors thrown immediately
  • Boundary-focused tests added/updated

    • Voice token validation tests cover invalid signatures, expiry, missing headers
    • Phase-2 fanout tests cover missing transport, misconfiguration, remote participant notification
  • If trust level/privilege increased, security maintainer approval is attached

📚 Research & Knowledge

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?

N/A: Remediation addresses known stubs; no new research basis required.

AI-Generated Code

  • Symbol-Referenzen mit GetSymbolReferences_CppTools geprüft
  • Keine rohen Pointer und kein new/delete ohne explizites Review eingeführt
  • RAII und Exception-Safety für neue/angepasste Pfade geprüft
  • Keine unnötig komplexen KI-Abstraktionen eingeführt
  • Performance-Metriken geprüft, falls Hotpath betroffen

Details: All changes use RAII patterns (lock_guard for mutex), no manual memory management, exception-safe try-catch blocks. Thread safety verified via static mutex protection in Stub #302. No performance-critical hotpaths modified.

AI Review Workflow

  • Findings-first review performed
  • Security hardening review performed (security-sensitive/runtime changes)
  • API impact review performed (new public API: setTokenValidatorFn)
  • All Critical/High findings are resolved or explicitly accepted
  • Residual risks and follow-up actions documented
  • Severity policy applied

Review Findings Summary:

  • Critical findings resolved: Configuration validation prevents unsafe 2PC state; fail-closed token validation prevents unauthorized access
  • Residual risks: None at code level; runtime validation depends on correct JWT validator configuration by operators (documented in code comments and migration guide)

Release Readiness Gate

  • Release readiness reviewed
  • Branch governance validated against BRANCHING_STRATEGY.md and RELEASE_STRATEGY.md
  • Versioning/changelog impact validated against VERSIONING.md and CHANGELOG.md

Branch Scope: Changes target develop branch (canonical development). Breaking change (T1 & T3 security tier) requires MAJOR version and release gate review.

Checklist

  • Code follows project style guidelines (clang-format / clang-tidy)
  • Self-review completed
  • Documentation updated (if needed)
  • CHANGELOG.md updated under [Unreleased]
  • No new warnings introduced
  • Security-sensitive paths reviewed by security maintainer (if applicable)

Scanner and IntelliSense Gates

Evidence:

  • Syntax validation: brace balance verified
  • Memory safety: RAII patterns used throughout (lock_guard, auto cleanup)
  • Thread safety: static validator protected with std::mutex
  • Exception safety: try-catch blocks added; all exceptions converted to fail-closed behavior
  • Security logging: CRITICAL/ERROR/WARN levels used appropriately for audit trail

Copilot AI changed the title [WIP] Remove critical legacy security and consistency stubs Remove critical security stubs #279 #302: 2PC phase-2 fanout + voice API JWT validation Jun 30, 2026
Copilot AI requested a review from makr-code June 30, 2026 05:28
@makr-code
makr-code marked this pull request as ready for review June 30, 2026 05:33
@makr-code
makr-code merged commit 253de5f into develop Jun 30, 2026
11 checks passed
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