Skip to content

Conversation

@transphorm
Copy link
Member

@transphorm transphorm commented Jan 27, 2026

Motivation

  • The proving internals were refactored into modules and retained unsafe casts and missing null checks, creating type-safety and potential security issues.
  • The changes aim to validate sensitive inputs before casting, avoid logging PII or full status payloads, and make mapping logic explicit for unsupported categories (Aadhaar/DSC).

Description

  • Added secret validation guards in _generateCircuitInputs for the register and disclose cases to ensure secret is present and a string, and removed unsafe as string casts (packages/mobile-sdk-alpha/src/proving/internal/payloadGenerator.ts).
  • Added a guard for uuid before building the submit request in _generatePayload and throw a clear error if missing (packages/mobile-sdk-alpha/src/proving/internal/payloadGenerator.ts).
  • Added secret validation in the validatingDocument disclose branch before calling isUserRegistered to avoid unsafe casts (packages/mobile-sdk-alpha/src/proving/internal/documentProcessor.ts).
  • Added circuit type presence validation in the Socket.IO status handler and changed PROVE_FAILURE logging to avoid printing the full status payload (log only the error code), then dispatch PROVE_ERROR if circuit type is missing (packages/mobile-sdk-alpha/src/proving/internal/socketIOListener.ts).
  • Made DSC mapping explicit in getMappingKey to handle passport, id_card, and explicitly disallow aadhaar for DSC circuits with a clear error (packages/mobile-sdk-alpha/src/proving/internal/websocketUrlResolver.ts).

Testing

  • Ran type check: yarn workspace @selfxyz/mobile-sdk-alpha types (passed).
  • Built the package: yarn workspace @selfxyz/mobile-sdk-alpha build (build succeeded).
  • Ran unit tests: yarn workspace @selfxyz/mobile-sdk-alpha test and all tests passed (Test Files: 28 passed; Tests: 250 passed).

Codex Task

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced validation and error handling for required security credentials during registration and disclosure operations
    • Added pre-submission validation to ensure complete transaction data before processing
    • Improved error messages for unsupported document types and document categories
    • Fixed detection and handling of missing configuration in status message processing

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

This PR adds runtime validation guards across the proving module to enforce required parameters (secret, uuid, circuitType) and enhances error handling in document processing, payload generation, socket handling, and URL resolution pipelines.

Changes

Cohort / File(s) Summary
Input Validation & Guards
packages/mobile-sdk-alpha/src/proving/internal/documentProcessor.ts, packages/mobile-sdk-alpha/src/proving/internal/payloadGenerator.ts
Added guards requiring secret to be a non-empty string in disclose and register circuit types before calling generator functions; added pre-submit validation ensuring uuid presence before payload submission
Socket Event Handling
packages/mobile-sdk-alpha/src/proving/internal/socketIOListener.ts
Introduced guard to detect missing circuitType in status messages, raising PROVE_ERROR if absent; improved error logging for PROVE_FAILURE events to extract error_code from result.stateUpdate
URL Resolution Logic
packages/mobile-sdk-alpha/src/proving/internal/websocketUrlResolver.ts
Replaced generic fallback logic with explicit conditional branches for document category mapping: passport → 'DSC', id_card → 'DSC_ID', aadhaar → throws error, unmapped categories → throws descriptive error

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • seshanthS

Poem

🛡️ Guards are standing at the gates,
Checking secrets, validating fates,
No stray uuid shall slip through,
Circuits mapped with rules so true—
Defensive coding takes the stage! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main changes—adding null guards and secure logging across proving internals modules.
Description check ✅ Passed The description comprehensively covers all changes across four modules, includes testing results, and follows the template structure with Motivation, Description, and Testing sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/mobile-sdk-alpha/src/proving/internal/documentProcessor.ts (1)

260-260: Inconsistent: unsafe as string cast remains in the register branch.

The PR goal is to remove unsafe casts, but line 260 still uses secret as string when calling isUserRegisteredWithAlternativeCSCA. This path could receive an undefined secret, which would be silently coerced.

Consider adding a similar guard before this call for consistency with the disclose path:

🔧 Suggested fix
     } else {
+      if (!secret || typeof secret !== 'string') {
+        throw new Error('Secret is required and must be a string');
+      }
       const { isRegistered, csca } = await isUserRegisteredWithAlternativeCSCA(passportData, secret as string, {

Then remove the as string cast after the guard is in place.

🤖 Fix all issues with AI agents
In `@packages/mobile-sdk-alpha/src/proving/internal/socketIOListener.ts`:
- Around line 120-125: Prettier flagged a formatting issue in the actorEvent
handling block around the PROVE_FAILURE branch; fix the formatting
(spacing/indentation) so the if-block and calls are compliant (ensure consistent
indentation and spacing around the if, the console.error(...) line, and the
getActor()?.send(result.actorEvent) line), then run Prettier or apply the
project's code formatter to the file to clear the CI warning; the relevant
symbols to look at are result.actorEvent, 'PROVE_FAILURE', console.error(...)
and getActor()?.send(...).

Comment on lines 120 to 125
if (result.actorEvent) {
if (result.actorEvent.type === 'PROVE_FAILURE') {
console.error('Proof generation/verification failed (status 3 or 5).');
console.error(data);
console.error('Proof generation/verification failed (status 3 or 5). Error code:', result.stateUpdate?.error_code);
}
getActor()?.send(result.actorEvent);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Good: Logging only error_code instead of full payload.

This aligns with the coding guidelines about not logging sensitive data. The status payload may contain sensitive context, so logging just the error_code is appropriate.

However, the static analysis indicates a Prettier formatting issue on line 122 that's causing the CI warning.

🔧 Fix formatting
       if (result.actorEvent) {
         if (result.actorEvent.type === 'PROVE_FAILURE') {
-          console.error('Proof generation/verification failed (status 3 or 5). Error code:', result.stateUpdate?.error_code);
+          console.error(
+            'Proof generation/verification failed (status 3 or 5). Error code:',
+            result.stateUpdate?.error_code,
+          );
         }
         getActor()?.send(result.actorEvent);
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (result.actorEvent) {
if (result.actorEvent.type === 'PROVE_FAILURE') {
console.error('Proof generation/verification failed (status 3 or 5).');
console.error(data);
console.error('Proof generation/verification failed (status 3 or 5). Error code:', result.stateUpdate?.error_code);
}
getActor()?.send(result.actorEvent);
}
if (result.actorEvent) {
if (result.actorEvent.type === 'PROVE_FAILURE') {
console.error(
'Proof generation/verification failed (status 3 or 5). Error code:',
result.stateUpdate?.error_code,
);
}
getActor()?.send(result.actorEvent);
}
🧰 Tools
🪛 GitHub Check: lint

[warning] 122-122:
Replace 'Proof·generation/verification·failed·(status·3·or·5).·Error·code:',·result.stateUpdate?.error_code with ⏎············'Proof·generation/verification·failed·(status·3·or·5).·Error·code:',⏎············result.stateUpdate?.error_code,⏎··········

🤖 Prompt for AI Agents
In `@packages/mobile-sdk-alpha/src/proving/internal/socketIOListener.ts` around
lines 120 - 125, Prettier flagged a formatting issue in the actorEvent handling
block around the PROVE_FAILURE branch; fix the formatting (spacing/indentation)
so the if-block and calls are compliant (ensure consistent indentation and
spacing around the if, the console.error(...) line, and the
getActor()?.send(result.actorEvent) line), then run Prettier or apply the
project's code formatter to the file to clear the CI warning; the relevant
symbols to look at are result.actorEvent, 'PROVE_FAILURE', console.error(...)
and getActor()?.send(...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants