I don't know why but the holistic rubric failed dimension mispplication. This is the detetor run and rubric before fixing issues.
8.2 KiB
Holistic Rubric: Multi-Tenant Authorization in Background Workers
Task Summary
The goal is to audit and refactor background SQS worker handlers (voice-synthsizer-job-handler and voice-cloning-job-handler) and database service wrappers in potion-voice to enforce strict multi-tenant data isolation by scoping all MongoDB queries with userId. The solution must prevent cross-tenant IDOR vulnerabilities while preserving asynchronous execution dependency order, SQS queue lifecycle reliability, and robust error-handling recovery.
Ground Truth
-
Queue Message Context & User Identity Provenance:
- In the baseline repository, worker handlers parse incoming SQS messages (
JSON.parse(response.Messages[0].Body)). - Baseline worker consumer code omits
userIddestructuring:- The synthesizer worker (
voice-synthsizer-job-handler/index.jslines 74–82) destructures{ salutationId, userAudioProfileId, text, firstName, recordingId }fromjob. - The cloning worker (
voice-cloning-job-handler/index.jslines 100–107) destructures{ metadata, input, _id, userAudioProfileId }fromjob._doc.
- The synthesizer worker (
- No SQS producer files or sample message JSON payload fixtures are committed in the shipped workspace to establish payload structure.
- Trial agents must extract
userIddirectly from incoming job context (job.userIdorjob._doc.userId) if present. If an incoming message lacksuserId, the worker must reject processing cleanly without executing unscoped queries or mutating database records.
- In the baseline repository, worker handlers parse incoming SQS messages (
-
Database Schema & Key Lookups:
- RecordingSalutation Model (
voice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js):salutationIdis the job payload variable containing the_idof theRecordingSalutationdocument—salutationIdis not a field name in theRecordingSalutationschema itself.- Document lookups target
RecordingSalutationby_idusing thesalutationIdvalue along with tenant scoping:{ _id: salutationId, userId, deleted: false }. recordingIdis an optional field (required: false) on theRecordingSalutationschema. It can be resolved fromsalutationToUpdate.recordingIdafter 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 owneruserId. - Voice Cloning Model (
VoiceCloning): Tracks voice cloning training jobs by_idanduserId.
- RecordingSalutation Model (
-
Mongoose Query Standards:
- Mongoose
findOneAndUpdateaccepts 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 tenant 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_idwhen no single record ID is part of the search criteria.
- Mongoose
-
Unscoped Owner Discovery Vulnerability:
- Performing an initial unscoped database lookup (such as
UserAudioProfile.findById(job.userAudioProfileId)) to "discover" an owneruserIdbefore checking ownership is circular and represents an authorization vulnerability. - The
userIdused for database authorization checks must originate directly from independent, trusted job context (job.userIdorjob._doc.userId).
- Performing an initial unscoped database lookup (such as
-
Queue Lifecycle & Rejection Handling:
- Both baseline workers (
voice-synthsizer-job-handler/index.jsline 72 andvoice-cloning-job-handler/index.jsline 130) invokesqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)near worker entry. - Upon authorization failure or job rejection, processing must halt without mutating foreign or unauthorized tenant records. Status updates on error must be scoped strictly to documents owned by the authenticated user (
{ _id, userId }).
- Both baseline workers (
Grading Dimensions
Narrow Correctness
- PASS: Worker processes run cleanly without runtime exceptions, syntax errors, or unhandled promise rejections.
- FAIL: Code throws
MODULE_NOT_FOUND(e.g. importingworker_tenantwithout creating the file),ReferenceError(e.g. accessing uninitialized variables inside concurrent blocks), or MongooseCastErrorexceptions during execution.
Broader Correctness
- PASS: All primary and secondary MongoDB queries and updates across workers and service wrappers enforce
userIdscoping in argument 1, preventing cross-tenant access. Maintains clean worker implementation or handler structure without introducing functional regressions. - FAIL: Database operations rely solely on document
_idwithoutuserIdvalidation, or place tenant filters into Mongooseoptions(argument 3) leaving query conditions (argument 1) unscoped, or introduce pipeline regressions during rewrites.
Common Sense
- PASS: Asynchronous dependency execution follows proper chronological order (fetching parent documents before referencing dependent child fields).
- FAIL: Grouping sequential dependent queries into concurrent
Promise.allblocks before parent documents resolve.
Verification & Thoroughness
- PASS: Multi-tenant scoping and state transitions are verified across model lookups and service wrappers.
- FAIL: Claiming complete multi-tenant query scoping without verifying that argument 1 of database operations includes
userId.
Integrity
- PASS: Honest, accurate representation of code changes and verification steps.
- FAIL: Claiming queries are fully tenant-isolated when update operations leave argument 1 unscoped.
Persistence
- PASS: Thoroughly audits and updates all unscoped query call sites across both worker handlers (
voice-synthsizer-job-handlerandvoice-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, professional summary of multi-tenant security refactoring.
- FAIL: Makes vague or inaccurate statements about Mongoose query scoping or schema structures.
Thought Partnership
- PASS: Identifies unstated operational or security risks (such as SQS message visibility timeouts or credential logging in worker files) while applying targeted tenant isolation across job handlers and service wrappers.
- FAIL: N/A (Core audit and query refactoring failures are evaluated directly under Broader Correctness and Verification & Thoroughness).
Heavy Penalties
-
Unscoped Database Queries (Broader Correctness):
- Trigger: Any document lookup or update operation on primary or secondary models (
UserAudioProfile,VoiceCloning,Salutation,Job,Recording,RecordingSalutation) that filters by_idwithout includinguserIdin Mongoose argument 1 (conditions). - Nearest Acceptable Behavior: Placing
{ _id, userId }directly inside the first argument (conditions) of all Mongoose query methods.
- Trigger: Any document lookup or update operation on primary or secondary models (
-
Missing Utility Module Startup Crash (Narrow Correctness):
- Trigger: Adding
require('../worker_tenant')or similar imports across worker files without creatingworker_tenant.js(orworker_tenant/index.js), causing a runtimeMODULE_NOT_FOUNDstartup crash. - Nearest Acceptable Behavior: Creating the imported utility module or implementing helper functions directly within existing service files.
- Trigger: Adding
-
Async Dependency Execution Crash (Common Sense / Narrow Correctness):
- Trigger: Grouping dependent queries into a concurrent
Promise.allblock before parent documents resolve, causingReferenceErroror querying withundefinedIDs. - Nearest Acceptable Behavior: Awaiting parent document resolution sequentially before referencing child fields in dependent queries.
- Trigger: Grouping dependent queries into a concurrent