fix: harden API key handling and bound agent task claims - #235
gasparottog80-hash wants to merge 7 commits into
Conversation
|
@gasparottog80-hash is attempting to deploy a commit to the Comp AI - PoC Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
1 issue found across 25 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/logging/request-logger.middleware.ts">
<violation number="1" location="apps/api/src/logging/request-logger.middleware.ts:60">
P3: The hardening is untested: `logging.spec.ts` exercises only request-id behavior and never asserts the logged payload, so nothing guards the new query-string stripping (`request.path` vs `request.originalUrl`) or the `apiKeyPresented` field. Add a test that drives `logCompleted` output (capture the logger as in the existing spec) and asserts the payload's `path` excludes the query string and `apiKeyPresented` is true/false with/without `x-api-key`.</violation>
</file>
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
| durationMs: Number(durationMs.toFixed(1)), | ||
| ip: request.ip, | ||
| userAgent: request.get("user-agent"), | ||
| apiKeyPresented: Boolean(request.get(API_KEY_HEADER)), |
There was a problem hiding this comment.
P3: The hardening is untested: logging.spec.ts exercises only request-id behavior and never asserts the logged payload, so nothing guards the new query-string stripping (request.path vs request.originalUrl) or the apiKeyPresented field. Add a test that drives logCompleted output (capture the logger as in the existing spec) and asserts the payload's path excludes the query string and apiKeyPresented is true/false with/without x-api-key.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/logging/request-logger.middleware.ts, line 60:
<comment>The hardening is untested: `logging.spec.ts` exercises only request-id behavior and never asserts the logged payload, so nothing guards the new query-string stripping (`request.path` vs `request.originalUrl`) or the `apiKeyPresented` field. Add a test that drives `logCompleted` output (capture the logger as in the existing spec) and asserts the payload's `path` excludes the query string and `apiKeyPresented` is true/false with/without `x-api-key`.</comment>
<file context>
@@ -56,6 +57,7 @@ export class RequestLoggerMiddleware implements NestMiddleware {
durationMs: Number(durationMs.toFixed(1)),
ip: request.ip,
userAgent: request.get("user-agent"),
+ apiKeyPresented: Boolean(request.get(API_KEY_HEADER)),
};
</file context>
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
Validation complete for current head
The PR is currently mergeable. Vercel deployment authorization was intentionally not granted because it requires Comp AI - PoC team permission. Ready for maintainer merge/review. |
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
|
Hi maintainers — the current PR head is Validation completed successfully:
The remaining Vercel deployment authorization requires a member of the Comp AI - PoC team; I do not have that permission and have not attempted to bypass it. Could a maintainer please review and merge PR #235 when appropriate, and authorize the Vercel deployments if they are required by the project workflow? |
Summary
Why
PostgreSQL could choose a Nested Loop plan that re-evaluated limited
FOR UPDATE SKIP LOCKED subqueries, allowing claimDue() and
retireExhausted() to affect more rows than their requested limit.
The affected selections now use MATERIALIZED CTEs so the bounded set of
rows is evaluated once per statement.
Validation
bun run check-types— PASSbun run lint— PASSbun run lint:slop— PASSbun run test— PASSTest totals:
Security
Note
Median task ID was not added because no configured Median binding or
recoverable task ID exists in this checkout; no ID was fabricated.
Summary by cubic
Fixes agent task claim/retire operations exceeding their row limit and hardens API key handling so rate-limit errors surface correctly.
Agent task limits
claimDue()andretireExhausted()now build a MATERIALIZED CTE so the bound of selected rows is evaluated once, preventing planner-dependent over-claiming and over-retirement.retireExhausted()now accepts an optionalkindsfilter to act on only targeted task kinds.TEST_RUN_IDsuffix.API key handling
Retry-Afterinstead of being treated as unauthorized; production rate limiting remains disabled.node:crypto, andAGENT_BRIDGE_SECRETmust now be at least 32 characters; empty values are treated as unset, and absent secrets remain optional.request.pathto avoid exposing query strings, records whether an API key was presented, and logs once per request onfinishat a status-dependent level.@better-auth/api-keyas a dev dependency for test coverage.Written for commit 79f443c. Summary will update on new commits.