Repository navigation
chore(pkg/cmd): medium/low findings from the 2026-07-28 full review [platform part] #357
Copy link
Copy link
Open
Labels
effort/lWeeksWeeksimpact/internalTeam-internal onlyTeam-internal onlypriority/p3Polish / idea / may never shipPolish / idea / may never shipseverity/lowMinor harmMinor harmtriagedItem has been triagedItem has been triagedtype/choreMaintenance / non-user-visibleMaintenance / non-user-visibleurgency/eventuallyNo deadlineNo deadline
Description
Split from LeanerCloud/cloud-commitments-cli#1613 (cross-component issue, monorepo split)
This issue carries the two findings whose files are in cmd/ subdirectories that belong to this repo post-split (cmd/cleanup-lambda, cmd/lambda), per the monorepo split's path mapping: root-level cmd/*.go stays with cloud-commitments-cli, while cmd/ subdirectories such as cleanup-lambda, lambda, server, rekey, and gen-permissions belong to this repo. Confirmed both files still exist here (2026-09-28).
MEDIUM
-
cmd/cleanup-lambdacan never delete a purchase execution, and has no status guard if it ever does- Where:
cmd/cleanup-lambda/main.go:63(dry-run count) and:91(delete), bothDELETE FROM purchase_executions WHERE expires_at < $1. - What:
PurchaseExecution.ExpiresAtis*time.Time(internal/config/types.go:888), and no non-test writer sets it (the only.ExpiresAtwriters found areApprovalTokenExpiresAt, API-key expiry, andPurchaseSuppression.ExpiresAt, a different struct). The column is therefore always NULL, andNULL < $1is NULL, so the predicate never matches. Separately, the delete has nostatusfilter, so ifExpiresAtis ever populated it would hard-deletepending/scheduled/runningrows alongside terminal ones. - Failure scenario (today): the scheduled cleanup Lambda runs on its cron, logs "Deleted 0 expired executions" forever, and reports
executionsDeleted: 0in its response. Operators reading that see a healthy job whilepurchase_executionsgrows without bound. Nothing alerts, because 0-deleted is indistinguishable from "nothing was due". - Failure scenario (once wired): an execution stuck in
runningpast its grace window is deleted. The per-recommendation idempotency token is derived from the execution ID (pkg/common/tokens.go:64-67,cloud-commitments-gorepo), so a re-drive after the row is gone necessarily uses a new execution ID and a new token. The AWS-side dedupe (ClientToken/IdempotencyTagKey) no longer recognises the earlier attempt, and the purchase can be made twice. - Fix direction: decide the intended retention rule and implement it explicitly, either by setting
ExpiresAtat execution creation or by changing the predicate to acompleted_at < $1 AND status IN (<terminal statuses>)form. Either way, add a terminal-status guard before any DELETE.
- Where:
LOW
-
RATE_LIMIT_DOMAINis interpolated into a SQLLIKEpattern without escaping wildcards- Where:
cmd/lambda/clear-rate-limit/main.go:40-42, with the value fromgetDomain()(:15-20). - What: the query is properly parameterised, so this is not injection, but
%and_inside the env var are LIKE metacharacters, so the deletion scope is wider than the variable name implies. - Failure scenario:
RATE_LIMIT_DOMAIN=%makes the patternEMAIL#%@%#ENDPOINT#forgot_password, which deletes the forgot-password rate-limit rows for every domain rather than one, removing brute-force protection across all tenants. A typo containing_, for exampleleaner_cloud.com, silently widens the match by one character position. - Fix direction: reject or escape
%and_ingetDomain(), or match on an exact suffix column instead of a constructed LIKE pattern.
- Where:
Acceptance criteria
- Each checklist item above is fixed with a regression test covering the described failure scenario.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
effort/lWeeksWeeksimpact/internalTeam-internal onlyTeam-internal onlypriority/p3Polish / idea / may never shipPolish / idea / may never shipseverity/lowMinor harmMinor harmtriagedItem has been triagedItem has been triagedtype/choreMaintenance / non-user-visibleMaintenance / non-user-visibleurgency/eventuallyNo deadlineNo deadline
Activity
IAmJSD commentedon Oct 23, 2026
Claiming: working on this
fix(clear-rate-limit): match RATE_LIMIT_DOMAIN literally in the LIKE …
IAmJSD commentedon Oct 27, 2026
Status update (2026-10-27, checked against main at 7b86e38): Waiting on an owner decision.
The LIKE-wildcard finding was fixed in #1272, and cmd/cleanup-lambda gained its terminal-status guard in #1173. Finding 1b is still open: nothing writes purchase_executions.expires_at, so the cleanup Lambda can never delete anything.
Left / blocked on: Owner question: should cmd/cleanup-lambda be kept and made to work, or removed? Recommended answer: delete cmd/cleanup-lambda and its unused deploy modules (option b). The in-app scheduled cleanup task already calls CleanupOldExecutions, and once #120 item 9 lands that function has a live-status guard. Option a (have the Lambda call the shared CleanupOldExecutions) duplicates it, and option c (set a TTL at creation) is not recommended.