Security: limit parameter tests cover only huge values, not negative or zero inputs [SEC-F05] #431
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#431
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Seven list routes in the indexer API enforce an upper-bound cap on the
limitquery parameter. Integration tests inindexer/tests/security.rsconfirm the cap by sendinglimit=99999and asserting the response count does not exceed the max. No test sends a negative value orlimit=0on any route. The checklist explicitly requires tests covering negative, zero, huge, and valid values. Lower-bound behavior for negative and zero inputs is unverified by any automated test.What Was Checked
indexer/tests/security.rslines 152-340: all seven capped-limit tests uselimit=99999orlimit=999999. Searched for "negative", "limit=-", "limit=0", "zero" across security.rs -- none present. Confirmed by direct file read./api/v1/pairs/{addr}/trades(line 160),/api/v1/pairs/{addr}/candles(line 179),/api/v1/oracle/history(line 237),/api/v1/traders/{addr}/trades(line 279),/api/v1/pairs/{addr}/limit-fills(line 297),/api/v1/pairs/{addr}/limit-placements(line 315),/api/v1/pairs/{addr}/limit-cancellations(line 333).Expected (per checklist)
Integration tests must cover negative, zero, huge, and valid values for every list/depth/limit route. A negative or zero
limitmust return a 400 or be treated as the minimum valid value (1), not silently return all rows or panic.Actual
Tests confirm the upper cap (huge values are clamped to the max and the response returns HTTP 200), but negative and zero inputs are not tested. The lower-bound behavior is unverified.
Evidence
indexer/tests/security.rsline 160:"/api/v1/pairs/{}/trades?limit=99999"-- no matching negative/zero test existsindexer/tests/security.rsline 179:"/api/v1/pairs/{}/candles?limit=99999"-- no matching negative/zero test existsindexer/tests/security.rsline 237:"/api/v1/oracle/history?limit=999999"-- no matching negative/zero test existsindexer/tests/security.rslines 279, 297, 315, 333: trader routes -- no matching negative/zero testsSuggested Fix
Add tests to
indexer/tests/security.rsfor each of the seven routes: sendlimit=-1and assert the response is 400; sendlimit=0and assert the response is 400 or returns an empty list (whichever matches the intended lower-bound contract). Document the intended behavior in a comment near each test.Verification Checklist
security.rshas a test forlimit=-1on all seven capped list routes asserting 400 or defined minimum behaviorsecurity.rshas a test forlimit=0on all seven capped list routes asserting 400 or defined minimum behaviorLabels
security,pre-launchCc: @PlasticDigits
mentioned in issue #381
mentioned in commit
536ff00cc1mentioned in merge request !959
mentioned in commit
55cf80af2eVerification — GitLab #431 (SEC-F05)
Result: PASS — negative and zero
limitcoverage is present on all seven capped list routes inindexer/tests/security.rs; no repo changes required.Checklist
limit=-1test on all seven capped list routes (400 or defined minimum)assert_negative_or_zero_limit_clamps_to_one(lines 342–371) sendslimit=-1; contract documented as clamp to 1 via.clamp(1, max)→ HTTP 200, ≤1 row. Seven route-specific tests at lines 373–461.limit=0test on all seven capped list routes (400 or defined minimum)limit=0with identical assertions.pair_trades_negative_and_zero_limit_clamp_to_one,pair_candles_negative_and_zero_limit_clamp_to_one,oracle_history_negative_and_zero_limit_clamp_to_one,trader_trades_negative_and_zero_limit_clamp_to_one,limit_fills_negative_and_zero_limit_clamp_to_one,limit_placements_negative_and_zero_limit_clamp_to_one,limit_cancellations_negative_and_zero_limit_clamp_to_one.trades_limit_capped_at_200, etc.) unchanged.Commands run
Notes
indexer/tests/api_limit_lower_bound.rsandindexer/tests/limit_clamp_guardrail.rs(static guard against.min(MAX)regressions).Closing as verified on
main.Independently verified the merged !959 on main. The lower-bound tests in security.rs cover all seven capped routes — trades, candles, oracle/history, trader trades, limit-fills, limit-placements, limit-cancellations — and each exercises BOTH limit=-1 and limit=0 via the assert_negative_or_zero_limit_clamps_to_one helper, asserting 200 + at most one row (the clamp-to-1 contract, which keeps a negative/zero value from reaching Postgres as a negative SQL LIMIT — the old #284 HTTP-500 path).
Ran the full security suite serial here: 35/35 (28 existing + the 7 new), 0 failed. clamp-to-1 is a sound lower-bound contract (the checklist allowed 400 or a defined minimum). Confirmed good — saw it was already closed.
mentioned in issue #337
mentioned in issue #705