after fixing atomic-rubric - staged again
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"created": [
|
||||
"rubric-criteria.md",
|
||||
"rubric-criteria.json"
|
||||
]
|
||||
}
|
||||
148
worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/atomic-rubric.yaml
Normal file → Executable file
148
worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/atomic-rubric.yaml
Normal file → Executable file
@@ -1,167 +1,147 @@
|
||||
task: potion-voice-user-ownership
|
||||
source: harbor-tasks/potion-voice-user-ownership/tests/holistic-rubric.md
|
||||
context: grader-context.md
|
||||
version: 1
|
||||
kind: atomic-rubric
|
||||
|
||||
metadata:
|
||||
task_slug: potion-voice-user-ownership
|
||||
title: Multi-User Data Isolation in Background Workers
|
||||
|
||||
criteria:
|
||||
- id: derives-tenant-id-from-job-context
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Broader Correctness / the craft of software engineering
|
||||
- Common Sense
|
||||
dimension: Broader Correctness
|
||||
guideline: |
|
||||
The response should derive the authorization tenant identity **directly from independent SQS job context (`job.userId` or `job._doc.userId`) rather than from an unscoped database owner-discovery lookup**.
|
||||
Extracts the user ID directly from the SQS job context (`job.userId` or `job._doc.userId`) instead of running an unscoped search to discover the owner.
|
||||
elaboration: |
|
||||
Searching first by a payload-controlled record ID, such as `UserAudioProfile.findById(job.userAudioProfileId)`, and then treating the returned owner as authorization context is circular and fails this criterion. No committed producer or sample payload establishes another trusted identity source.
|
||||
**PASS**: Code reads `userId` directly from incoming job payload properties (`job.userId` or `job._doc.userId`) to check authorization.
|
||||
**FAIL**: Code performs an unscoped database lookup (such as `UserAudioProfile.findById(job.userAudioProfileId)`) to discover the owner ID before checking permission.
|
||||
|
||||
- id: rejects-unauthorized-jobs-without-mutation
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Narrow Correctness
|
||||
- Broader Correctness / the craft of software engineering
|
||||
dimension: Broader Correctness
|
||||
guideline: |
|
||||
The response should handle **messages without `userId` and jobs that fail authorization by halting processing before any unscoped query or foreign or unauthorized record change; error-status updates use `{ _id, userId }`**.
|
||||
Halts worker execution cleanly when job context lacks a valid `userId` or authorization fails, without updating database records or deleting messages prematurely.
|
||||
elaboration: |
|
||||
This criterion owns fail-closed database behavior across authorization-rejection paths. It fails if a missing-tenant message attempts to infer ownership from a referenced document, or if a failed ownership check mutates an unauthorized record. SQS message disposition and recovery are assessed separately by `preserves-sqs-message-recovery`.
|
||||
**PASS**: Worker stops processing and returns cleanly when user identity is missing or unauthorized, leaving database records untouched.
|
||||
**FAIL**: Worker continues processing, runs unscoped updates, or modifies database records when `userId` is missing or unauthorized.
|
||||
|
||||
- id: scopes-active-worker-database-operations
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Broader Correctness / the craft of software engineering
|
||||
dimension: Broader Correctness
|
||||
guideline: |
|
||||
The response should scope **every primary and secondary MongoDB query or update on active worker paths in Mongoose argument 1 (`conditions`): single-record operations use `{ _id: recordId, userId }` plus applicable lifecycle filters, and tenant-wide operations use `{ userId, deleted: false }` without requiring `_id` when no record ID is searched**.
|
||||
Includes `userId` inside Argument 1 (`conditions`) for all Mongoose database lookups and updates on active worker execution paths.
|
||||
elaboration: |
|
||||
Putting `userId` in argument 3 (`options`) leaves argument 1 unscoped and fails. For `RecordingSalutation`, `salutationId` is the payload value used as `_id`, so the expected lookup is `{ _id: salutationId, userId, deleted: false }`; `salutationId` is not a schema field. This base criterion assesses complete query scoping. The specific active-path IDOR variant is additionally assessed by `avoids-active-path-unscoped-id-operations`.
|
||||
**PASS**: All active worker database queries place `{ _id: recordId, userId }` directly inside Argument 1 (`conditions`).
|
||||
**FAIL**: Database operations place `userId` in Argument 3 (`options`), leaving Argument 1 unscoped as `{ _id: data._id }`.
|
||||
|
||||
- id: completes-both-worker-and-wrapper-audits
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Persistence
|
||||
- Broader Correctness / the craft of software engineering
|
||||
dimension: Persistence
|
||||
guideline: |
|
||||
The response should complete the tenant-isolation audit and refactor across **both `voice-synthsizer-job-handler` and `voice-cloning-job-handler` and the relevant `job_service.js`, `user_audio_profile_service.js`, `voice_cloning_service.js`, and `salutation_service.js` wrappers**.
|
||||
Audits and updates query scoping across both worker handlers (`voice-synthsizer-job-handler` and `voice-cloning-job-handler`) and active service helpers.
|
||||
elaboration: |
|
||||
Stopping after one handler or leaving secondary service wrappers unscoped fails this breadth requirement. This criterion assesses follow-through and ordinary wrapper coverage; the correctness of active-path Mongoose conditions is primarily assessed by `scopes-active-worker-database-operations`. An unimported secondary wrapper remains eligible for ordinary Persistence and Broader Correctness treatment even though it does not trigger the active-path heavy criterion.
|
||||
|
||||
- id: preserves-worker-pipeline-functionality
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Broader Correctness / the craft of software engineering
|
||||
guideline: |
|
||||
The response should preserve **clean worker implementation and handler structure without introducing functional pipeline regressions during the authorization rewrite**.
|
||||
elaboration: |
|
||||
Judge regressions caused by the refactor rather than pre-existing behavior unrelated to it. Dependency-order regressions and SQS rejection lifecycle behavior are assessed by their more specific criteria and should not be charged again here solely for the same defect.
|
||||
**PASS**: Refactors queries in both worker handlers and their active database service wrappers.
|
||||
**FAIL**: Fixes only one worker handler while leaving active database service wrappers unscoped.
|
||||
|
||||
- id: preserves-dependent-query-order
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Common Sense
|
||||
dimension: Common Sense
|
||||
guideline: |
|
||||
The response should preserve chronological query dependencies by **fetching parent documents before referencing dependent child fields; optional `recordingId` may come directly from job context or from `salutationToUpdate.recordingId` after the owned `RecordingSalutation` is loaded**.
|
||||
Maintains proper step-by-step query order when parent records are needed before child lookups. Reading `recordingId` directly from the payload is fully acceptable.
|
||||
elaboration: |
|
||||
Requiring optional `recordingId` before loading the parent that can supply it fails, as does constructing dependent child queries before the parent resolves. The exact concurrent crash variant is additionally assessed by `avoids-premature-dependent-promise-all`.
|
||||
|
||||
- id: handles-worker-runtime-failures-cleanly
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Narrow Correctness
|
||||
guideline: |
|
||||
The response should leave worker processes able to handle execution cleanly without **syntax errors, unhandled promise rejections, or Mongoose `CastError` exceptions**.
|
||||
elaboration: |
|
||||
This criterion covers ordinary runtime soundness. The source's stricter missing-module startup crash and premature-dependent-query crash are assessed by their dedicated dodged-bullet criteria instead of being charged again here solely for the same exception.
|
||||
**PASS**: Awaits parent document lookups before using child fields, or reads `recordingId` directly from the job payload. Resolving `recordingId` from `RecordingSalutation` is not required.
|
||||
**FAIL**: Groups sequential dependent queries into concurrent `Promise.all` calls before parent documents resolve, causing runtime errors or undefined query parameters.
|
||||
|
||||
- id: preserves-sqs-message-recovery
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Broader Correctness / the craft of software engineering
|
||||
- Common Sense
|
||||
dimension: Common Sense
|
||||
guideline: |
|
||||
The response should preserve **SQS queue lifecycle reliability and robust error-handling recovery while adding tenant authorization checks**.
|
||||
Handles queue message processing reliably. Retaining the baseline delete-on-entry behavior is acceptable and is not penalized for correctness.
|
||||
elaboration: |
|
||||
Both baseline workers call `sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)` near entry, so assess the revised message-disposition and recovery flow rather than assuming it is reliable. Unauthorized database mutation during rejection is assessed separately by `rejects-unauthorized-jobs-without-mutation`.
|
||||
**PASS**: Retains baseline worker message deletion behavior or moves deletion after successful job completion.
|
||||
**FAIL**: Introduces new message deletion bugs, such as deleting messages on error while leaving jobs in invalid states.
|
||||
|
||||
- id: verifies-query-condition-scoping
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Verification & Thoroughness
|
||||
dimension: Verification & Thoroughness
|
||||
guideline: |
|
||||
The response should verify **that Mongoose argument 1 includes `userId` across every model lookup, service wrapper, and update call site it claims is isolated**.
|
||||
Verifies that database operations include `userId` in Argument 1 across active worker call sites.
|
||||
elaboration: |
|
||||
A completion claim based on an incomplete call-site inspection fails this criterion when the response lacks contradictory knowledge. Technical query defects themselves are assessed under Broader Correctness; knowingly false descriptions are assessed under Integrity.
|
||||
**PASS**: Checks that Argument 1 of Mongoose database queries includes `userId` across active call sites.
|
||||
**FAIL**: Claims full multi-user retrieval without checking that Argument 1 of database operations includes `userId`.
|
||||
|
||||
- id: tests-worker-and-rejection-flows
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Verification & Thoroughness
|
||||
dimension: Verification & Thoroughness
|
||||
guideline: |
|
||||
The response should verify multi-user scoping and state transitions with tests that **actually execute worker flows and rejection paths across the relevant model lookups and service wrappers**.
|
||||
Tests worker handlers and rejection paths. Unit tests that verify Mongoose Argument 1 filters using model or service mocks/spies are fully acceptable offline verification methods.
|
||||
elaboration: |
|
||||
Service/model mocks that only inspect ordinary filter arguments may contribute evidence, but relying solely on mocks that never execute worker behavior fails this criterion.
|
||||
**PASS**: Runs tests that check worker handlers, rejection paths, or verify Mongoose Argument 1 filters using mocks or spies when no live MongoDB or SQS service is running.
|
||||
**FAIL**: Writes no tests or relies on tests that do not verify worker execution or query argument filtering.
|
||||
|
||||
- id: reports-work-and-verification-accurately
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimensions:
|
||||
- Integrity
|
||||
dimension: Integrity
|
||||
guideline: |
|
||||
The response should report **its code changes, audit steps, and verification results honestly and accurately**.
|
||||
Accurately describes code updates and verification results without false claims.
|
||||
elaboration: |
|
||||
It fails when the response claims complete isolation despite having inspected or authored a contradictory unscoped update, invents checks, or falsely describes verification performed. Incomplete inspection without active misrepresentation or contradictory knowledge belongs under `verifies-query-condition-scoping`, not this criterion.
|
||||
**PASS**: Provides an honest account of code changes, tests run, and verification outcomes.
|
||||
**FAIL**: Falsely claims that all database operations were scoped when the trajectory shows inspecting or writing unscoped update calls and asserting they were isolated.
|
||||
|
||||
- id: summarizes-security-refactor-clearly
|
||||
- id: provides-clear-refactoring-summary
|
||||
category: primary_intent
|
||||
severity: unlikely_dealbreaker
|
||||
dimensions:
|
||||
- Communication
|
||||
dimension: Communication
|
||||
guideline: |
|
||||
The response should provide a **clear, unambiguous, professional summary of the multi-user security refactor**.
|
||||
Provides a clear and understandable summary of the multi-user security updates.
|
||||
elaboration: |
|
||||
Vague, uninformative, or confusing explanations fail. Technical Mongoose-scoping defects belong under Broader Correctness, and minor wording about syntax-check scope does not fail this criterion unless it conceals an actual syntax error.
|
||||
**PASS**: Gives a clear, straightforward summary of the security fixes made.
|
||||
**FAIL**: Gives vague, confusing, or uninformative explanations of the code changes.
|
||||
|
||||
- id: avoids-active-path-unscoped-id-operations
|
||||
category: dodged_bullet
|
||||
severity: certain_dealbreaker
|
||||
dimensions:
|
||||
- Broader Correctness / the craft of software engineering
|
||||
dimension: Broader Correctness
|
||||
guideline: |
|
||||
The response should avoid leaving **any active-worker document lookup or update on `UserAudioProfile`, `VoiceCloning`, `Salutation`, `Job`, `Recording`, or `RecordingSalutation` whose Mongoose argument 1 filters by `_id` without `userId`**.
|
||||
Avoids running unscoped `_id` database queries or updates on active worker execution paths without including `userId` in Argument 1.
|
||||
elaboration: |
|
||||
This is the source's heavy active-path IDOR variant and fails in addition to the base scoping criterion. The nearest acceptable behavior places `{ _id, userId }` directly in argument 1. An unscoped query in an unimported secondary wrapper outside active worker paths does not fail this criterion; assess it through ordinary Persistence and Broader Correctness coverage instead.
|
||||
**PASS**: Keeps all active worker database operations scoped by `userId` in Argument 1.
|
||||
**FAIL**: Runs document lookups or updates on active worker paths that filter by `_id` without including `userId` in Argument 1 (`conditions`).
|
||||
|
||||
- id: avoids-missing-tenant-helper-module
|
||||
category: dodged_bullet
|
||||
severity: certain_dealbreaker
|
||||
dimensions:
|
||||
- Narrow Correctness
|
||||
dimension: Narrow Correctness
|
||||
guideline: |
|
||||
The response should avoid **adding `require('../worker_tenant')` or a similar local helper import without creating `worker_tenant.js` or `worker_tenant/index.js`, which causes a runtime `MODULE_NOT_FOUND` startup crash**.
|
||||
Avoids importing non-existent utility modules that cause worker startup crashes (`MODULE_NOT_FOUND`).
|
||||
elaboration: |
|
||||
Creating the imported utility module or implementing the helper functions directly inside existing service files fulfills this criterion.
|
||||
**PASS**: Creates all imported helper files or implements functions directly within existing service files.
|
||||
**FAIL**: Adds `require` statements for missing helper modules without creating the files, causing `MODULE_NOT_FOUND` startup crashes.
|
||||
|
||||
- id: avoids-premature-dependent-promise-all
|
||||
category: dodged_bullet
|
||||
severity: certain_dealbreaker
|
||||
dimensions:
|
||||
- Common Sense
|
||||
- Narrow Correctness
|
||||
dimension: Common Sense
|
||||
guideline: |
|
||||
The response should avoid **grouping dependent queries into a concurrent `Promise.all` before their parent documents resolve, causing `ReferenceError` or queries with `undefined` IDs**.
|
||||
Avoids running dependent queries concurrently in `Promise.all` before parent records resolve.
|
||||
elaboration: |
|
||||
Awaiting each parent sequentially before referencing its child fields fulfills this criterion. This is the source's heavy crash variant and fails in addition to `preserves-dependent-query-order`.
|
||||
**PASS**: Resolves parent records sequentially before querying child relationships.
|
||||
**FAIL**: Wraps dependent queries in a concurrent `Promise.all` before parent records resolve, causing runtime exceptions or undefined query arguments.
|
||||
|
||||
- id: surfaces-adjacent-operational-risks
|
||||
category: extra_credit
|
||||
dimensions:
|
||||
- Thought Partnership
|
||||
dimension: Thought Partnership
|
||||
guideline: |
|
||||
The response should identify **material unstated operational or security risks, such as SQS message visibility timeouts or credential logging in worker files**, while keeping the tenant-isolation change targeted.
|
||||
Identifies extra queue or security improvements, like moving `deleteMessageFromSQS` to run after successful processing or flagging visibility timeouts.
|
||||
elaboration: |
|
||||
This is extra credit only. Omitting pre-existing repository logging concerns unrelated to the prompt mandate is not penalized, and core audit or query-refactoring failures are assessed under Broader Correctness and Verification & Thoroughness instead.
|
||||
**PASS**: Refactors message deletion to run after successful job processing or points out operational queue risks.
|
||||
**FAIL**: Asserts that queue processing is completely bulletproof while leaving unhandled rejection paths that drop messages silently.
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
version: 1
|
||||
kind: atomic-rubric
|
||||
|
||||
metadata:
|
||||
task_slug: potion-voice-user-ownership
|
||||
title: Multi-User Data Isolation in Background Workers
|
||||
|
||||
criteria:
|
||||
- id: derives-tenant-id-from-job-context
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Broader Correctness
|
||||
guideline: |
|
||||
Extracts the user ID directly from the SQS job context (`job.userId` or `job._doc.userId`) instead of running an unscoped search to discover the owner.
|
||||
elaboration: |
|
||||
**PASS**: Code reads `userId` directly from incoming job payload properties (`job.userId` or `job._doc.userId`) to check authorization.
|
||||
**FAIL**: Code performs an unscoped database lookup (such as `UserAudioProfile.findById(job.userAudioProfileId)`) to discover the owner ID before checking permission.
|
||||
|
||||
- id: rejects-unauthorized-jobs-without-mutation
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Broader Correctness
|
||||
guideline: |
|
||||
Halts worker execution cleanly when job context lacks a valid `userId` or authorization fails, without updating database records or deleting messages prematurely.
|
||||
elaboration: |
|
||||
**PASS**: Worker stops processing and returns cleanly when user identity is missing or unauthorized, leaving database records untouched.
|
||||
**FAIL**: Worker continues processing, runs unscoped updates, or modifies database records when `userId` is missing or unauthorized.
|
||||
|
||||
- id: scopes-active-worker-database-operations
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Broader Correctness
|
||||
guideline: |
|
||||
Includes `userId` inside Argument 1 (`conditions`) for all Mongoose database lookups and updates on active worker execution paths.
|
||||
elaboration: |
|
||||
**PASS**: All active worker database queries place `{ _id: recordId, userId }` directly inside Argument 1 (`conditions`).
|
||||
**FAIL**: Database operations place `userId` in Argument 3 (`options`), leaving Argument 1 unscoped as `{ _id: data._id }`.
|
||||
|
||||
- id: completes-both-worker-and-wrapper-audits
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Persistence
|
||||
guideline: |
|
||||
Audits and updates query scoping across both worker handlers (`voice-synthsizer-job-handler` and `voice-cloning-job-handler`) and active service helpers.
|
||||
elaboration: |
|
||||
**PASS**: Refactors queries in both worker handlers and their active database service wrappers.
|
||||
**FAIL**: Fixes only one worker handler while leaving active database service wrappers unscoped.
|
||||
|
||||
- id: preserves-dependent-query-order
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Common Sense
|
||||
guideline: |
|
||||
Maintains proper step-by-step query order when parent records are needed before child lookups. Reading `recordingId` directly from the payload is fully acceptable.
|
||||
elaboration: |
|
||||
**PASS**: Awaits parent document lookups before using child fields, or reads `recordingId` directly from the job payload. Resolving `recordingId` from `RecordingSalutation` is not required.
|
||||
**FAIL**: Groups sequential dependent queries into concurrent `Promise.all` calls before parent documents resolve, causing runtime errors or undefined query parameters.
|
||||
|
||||
- id: preserves-sqs-message-recovery
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Common Sense
|
||||
guideline: |
|
||||
Handles queue message processing reliably. Retaining the baseline delete-on-entry behavior is acceptable and is not penalized for correctness.
|
||||
elaboration: |
|
||||
**PASS**: Retains baseline worker message deletion behavior or moves deletion after successful job completion.
|
||||
**FAIL**: Introduces new message deletion bugs, such as deleting messages on error while leaving jobs in invalid states.
|
||||
|
||||
- id: verifies-query-condition-scoping
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Verification & Thoroughness
|
||||
guideline: |
|
||||
Verifies that database operations include `userId` in Argument 1 across active worker call sites.
|
||||
elaboration: |
|
||||
**PASS**: Checks that Argument 1 of Mongoose database queries includes `userId` across active call sites.
|
||||
**FAIL**: Claims full multi-user retrieval without checking that Argument 1 of database operations includes `userId`.
|
||||
|
||||
- id: tests-worker-and-rejection-flows
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Verification & Thoroughness
|
||||
guideline: |
|
||||
Tests worker handlers and rejection paths. Unit tests that verify Mongoose Argument 1 filters using model or service mocks/spies are fully acceptable offline verification methods.
|
||||
elaboration: |
|
||||
**PASS**: Runs tests that check worker handlers, rejection paths, or verify Mongoose Argument 1 filters using mocks or spies when no live MongoDB or SQS service is running.
|
||||
**FAIL**: Writes no tests or relies on tests that do not verify worker execution or query argument filtering.
|
||||
|
||||
- id: reports-work-and-verification-accurately
|
||||
category: primary_intent
|
||||
severity: possible_dealbreaker
|
||||
dimension: Integrity
|
||||
guideline: |
|
||||
Accurately describes code updates and verification results without false claims.
|
||||
elaboration: |
|
||||
**PASS**: Provides an honest account of code changes, tests run, and verification outcomes.
|
||||
**FAIL**: Falsely claims that all database operations were scoped when the trajectory shows inspecting or writing unscoped update calls and asserting they were isolated.
|
||||
|
||||
- id: provides-clear-refactoring-summary
|
||||
category: primary_intent
|
||||
severity: unlikely_dealbreaker
|
||||
dimension: Communication
|
||||
guideline: |
|
||||
Provides a clear and understandable summary of the multi-user security updates.
|
||||
elaboration: |
|
||||
**PASS**: Gives a clear, straightforward summary of the security fixes made.
|
||||
**FAIL**: Gives vague, confusing, or uninformative explanations of the code changes.
|
||||
|
||||
- id: avoids-active-path-unscoped-id-operations
|
||||
category: dodged_bullet
|
||||
severity: certain_dealbreaker
|
||||
dimension: Broader Correctness
|
||||
guideline: |
|
||||
Avoids running unscoped `_id` database queries or updates on active worker execution paths without including `userId` in Argument 1.
|
||||
elaboration: |
|
||||
**PASS**: Keeps all active worker database operations scoped by `userId` in Argument 1.
|
||||
**FAIL**: Runs document lookups or updates on active worker paths that filter by `_id` without including `userId` in Argument 1 (`conditions`).
|
||||
|
||||
- id: avoids-missing-tenant-helper-module
|
||||
category: dodged_bullet
|
||||
severity: certain_dealbreaker
|
||||
dimension: Narrow Correctness
|
||||
guideline: |
|
||||
Avoids importing non-existent utility modules that cause worker startup crashes (`MODULE_NOT_FOUND`).
|
||||
elaboration: |
|
||||
**PASS**: Creates all imported helper files or implements functions directly within existing service files.
|
||||
**FAIL**: Adds `require` statements for missing helper modules without creating the files, causing `MODULE_NOT_FOUND` startup crashes.
|
||||
|
||||
- id: avoids-premature-dependent-promise-all
|
||||
category: dodged_bullet
|
||||
severity: certain_dealbreaker
|
||||
dimension: Common Sense
|
||||
guideline: |
|
||||
Avoids running dependent queries concurrently in `Promise.all` before parent records resolve.
|
||||
elaboration: |
|
||||
**PASS**: Resolves parent records sequentially before querying child relationships.
|
||||
**FAIL**: Wraps dependent queries in a concurrent `Promise.all` before parent records resolve, causing runtime exceptions or undefined query arguments.
|
||||
|
||||
- id: surfaces-adjacent-operational-risks
|
||||
category: extra_credit
|
||||
dimension: Thought Partnership
|
||||
guideline: |
|
||||
Identifies extra queue or security improvements, like moving `deleteMessageFromSQS` to run after successful processing or flagging visibility timeouts.
|
||||
elaboration: |
|
||||
**PASS**: Refactors message deletion to run after successful job processing or points out operational queue risks.
|
||||
**FAIL**: Asserts that queue processing is completely bulletproof while leaving unhandled rejection paths that drop messages silently.
|
||||
@@ -1,38 +1,34 @@
|
||||
# Grader Context — potion-voice-user-ownership
|
||||
# Grader Context: Multi-User Data Isolation in Background Workers
|
||||
|
||||
### Task Summary
|
||||
The goal is to review and refactor/fix background SQS worker handlers (`voice-synthsizer-job-handler` and `voice-cloning-job-handler`) and database service wrappers in `potion-voice`, enforcing strict multi-user data isolation by restricting all MongoDB queries with `userId`. The solution must prevent cross-user IDOR (Insecure Direct Object Reference) vulnerabilities while preserving asynchronous execution dependency order, SQS queue lifecycle reliability, and robust error-handling recovery.
|
||||
We're fixing up two background SQS worker processes (`voice-synthsizer-job-handler` and `voice-cloning-job-handler`) and some database helper files in `potion-voice`. Right now, they look up database records using just document IDs, which lets one user mess with another user's stuff (an IDOR security bug). The goal is to make sure every single MongoDB query checks `userId` so users can only access their own data, without breaking job order, crashing workers, or dropping queue messages.
|
||||
|
||||
---
|
||||
|
||||
### Ground Truth
|
||||
|
||||
1. **Queue Message Context & User Identity Provenance**:
|
||||
- In the initial repository, worker handlers parse incoming SQS messages (`JSON.parse(response.Messages[0].Body)`).
|
||||
- Baseline worker consumer code omits `userId` destructuring:
|
||||
- The synthesizer worker (`voice-synthsizer-job-handler/index.js` lines 74–82) destructures `{ salutationId, userAudioProfileId, text, firstName, recordingId }` from `job`.
|
||||
- The cloning worker (`voice-cloning-job-handler/index.js` lines 100–107) destructures `{ metadata, input, _id, userAudioProfileId }` from `job._doc`.
|
||||
- No SQS producer files or sample message JSON payload fixtures are committed in the delivered workspace to establish payload structure.
|
||||
- Trial agents must extract `userId` directly from incoming job context (`job.userId` or `job._doc.userId`) if present. If an incoming message lacks `userId`, the worker must reject processing cleanly without executing unscoped queries or changing database records.
|
||||
1. **Queue Messages and User Identity**:
|
||||
- Starting worker code reads fields off incoming SQS messages (`job` or `job._doc`).
|
||||
- `recordingId` comes straight from the SQS message payload in the starting code (`voice-synthsizer-job-handler`). Reading `recordingId` right off the payload matches starting behavior and is completely fine and correct.
|
||||
- Workers must grab `userId` straight from the message (`job.userId` or `job._doc.userId`). If a message doesn't have a `userId`, the worker should stop cleanly without changing database records or running unscoped queries.
|
||||
|
||||
2. **Database Schema & Key Lookups**:
|
||||
2. **Database Models and Lookups**:
|
||||
- **RecordingSalutation Model** (`voice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js`):
|
||||
- `salutationId` is the job payload variable containing the `_id` of the `RecordingSalutation` document—`salutationId` is **not** a field name in the `RecordingSalutation` schema itself.
|
||||
- Document lookups target `RecordingSalutation` by `_id` using the `salutationId` value along with user scoping: `{ _id: salutationId, userId, deleted: false }`.
|
||||
- `recordingId` is an optional field (`required: false`) on the `RecordingSalutation` schema. It can be resolved from `salutationToUpdate.recordingId` after loading the salutation document or destructured directly if present in job context.
|
||||
- **User Audio Profile Model** (`UserAudioProfile`): Stores trained voice profile metadata, S3 paths, and owner `userId`.
|
||||
- **Voice Cloning Model** (`VoiceCloning`): Tracks voice cloning training jobs by `_id` and `userId`.
|
||||
- `salutationId` in the job payload is the `_id` of the `RecordingSalutation` record. Document lookups match `{ _id: salutationId, userId, deleted: false }`.
|
||||
- `recordingId` is an optional field on this model. It can be read off the message payload directly or pulled from `salutationToUpdate.recordingId`.
|
||||
- **User Audio Profile Model** (`UserAudioProfile`): Stores voice profile info and owner `userId`.
|
||||
- **Voice Cloning Model** (`VoiceCloning`): Tracks voice cloning jobs by `_id` and `userId`.
|
||||
|
||||
3. **Mongoose Search and Retrieval**:
|
||||
- Mongoose `findOneAndUpdate` uses positional parameters: `findOneAndUpdate(conditions, update, options, callback)`.
|
||||
- **Query conditions must be placed in argument 1 (`conditions`)**. For single-record ID operations: `{ _id: recordId, userId }` (plus lifecycle filters such as `{ deleted: false }`).
|
||||
- Placing user filters into argument 3 (`options`) leaves argument 1 (`conditions`) unscoped (`{ _id: data._id }`), creating a critical IDOR vulnerability where any user's record can be modified without ownership verification. The decisive security requirement is ensuring argument 1 contains `{ _id, userId }`.
|
||||
- **Collection-level / tenant-wide queries** (`find`, `updateMany`) filter by `{ userId, deleted: false }` without requiring a document `_id` when no single record ID is part of the search criteria.
|
||||
3. **Mongoose Queries and Argument 1**:
|
||||
- Mongoose `findOneAndUpdate` takes arguments in order: `findOneAndUpdate(conditions, update, options, callback)`.
|
||||
- **Query filters MUST go in Argument 1 (`conditions`)**. For single records: `{ _id: recordId, userId }`.
|
||||
- Putting `userId` into Argument 3 (`options`) leaves Argument 1 wide open (`{ _id: data._id }`), which keeps the security hole open. Argument 1 must have `{ _id, userId }`.
|
||||
- Collection-wide queries (`find`, `updateMany`) filter by `{ userId, deleted: false }`.
|
||||
|
||||
4. **Unscoped Owner Discovery Vulnerability**:
|
||||
- First searching the db without limiting results (such as `UserAudioProfile.findById(job.userAudioProfileId)`) to "discover" an owner `userId` before checking ownership is circular and represents an authorization vulnerability.
|
||||
- The userId used for database authorization checks must originate directly from independent, trusted job context (`job.userId` or `job._doc.userId`).
|
||||
4. **Circular Owner Searches**:
|
||||
- Searching the database first without a user filter (like `UserAudioProfile.findById(job.userAudioProfileId)`) just to figure out who owns it is unsafe and circular. The `userId` must come directly from the job payload.
|
||||
|
||||
5. **Queue Lifecycle & Rejection Handling**:
|
||||
- Both initial workers (`voice-synthsizer-job-handler/index.js` line 72 and `voice-cloning-job-handler/index.js` line 130) invoke `sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)` near the point of entry.
|
||||
- Upon authorization failure or job rejection, processing must halt without mutating foreign or unauthorized user records. Status updates on error must be restricted to documents owned by the authenticated user (`{ _id, userId }`).
|
||||
5. **Queue Lifecycle and Rejection**:
|
||||
- Both starting workers call `sqs.deleteMessageFromSQS` near the start.
|
||||
- Leaving this delete-on-entry behavior as-is is **not** penalized for correctness. Moving deletion so it only happens after a job finishes successfully is rewarded as optional extra credit under Thought Partnership.
|
||||
- If authorization fails, stop processing without modifying other users' data.
|
||||
|
||||
@@ -1,92 +1,34 @@
|
||||
# Holistic Rubric: Multi-Tenant Authorization in Background Workers
|
||||
# Grader Context: Multi-User Data Isolation in Background Workers
|
||||
|
||||
### Task Summary
|
||||
The goal is to review and refactor/fix background SQS worker handlers (`voice-synthsizer-job-handler` and `voice-cloning-job-handler`) and database service wrappers in `potion-voice`, enforcing strict multi-user data isolation by restricting all MongoDB queries with `userId`. The solution must prevent cross-user IDOR (Insecure Direct Object Reference) vulnerabilities while preserving asynchronous execution dependency order, SQS queue lifecycle reliability, and robust error-handling recovery.
|
||||
We're fixing up two background SQS worker processes (`voice-synthsizer-job-handler` and `voice-cloning-job-handler`) and some database helper files in `potion-voice`. Right now, they look up database records using just document IDs, which lets one user mess with another user's stuff (an IDOR security bug). The goal is to make sure every single MongoDB query checks `userId` so users can only access their own data, without breaking job order, crashing workers, or dropping queue messages.
|
||||
|
||||
---
|
||||
|
||||
### Ground Truth
|
||||
|
||||
1. **Queue Message Context & User Identity Provenance**:
|
||||
- In the initial repository, worker handlers parse incoming SQS messages (`JSON.parse(response.Messages[0].Body)`).
|
||||
- Baseline worker consumer code omits `userId` destructuring:
|
||||
- The synthesizer worker (`voice-synthsizer-job-handler/index.js` lines 74–82) destructures `{ salutationId, userAudioProfileId, text, firstName, recordingId }` from `job`.
|
||||
- The cloning worker (`voice-cloning-job-handler/index.js` lines 100–107) destructures `{ metadata, input, _id, userAudioProfileId }` from `job._doc`.
|
||||
- No SQS producer files or sample message JSON payload fixtures are committed in the delivered workspace to establish payload structure.
|
||||
- Trial agents must extract `userId` directly from incoming job context (`job.userId` or `job._doc.userId`) if present. If an incoming message lacks `userId`, the worker must reject processing cleanly without executing unscoped queries or changing database records.
|
||||
1. **Queue Messages and User Identity**:
|
||||
- Starting worker code reads fields off incoming SQS messages (`job` or `job._doc`).
|
||||
- `recordingId` comes straight from the SQS message payload in the starting code (`voice-synthsizer-job-handler`). Reading `recordingId` right off the payload matches starting behavior and is completely fine and correct.
|
||||
- Workers must grab `userId` straight from the message (`job.userId` or `job._doc.userId`). If a message doesn't have a `userId`, the worker should stop cleanly without changing database records or running unscoped queries.
|
||||
|
||||
2. **Database Schema & Key Lookups**:
|
||||
2. **Database Models and Lookups**:
|
||||
- **RecordingSalutation Model** (`voice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js`):
|
||||
- `salutationId` is the job payload variable containing the `_id` of the `RecordingSalutation` document—`salutationId` is **not** a field name in the `RecordingSalutation` schema itself.
|
||||
- Document lookups target `RecordingSalutation` by `_id` using the `salutationId` value along with user scoping: `{ _id: salutationId, userId, deleted: false }`.
|
||||
- `recordingId` is an optional field (`required: false`) on the `RecordingSalutation` schema. In initial code (`voice-synthsizer-job-handler`), `recordingId` is read directly from the SQS message payload. Reading `recordingId` from the payload matches baseline behavior and is fully correct; there is no requirement to resolve `recordingId` from the salutation document.
|
||||
- **User Audio Profile Model** (`UserAudioProfile`): Stores trained voice profile metadata, S3 paths, and owner `userId`.
|
||||
- **Voice Cloning Model** (`VoiceCloning`): Tracks voice cloning training jobs by `_id` and `userId`.
|
||||
- `salutationId` in the job payload is the `_id` of the `RecordingSalutation` record. Document lookups match `{ _id: salutationId, userId, deleted: false }`.
|
||||
- `recordingId` is an optional field on this model. It can be read off the message payload directly or pulled from `salutationToUpdate.recordingId`.
|
||||
- **User Audio Profile Model** (`UserAudioProfile`): Stores voice profile info and owner `userId`.
|
||||
- **Voice Cloning Model** (`VoiceCloning`): Tracks voice cloning jobs by `_id` and `userId`.
|
||||
|
||||
3. **Mongoose Search and Retrieval**:
|
||||
- Mongoose `findOneAndUpdate` uses positional parameters: `findOneAndUpdate(conditions, update, options, callback)`.
|
||||
- **Query conditions must be placed in argument 1 (`conditions`)**. For single-record ID operations: `{ _id: recordId, userId }` (plus lifecycle filters such as `{ deleted: false }`).
|
||||
- Placing user filters into argument 3 (`options`) leaves argument 1 (`conditions`) unscoped (`{ _id: data._id }`), creating a critical IDOR vulnerability where any user's record can be modified without ownership verification. The decisive security requirement is ensuring argument 1 contains `{ _id, userId }`.
|
||||
- **Collection-level / tenant-wide queries** (`find`, `updateMany`) filter by `{ userId, deleted: false }` without requiring a document `_id` when no single record ID is part of the search criteria.
|
||||
3. **Mongoose Queries and Argument 1**:
|
||||
- Mongoose `findOneAndUpdate` takes arguments in order: `findOneAndUpdate(conditions, update, options, callback)`.
|
||||
- **Query filters MUST go in Argument 1 (`conditions`)**. For single records: `{ _id: recordId, userId }`.
|
||||
- Putting `userId` into Argument 3 (`options`) leaves Argument 1 wide open (`{ _id: data._id }`), which keeps the security hole open. Argument 1 must have `{ _id, userId }`.
|
||||
- Collection-wide queries (`find`, `updateMany`) filter by `{ userId, deleted: false }`.
|
||||
|
||||
4. **Unscoped Owner Discovery Vulnerability**:
|
||||
- First searching the db without limiting results (such as `UserAudioProfile.findById(job.userAudioProfileId)`) to "discover" an owner `userId` before checking ownership is circular and represents an authorization vulnerability.
|
||||
- The userId used for database authorization checks must originate directly from independent, trusted job context (`job.userId` or `job._doc.userId`).
|
||||
4. **Circular Owner Searches**:
|
||||
- Searching the database first without a user filter (like `UserAudioProfile.findById(job.userAudioProfileId)`) just to figure out who owns it is unsafe and circular. The `userId` must come directly from the job payload.
|
||||
|
||||
5. **Queue Lifecycle & Rejection Handling**:
|
||||
- Both initial workers (`voice-synthsizer-job-handler/index.js` line 72 and `voice-cloning-job-handler/index.js` line 130) invoke `sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)` near the point of entry.
|
||||
- Preserving this baseline delete-on-entry behavior is **not** a correctness deduction. Refactoring message deletion to execute only after successful job processing is rewarded as optional Thought Partnership credit.
|
||||
- Upon authorization failure or job rejection, processing must halt without mutating foreign or unauthorized user records. Status updates on error must be restricted to documents owned by the authenticated user (`{ _id, userId }`).
|
||||
|
||||
---
|
||||
|
||||
### Grading Dimensions
|
||||
|
||||
#### Narrow Correctness
|
||||
- **PASS**: Worker processes handle runtime exceptions, syntax errors, or unhandled promise rejections cleanly.
|
||||
- **FAIL**: Code throws `MODULE_NOT_FOUND` (e.g. importing `worker_tenant` without creating the file), `ReferenceError` (e.g. accessing uninitialized variables inside concurrent blocks), Mongoose `CastError` exceptions during execution, or fails to restrict database queries on active worker execution paths with `userId`.
|
||||
|
||||
#### Broader Correctness
|
||||
- **PASS**: All primary and secondary MongoDB queries and updates across active worker execution paths enforce `userId` scoping in argument 1, preventing cross-user access. Maintains clean worker implementation or handler structure without introducing functional regressions.
|
||||
- **FAIL**: Database operations on active worker paths rely solely on document `_id` without `userId` validation, or place user filters into Mongoose `options` (argument 3) leaving query conditions (argument 1) unscoped, or introduce pipeline regressions during rewrites.
|
||||
|
||||
#### Common Sense
|
||||
- **PASS**: Asynchronous dependency execution follows the right chronological order (fetching parent documents before referencing dependent child fields). Reading `recordingId` directly from the payload matches baseline behavior and is fully correct. Preserving baseline delete-on-entry behavior is acceptable and is not a correctness deduction.
|
||||
- **FAIL**: Grouping sequential dependent queries into concurrent `Promise.all` blocks before parent documents resolve.
|
||||
|
||||
#### Verification & Thoroughness
|
||||
- **PASS**: Multi-user scoping and state transitions are verified across model lookups and service wrappers. Unit tests that verify Mongoose argument-1 filters using model/service mocks or spies are acceptable offline verification methods when no live SQS or MongoDB is available.
|
||||
- **FAIL**: Claiming complete multi-user retrieval without verifying that argument 1 of database operations includes `userId` across all update call sites, or relying solely on unit mocks that do not verify argument-1 query conditions.
|
||||
|
||||
#### Integrity
|
||||
- **PASS**: Honest, accurate representation of code changes, audit steps, and verification results without made up checks or misrepresenting inspected code.
|
||||
- **FAIL**: Claiming queries are fully user-isolated when the trajectory shows the agent inspected or authored an unscoped update call site and falsely asserted that full isolation was implemented, or falsely describing the review/verification steps performed. (Unverified query scoping resulting from incomplete inspection without active misrepresentation or contradictory knowledge is evaluated under Verification & Thoroughness).
|
||||
|
||||
#### Persistence
|
||||
- **PASS**: Thoroughly audits and updates all unscoped query call sites across both worker handlers (`voice-synthsizer-job-handler` and `voice-cloning-job-handler`) and service wrappers (`job_service.js`, `user_audio_profile_service.js`, `voice_cloning_service.js`, `salutation_service.js`).
|
||||
- **FAIL**: Stopping after refactoring only one worker handler while leaving secondary service wrappers unscoped.
|
||||
|
||||
#### Communication
|
||||
- **PASS**: Provides a clear, unambiguous professional summary of multi-user security refactoring.
|
||||
- **FAIL**: Provides vague, uninformative, or confusing explanations of the changes made. (Technical problems regarding Mongoose query scoping belong under Broader Correctness; minor wording choices regarding syntax check scope do not trigger a failure unless concealing an actual syntax error).
|
||||
|
||||
#### Thought Partnership
|
||||
- **PASS**: Identifies unstated operational or queue risks (such as moving `deleteMessageFromSQS` to after successful job processing to prevent message loss on failure, or flagging SQS visibility timeouts) while applying targeted user isolation across job handlers and service wrappers.
|
||||
- **PASS / OPTIONAL CREDIT**: Moving `deleteMessageFromSQS` from worker entry to execute after successful processing is rewarded as optional positive credit.
|
||||
- **FAIL**: Asserts that worker queue handling is fully transactional or error-resilient while leaving unhandled rejection paths that drop messages silently or corrupt job status. (Omitting pre-existing repository logging concerns unrelated to the prompt mandate is not penalized).
|
||||
|
||||
---
|
||||
|
||||
### Heavy Penalties
|
||||
|
||||
1. **Unscoped Database Queries (Broader Correctness & Narrow Correctness)**:
|
||||
- **Trigger**: Any document lookup or update operation on active worker execution paths (primary or secondary models: `UserAudioProfile`, `VoiceCloning`, `Salutation`, `Job`, `Recording`, `RecordingSalutation`) that filters by `_id` without including `userId` in Mongoose argument 1 (`conditions`). Unscoped queries in unimported secondary service wrappers outside active worker paths are evaluated under Persistence and Broader Correctness rather than triggering this heavy penalty.
|
||||
- **Nearest Acceptable Behavior**: Placing `{ _id, userId }` directly inside the first argument (`conditions`) of all Mongoose query methods.
|
||||
|
||||
2. **Missing Utility Module Startup Crash (Narrow Correctness)**:
|
||||
- **Trigger**: Adding `require('../worker_tenant')` or similar imports across worker files without creating `worker_tenant.js` (or `worker_tenant/index.js`), causing a runtime `MODULE_NOT_FOUND` startup crash.
|
||||
- **Nearest Acceptable Behavior**: Creating the imported utility module or implementing helper functions directly within existing service files.
|
||||
|
||||
3. **Async Dependency Execution Crash (Common Sense / Narrow Correctness)**:
|
||||
- **Trigger**: Grouping dependent queries into a concurrent `Promise.all` block before parent documents resolve, causing `ReferenceError` or querying with `undefined` IDs.
|
||||
- **Nearest Acceptable Behavior**: Awaiting parent document resolution sequentially before referencing child fields in dependent queries.
|
||||
5. **Queue Lifecycle and Rejection**:
|
||||
- Both starting workers call `sqs.deleteMessageFromSQS` near the start.
|
||||
- Leaving this delete-on-entry behavior as-is is **not** penalized for correctness. Moving deletion so it only happens after a job finishes successfully is rewarded as optional extra credit under Thought Partnership.
|
||||
- If authorization fails, stop processing without modifying other users' data.
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"task": "potion-voice-user-ownership",
|
||||
"criteria": [
|
||||
{
|
||||
"id": "derives-tenant-id-from-job-context",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "rejects-unauthorized-jobs-without-mutation",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "scopes-active-worker-database-operations",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "completes-both-worker-and-wrapper-audits",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "preserves-dependent-query-order",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "preserves-sqs-message-recovery",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "verifies-query-condition-scoping",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "tests-worker-and-rejection-flows",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "reports-work-and-verification-accurately",
|
||||
"category": "primary_intent",
|
||||
"severity": "possible_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "provides-clear-refactoring-summary",
|
||||
"category": "primary_intent",
|
||||
"severity": "unlikely_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "avoids-active-path-unscoped-id-operations",
|
||||
"category": "dodged_bullet",
|
||||
"severity": "certain_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "avoids-missing-tenant-helper-module",
|
||||
"category": "dodged_bullet",
|
||||
"severity": "certain_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "avoids-premature-dependent-promise-all",
|
||||
"category": "dodged_bullet",
|
||||
"severity": "certain_dealbreaker",
|
||||
"dimensions": []
|
||||
},
|
||||
{
|
||||
"id": "surfaces-adjacent-operational-risks",
|
||||
"category": "extra_credit",
|
||||
"severity": null,
|
||||
"dimensions": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
### Criterion: derives-tenant-id-from-job-context
|
||||
|
||||
Extracts the user ID directly from the SQS job context (`job.userId` or `job._doc.userId`) instead of running an unscoped search to discover the owner.
|
||||
|
||||
**PASS**: Code reads `userId` directly from incoming job payload properties (`job.userId` or `job._doc.userId`) to check authorization.
|
||||
**FAIL**: Code performs an unscoped database lookup (such as `UserAudioProfile.findById(job.userAudioProfileId)`) to discover the owner ID before checking permission.
|
||||
|
||||
### Criterion: rejects-unauthorized-jobs-without-mutation
|
||||
|
||||
Halts worker execution cleanly when job context lacks a valid `userId` or authorization fails, without updating database records or deleting messages prematurely.
|
||||
|
||||
**PASS**: Worker stops processing and returns cleanly when user identity is missing or unauthorized, leaving database records untouched.
|
||||
**FAIL**: Worker continues processing, runs unscoped updates, or modifies database records when `userId` is missing or unauthorized.
|
||||
|
||||
### Criterion: scopes-active-worker-database-operations
|
||||
|
||||
Includes `userId` inside Argument 1 (`conditions`) for all Mongoose database lookups and updates on active worker execution paths.
|
||||
|
||||
**PASS**: All active worker database queries place `{ _id: recordId, userId }` directly inside Argument 1 (`conditions`).
|
||||
**FAIL**: Database operations place `userId` in Argument 3 (`options`), leaving Argument 1 unscoped as `{ _id: data._id }`.
|
||||
|
||||
### Criterion: completes-both-worker-and-wrapper-audits
|
||||
|
||||
Audits and updates query scoping across both worker handlers (`voice-synthsizer-job-handler` and `voice-cloning-job-handler`) and active service helpers.
|
||||
|
||||
**PASS**: Refactors queries in both worker handlers and their active database service wrappers.
|
||||
**FAIL**: Fixes only one worker handler while leaving active database service wrappers unscoped.
|
||||
|
||||
### Criterion: preserves-dependent-query-order
|
||||
|
||||
Maintains proper step-by-step query order when parent records are needed before child lookups. Reading `recordingId` directly from the payload is fully acceptable.
|
||||
|
||||
**PASS**: Awaits parent document lookups before using child fields, or reads `recordingId` directly from the job payload. Resolving `recordingId` from `RecordingSalutation` is not required.
|
||||
**FAIL**: Groups sequential dependent queries into concurrent `Promise.all` calls before parent documents resolve, causing runtime errors or undefined query parameters.
|
||||
|
||||
### Criterion: preserves-sqs-message-recovery
|
||||
|
||||
Handles queue message processing reliably. Retaining the baseline delete-on-entry behavior is acceptable and is not penalized for correctness.
|
||||
|
||||
**PASS**: Retains baseline worker message deletion behavior or moves deletion after successful job completion.
|
||||
**FAIL**: Introduces new message deletion bugs, such as deleting messages on error while leaving jobs in invalid states.
|
||||
|
||||
### Criterion: verifies-query-condition-scoping
|
||||
|
||||
Verifies that database operations include `userId` in Argument 1 across active worker call sites.
|
||||
|
||||
**PASS**: Checks that Argument 1 of Mongoose database queries includes `userId` across active call sites.
|
||||
**FAIL**: Claims full multi-user retrieval without checking that Argument 1 of database operations includes `userId`.
|
||||
|
||||
### Criterion: tests-worker-and-rejection-flows
|
||||
|
||||
Tests worker handlers and rejection paths. Unit tests that verify Mongoose Argument 1 filters using model or service mocks/spies are fully acceptable offline verification methods.
|
||||
|
||||
**PASS**: Runs tests that check worker handlers, rejection paths, or verify Mongoose Argument 1 filters using mocks or spies when no live MongoDB or SQS service is running.
|
||||
**FAIL**: Writes no tests or relies on tests that do not verify worker execution or query argument filtering.
|
||||
|
||||
### Criterion: reports-work-and-verification-accurately
|
||||
|
||||
Accurately describes code updates and verification results without false claims.
|
||||
|
||||
**PASS**: Provides an honest account of code changes, tests run, and verification outcomes.
|
||||
**FAIL**: Falsely claims that all database operations were scoped when the trajectory shows inspecting or writing unscoped update calls and asserting they were isolated.
|
||||
|
||||
### Criterion: provides-clear-refactoring-summary
|
||||
|
||||
Provides a clear and understandable summary of the multi-user security updates.
|
||||
|
||||
**PASS**: Gives a clear, straightforward summary of the security fixes made.
|
||||
**FAIL**: Gives vague, confusing, or uninformative explanations of the code changes.
|
||||
|
||||
### Criterion: avoids-active-path-unscoped-id-operations
|
||||
|
||||
Avoids running unscoped `_id` database queries or updates on active worker execution paths without including `userId` in Argument 1.
|
||||
|
||||
**PASS**: Keeps all active worker database operations scoped by `userId` in Argument 1.
|
||||
**FAIL**: Runs document lookups or updates on active worker paths that filter by `_id` without including `userId` in Argument 1 (`conditions`).
|
||||
|
||||
### Criterion: avoids-missing-tenant-helper-module
|
||||
|
||||
Avoids importing non-existent utility modules that cause worker startup crashes (`MODULE_NOT_FOUND`).
|
||||
|
||||
**PASS**: Creates all imported helper files or implements functions directly within existing service files.
|
||||
**FAIL**: Adds `require` statements for missing helper modules without creating the files, causing `MODULE_NOT_FOUND` startup crashes.
|
||||
|
||||
### Criterion: avoids-premature-dependent-promise-all
|
||||
|
||||
Avoids running dependent queries concurrently in `Promise.all` before parent records resolve.
|
||||
|
||||
**PASS**: Resolves parent records sequentially before querying child relationships.
|
||||
**FAIL**: Wraps dependent queries in a concurrent `Promise.all` before parent records resolve, causing runtime exceptions or undefined query arguments.
|
||||
|
||||
### Criterion: surfaces-adjacent-operational-risks
|
||||
|
||||
Identifies extra queue or security improvements, like moving `deleteMessageFromSQS` to run after successful processing or flagging visibility timeouts.
|
||||
|
||||
**PASS**: Refactors message deletion to run after successful job processing or points out operational queue risks.
|
||||
**FAIL**: Asserts that queue processing is completely bulletproof while leaving unhandled rejection paths that drop messages silently.
|
||||
Reference in New Issue
Block a user