Reject whitespace-padded account and wallet paths#782
Conversation
📝 WalkthroughWalkthroughThis PR introduces a centralized path-parameter validation helper to reject whitespace-padded path segments and applies it consistently to account and wallet route handlers across both API and HTML endpoints. All affected routes now validate and reject leading or trailing whitespace before processing requests. ChangesPath Whitespace Padding Validation
Possibly related issues
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: bbb71272-8265-4b61-b10c-c309ad34e646
📒 Files selected for processing (7)
app/accounts.pyapp/path_params.pyapp/public_routes.pyapp/wallet_api.pytests/test_account_validation.pytests/test_api_mcp.pytests/test_wallet_api.py
| if any(ord(char) < 32 or 127 <= ord(char) < 160 for char in value): | ||
| return |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | 💤 Low value
Consider adding a comment explaining the control-character bypass.
The early return when control characters are present is intentional and correct—it allows control-character validation to take precedence when both issues exist. However, the rationale is subtle: the range check excludes ordinary space (U+0020, ord=32) while catching C0/C1 controls, so that contains_control_character downstream can provide a more specific error for strings like " \tgithub:alice".
📝 Suggested comment
+# Skip whitespace validation if control characters are present; those will be
+# caught by contains_control_character with a more specific error message.
+# Ordinary space (U+0020) is not in these ranges and will still be validated.
if any(ord(char) < 32 or 127 <= ord(char) < 160 for char in value):
return
shaiananvari8
left a comment
There was a problem hiding this comment.
Reviewed current head 8ce87f23f31d680b099d11c5058e6538fa18e6a7 as a non-author.
I checked the account and wallet path surfaces touched by this PR:
app/accounts.py,app/path_params.py,app/public_routes.py,app/wallet_api.pytests/test_account_validation.py,tests/test_api_mcp.py,tests/test_wallet_api.py
Local validation passed:
pytest tests/test_account_validation.py tests/test_wallet_api.py::test_wallet_lookup_rejects_path_whitespace_padding tests/test_wallet_api.py::test_wallet_lookup_rejects_invalid_addresses_before_lookup -q->49 passed, 1 warning- targeted Ruff check passed
- targeted Ruff format check passed (
7 files already formatted) git diff --check origin/main...HEADpassedgit merge-tree --write-tree origin/main HEADpassed with clean treedd3e7592d989866a7ea9e21f268c341489fca97f
I also ran a small TestClient probe that verified clean mixed-case identifiers still normalize while space-padded HTTP path identifiers fail closed:
/api/v1/accounts/GitHub:Alice-> 200 /github:alice/api/v1/accounts/%20GitHub:Alice%20-> 400 /account must not contain leading or trailing whitespace/accounts/%20GitHub:Alice%20-> 400 / same detail/api/v1/wallets/<uppercase valid wallet>-> 200 / normalized lowercase address/api/v1/wallets/%20<wallet>%20-> 400 /MRWK wallet address must not contain leading or trailing whitespace/wallets/%20<wallet>%20-> 400 / same detail
GitHub reports the PR clean; hosted Quality/readiness/docs/image check and CodeRabbit are successful. I did not find a blocking issue in the current head. The CodeRabbit note about documenting the control-character precedence is reasonable but non-blocking because the downstream account/wallet validators still produce the specific control-character errors.
|
Current-head review for the #654 review bounty. I reviewed head What I checked:
Public live probe:
I did not find a blocker in this patch. The change is scoped to HTTP path identifiers, while leaving MCP string argument normalization and existing control-character errors intact. |
aunysillyme
left a comment
There was a problem hiding this comment.
Approved PR #782.
Evidence & Findings:
- Checked out and inspected current-head commit
8ce87f23f31d680b099d11c5058e6538fa18e6a7on branchpr-782. - Inspected files
app/accounts.py,app/path_params.py,app/public_routes.py,app/wallet_api.py,tests/test_account_validation.py,tests/test_api_mcp.py, andtests/test_wallet_api.py. - Verified the stricter validation of URL path parameters in
app/path_params.py: JONASXZB introducedreject_path_whitespace_padding(value: str, field: str)which correctly throws an HTTP 400 Bad Request error if a path parameter contains leading or trailing ordinary whitespace. - Verified that this guard is applied cleanly to public account details routes, accepted work details routes, and wallet details API/page routes. Padded or malformed path variables (e.g.
%20github:aliceorgithub:alice%20) are now correctly rejected upfront before normalization, preventing loose URL alias mapping. - MCP tool integration was verified: mixed-case normalization and balance lookup for arguments (like
" GitHub:Alice ") remain fully functional as intended. - Verified all targeted unit tests pass successfully: ran
PYTHONPATH=. .venv/bin/pytest tests/test_account_validation.py tests/test_api_mcp.py tests/test_wallet_api.pyand got 190/190 green tests passing cleanly under 18s. - Verified ruff check formatting is 100% compliant with no lints across the modified codebase.
- Confirmed no trailing whitespaces (
git diff --checkpasses cleanly).
No secrets, wallet private credentials, private vulnerability details, deployment keys, private payout details, or MRWK price claims were included.
Refs #656
Related report: #656 (comment)
Related proposed work: #778
Summary
%20-padded HTTP path identifiers.Why
Live public checks showed
/api/v1/accounts/%20github:...,/accounts/...%20,/api/v1/wallets/%20mrwk1..., and/wallets/...%20normalized to canonical resources with HTTP 200. That makes malformed generated URLs look canonical. This PR keeps normal clean values working and rejects whitespace-padded path aliases with bounded 400 responses.Verification
.venv/bin/python -m pytest tests/test_account_validation.py tests/test_wallet_api.py::test_wallet_lookup_rejects_path_whitespace_padding tests/test_wallet_api.py::test_wallet_lookup_rejects_invalid_addresses_before_lookup -q-> 49 passed, 1 warning.venv/bin/python -m pytest tests/test_api_mcp.py::test_github_account_views_normalize_mixed_case_logins tests/test_account_validation.py tests/test_wallet_api.py::test_wallet_lookup_rejects_path_whitespace_padding -q-> 49 passed, 1 warning.venv/bin/python -m pytest -q-> 684 passed, 1 warning.venv/bin/python -m ruff format --check .-> 104 files already formatted.venv/bin/python -m ruff check .-> All checks passedgit diff --check-> cleanNo secrets, wallet material, private vulnerability details, deployment credentials, payout details, MRWK price/exchange, or bridge/liquidity claims are included.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests