fix: three defensive bug fixes — GHCR manifest validation, shared issue response guard, hex-id adapter array checks - #1401
Draft
cursor[bot] wants to merge 3 commits into
Draft
Conversation
fetchManifest() cast response.json() as OciManifest without validating the response shape. If the registry returns malformed JSON or a response without a layers array, findLayerByFilename() crashes with TypeError: Cannot read properties of undefined. Add try/catch around response.json() with debug logging, and validate that layers is an array before returning. Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
…groupID
getSharedIssue() cast response.json() as { groupID: string }
without validation. If the API returns a different shape (missing
groupID, null, or non-string), the caller passes undefined to
subsequent API calls, producing confusing 404 errors.
Add try/catch around response.json() with debug logging, and
validate groupID is a non-empty string before returning.
Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
The event, trace, and span fuzzy-lookup adapters cast the data field from API responses as typed arrays and call .map() without checking Array.isArray(). If the API returns non-array data (null, undefined, or an error object), .map() crashes with TypeError. Add Array.isArray guards with debug logging, returning empty arrays on malformed responses. Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three independent bug fixes for unguarded external data handling that can cause runtime crashes.
1.
ghcr.ts— Validate OCI manifest response before accessinglayersRoot cause:
fetchManifest()castresponse.json()asOciManifestwithout validating the response shape. If the GHCR registry returns malformed JSON or a response without alayersarray,findLayerByFilename()crashes withTypeError: Cannot read properties of undefined (reading 'find').Reproduction: GHCR returns a non-standard manifest (e.g., during an outage or when the tag points to an index manifest rather than an image manifest).
Fix: Wrap
response.json()in try/catch with debug logging, and validate thatlayersis an array before returning.2.
api/issues.ts— ValidategetSharedIssueresponse shape before returninggroupIDRoot cause:
getSharedIssue()castresponse.json()as{ groupID: string }without validation. If the API returns a different shape (missinggroupID,null, or non-string value), the caller passesundefinedto subsequent API calls, producing confusing 404 errors on/issues/undefined/.Reproduction: The shared issue endpoint returns a response without
groupID(e.g., API version change, rate limiting with non-standard body).Fix: Wrap
response.json()in try/catch with debug logging, and validategroupIDis a non-empty string before returning.3.
hex-id-recovery.ts— Guard adapter data casts withArray.isArrayRoot cause: The event, trace, and span fuzzy-lookup adapters cast the
datafield from API responses as typed arrays and call.map()without checkingArray.isArray(). If the API returns non-array data (null,undefined, or an error object),.map()crashes withTypeError.Reproduction: API returns an error response body or malformed JSON where
datais not an array.Fix: Add
Array.isArrayguards with debug logging, returning empty arrays on malformed responses.All existing tests pass (148 tests across 5 test files).