fix: return null instead of throwing on invalid crypto input#443
fix: return null instead of throwing on invalid crypto input#443tmdeveloper007 wants to merge 2 commits into
Conversation
|
@tmdeveloper007 is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
|
@Priyanshu-byte-coder |
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
Two issues to resolve before merge:
-
Return type contract changed without auditing callers. The base
decryptTokenreturnsstring | null— all call sites ingithub-accounts.tshandlenullcorrectly. This PR appears to change the return type tostringand throws instead of returningnull. If the existingtry/catchwrapper is still present, the thrown errors are silently caught and the validation is dead code. If thetry/catchwas removed, all callers now receive uncaught exceptions instead of null. Please clarify: keep returningnullon invalid input (consistent with existing contract) rather than throwing, so no call sites need to change. -
Length check edge case.
encrypted.length < AUTH_TAG_LENGTH * 2(i.e., < 32) allows zero-byte ciphertext (length === 32 = auth tag only, empty plaintext). If empty plaintext tokens should be rejected, use<= AUTH_TAG_LENGTH * 2.
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
Two issues still not resolved + new merge conflict:
- Merge conflict — branch needs rebase on
mainbefore this can proceed. - Return type not fixed —
decryptTokenstill throws instead of returningnull. Callers ingithub-accounts.tsexpectnullon bad input; they will now receive uncaught exceptions. Keepstring | nullreturn type and returnnullfrom the guard clauses instead of throwing. - Length check —
encrypted.length < AUTH_TAG_LENGTH * 2allows zero-byte ciphertext (32 hex chars = 16-byte auth tag + 0 bytes plaintext). Use<= AUTH_TAG_LENGTH * 2to reject empty plaintext.
tmdeveloper007
left a comment
There was a problem hiding this comment.
Thank you for the review. I have addressed both issues:
-
Return type contract preserved: Changed to return instead of throwing. Added filters in and to handle null values gracefully.
-
Length check edge case fixed: Changed to to reject empty ciphertext.
All tests pass (type-check and lint). Please review the updated changes.
Closes #442.
Summary of What Has Been Done:
Updated to return instead of throwing on invalid input, preserving the original return type contract. Also fixed the edge case where empty ciphertext could pass validation by changing to in the length check.
Changes Made:
File: src/lib/crypto.ts
File: src/lib/github-accounts.ts
Impact it Made: