Refs #576: Reject control chars in JSON integer fields#614
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe ChangesControl character validation
Possibly related PRs
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
eliasx45
left a comment
There was a problem hiding this comment.
Reviewed current head de30d8b0e7b0776d5bd582e9997239da88b5e512 for Refs #576.
Verdict: approve.
The shared _parse_int() guard now rejects ASCII control characters before whitespace normalization, so a body field like nonce=\t1 cannot be accepted as canonical integer 1 after the signature was computed for 1. The regression signs the canonical transfer payload, submits the control-character-padded nonce, verifies the bounded 400 response, and confirms the receiver balance does not change.
Validation on this checkout:
git diff --check origin/main...HEAD
# clean
git merge-tree --write-tree origin/main HEAD
# 924f4574d1954dcc5eca1347689ac6b2a74ed3c8
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 ..\mergework\.venv\Scripts\python.exe -m pytest tests\test_wallet_api.py::test_wallet_transfer_api_rejects_control_character_nonce_string tests\test_wallet_api.py::test_wallet_transfer_api_rejects_replayed_signed_body tests\test_wallet_api.py::test_wallet_transfer_api_rejects_invalid_requests tests\test_wallet_api.py::test_wallet_transfer_api_returns_validation_error tests\test_wallet_api.py::test_wallet_transfer_api_rejects_memo_control_characters -q
# 8 passed
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 ..\mergework\.venv\Scripts\python.exe -m pytest tests\test_wallet_api.py -q
# 34 passed
..\mergework\.venv\Scripts\python.exe -m ruff check app\main.py tests\test_wallet_api.py
# passed
..\mergework\.venv\Scripts\python.exe -m ruff format --check app\main.py tests\test_wallet_api.py
# 2 files already formatted
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 ..\mergework\.venv\Scripts\python.exe -m mypy app\main.py
# success
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 ..\mergework\.venv\Scripts\python.exe scripts\docs_smoke.py
# docs smoke ok
GitHub readback: PR is open/non-draft, merge state is clean, hosted CI is green, and CodeRabbit has no actionable comments. I used isolated local SQLite files for the pytest runs to avoid cross-process schema collisions in this workspace.
Summary
nonce="\t1"no longer succeeds even with a signature for nonce1Evidence
Before this fix, the public wallet transfer API accepted a control-character-padded integer string after
strip():POST /api/v1/transferswithnonce="\t1"and a valid signature for nonce1returned HTTP 200 and created a transfer. That makes the submitted body less strict than the signed canonical integer payload.This PR rejects C0/DEL control characters in
_parse_int()before whitespace normalization, so shared JSON body integer fields fail closed with a bounded400such asnonce must not contain control characters.Validation
tests/test_wallet_api.py::test_wallet_transfer_api_rejects_control_character_nonce_string-> 1 passed, 1 warningtests/test_wallet_api.py-> 34 passed, 1 warningruff check app/main.py tests/test_wallet_api.py-> passedruff format --check app/main.py tests/test_wallet_api.py-> 2 files already formattedmypy app/main.py-> successscripts/docs_smoke.py-> docs smoke okgit diff --check-> cleanNo private data, wallet private material, tokens, admin access, production mutation, price/liquidity/exchange/bridge/off-ramp claims, or fabricated payout claims are included.
Summary by CodeRabbit