fix: standardize rate limiter TTL to milliseconds and parameterize migration SQL#1896
fix: standardize rate limiter TTL to milliseconds and parameterize migration SQL#1896LautaroPetaccio wants to merge 2 commits into
Conversation
decentraland-bot
left a comment
There was a problem hiding this comment.
Code Review — PR #1896: Rate Limiter TTL Standardization & Migration SQL Parameterization
Verdict: ✅ APPROVE
Important fixes for both correctness and security.
Key Findings
What's fixed (all correct):
-
Rate limiter TTL unit mismatch:
DEPLOYMENTS_DEFAULT_RATE_LIMIT_TTLwas divided by 1000 (stored in seconds) while all other TTL configs were in milliseconds. The fallback incomponents.tsusedms('1m')(60000 ms), creating inconsistency. Fix removes the/1000and addstoSeconds()at the consumption site. All paths now consistently produce seconds for NodeCache. Verified correct. -
SQL injection in migrations/Helper.ts: All string interpolation (
'${entityType}',${row.id}) replaced with parameterized queries using$1,$2placeholders.deleteFailedDeploymentschanged from syncpgm.sql()to asyncpgm.db.query()with params. Both callers updated withawait. Correct and important for security hygiene.
P3 — Minor observations (not blocking):
- The parameterized queries use
$1,$2for values (entity_id, entity_type, etc.) which is correct for DML. All the SQL in Helper.ts is DML (DELETE, INSERT, SELECT), not DDL, so standard parameterization works correctly. - Consider adding a unit suffix to the TTL variable name (e.g.,
defaultTtlMs) to prevent future regressions.
Tests: New deployRateLimiterComponent.spec.ts with 4 tests verifying correct TTL behavior with millisecond values. Good coverage of the fix.
CI: Tests still in progress (test-content running), validations + test-lambdas passing ✅
Requested by Lautaro Petaccio via Slack
Summary
Rate limiter TTL unit mismatch:
DEPLOYMENTS_DEFAULT_RATE_LIMIT_TTLwas stored in seconds (divided by 1000 inEnvironment.ts) while all other TTL configs (entitiesConfigTtl,entitiesConfigUnchangedTtl) were stored in milliseconds. The fallback incomponents.tsusedms('1m')(60000 ms), creating a unit mismatch with the configured value (60 seconds).The fix removes the
/1000conversion inEnvironment.tsso the config is stored in milliseconds like all other TTL fields, and adds atoSeconds()call indeployRateLimiterComponent.tswhere thedefaultTtlfallback is used, so NodeCache receives the correct seconds value.Migration SQL injection:
migrations/Helper.tsused string interpolation for all SQL queries ('${entityType}',${row.id}, etc.). While the inputs are developer-controlled migration data (not user input), this is unsafe practice. Replaced all interpolation with parameterized queries using$1,$2placeholders. ChangeddeleteFailedDeploymentsfrom syncpgm.sql()to asyncpgm.db.query()with params, and updated the two callers to addawait.Test plan
defaultTtlcd content && npx jest test/unit/ports/deployRateLimiterComponent.spec.ts --no-coverage