Redact SQLAlchemy bind params, attach SQL context to errors, add RFC8523 JTI replay and tests#4861
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3e8f8553a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| current_time = int(time.time()) | ||
| with _JTI_LOCK: | ||
| _purge_expired_jtis(current_time, max_age_seconds) | ||
| if jti in _JTI_CACHE: | ||
| return True | ||
| if current_time - iat <= max_age_seconds: | ||
| _JTI_CACHE[jti] = iat |
There was a problem hiding this comment.
Keep JTI cache alive through skew window
Replay detection uses _JTI_CACHE[jti] = iat and evicts entries based on current_time - seen_at > max_age_seconds. Because validate_enhanced_jwt_bearer allows tokens up to max_age_seconds + clock_skew_seconds, a token issued near the end of the max-age window can be replayed after max_age_seconds elapses but before max_age_seconds + clock_skew_seconds (the JTI entry gets purged, so the replay passes). Consider storing current_time (first-seen) instead of iat, or evict based on max_age_seconds + clock_skew_seconds so replays remain blocked for the entire validity window.
Useful? React with 👍 / 👎.
Motivation
authn.tenants) exist during tests.Description
_format_sqlalchemy_error_data,_safe_params_metadata, and_looks_like_validation_errorhelpers totigrbl/runtime/errors/utils.pyand exported them for use by the error conversion layer.tigrbl/runtime/errors/converters.pyto recognizeStatementErrorand to include SQL context or safe redaction metadata forStatementError,OperationalError, andDBAPIErrorwhen appropriate._JTI_CACHEwith locking and expiry logic intigrbl_auth/rfc/rfc8523.pyand invoked replay detection insidevalidate_enhanced_jwt_bearer.pkgs/standards/tigrbl_tests/tests/i9n/test_sqlalchemy_error_redaction_uvicorn.pyandpkgs/standards/tigrbl_tests/tests/unit/runtime/test_error_sqlalchemy_context.py) and extended RFC8523 tests to assert JTI replay behavior (pkgs/standards/tigrbl_auth/tests/unit/test_rfc8523_jwt_client_auth.py).authnschema inpkgs/standards/tigrbl_auth/tests/conftest.pyand cleaning it up after the engine is disposed so schema-qualified inserts succeed.Testing
uv run --directory pkgs/standards/tigrbl_auth --package tigrbl-auth ruff format .which completed successfully.uv run --directory pkgs/standards/tigrbl_auth --package tigrbl-auth ruff check . --fixwhich reportedAll checks passed!.tigrbl_authtest suite withuv run --package tigrbl-auth --directory standards/tigrbl_auth pytestand observed388 passed, 5 skipped, 83 deselected(all tests in that run passed).pkgs/standards/tigrbl_tests; those tests were added but not executed as part of thetigrbl_authpytest run above.Codex Task