Repository navigation
feat(tools): expose selected package versions for exact events #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f7ae542
2a7311a
151d53d
11929e5
3260660
09e25a0
e02dd8a
86bf881
860b10b
4cd3136
d622ab8
d2cd3f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { z } from "zod"; | ||
| import type { Event } from "../api-client/types"; | ||
|
|
||
| export const SelectedEventPackagesSchema = z.object({ | ||
| metadataAvailable: z.boolean(), | ||
| packages: z.array( | ||
| z.discriminatedUnion("status", [ | ||
| z.object({ | ||
| name: z.string(), | ||
| status: z.literal("recorded"), | ||
| version: z.string(), | ||
| truncated: z.boolean(), | ||
| }), | ||
| z.object({ | ||
| name: z.string(), | ||
| status: z.enum(["not_listed", "version_not_recorded"]), | ||
| version: z.null(), | ||
| truncated: z.literal(false), | ||
| }), | ||
| ]), | ||
| ), | ||
| }); | ||
|
|
||
| /** Select once for both structured and Markdown output, without exposing the full map. */ | ||
| export function selectEventPackages( | ||
| packages: Event["packages"], | ||
| packageNames?: string[], | ||
| ): z.infer<typeof SelectedEventPackagesSchema> | undefined { | ||
| if (!packageNames?.length) { | ||
| return undefined; | ||
| } | ||
| const packageVersions = new Map(Object.entries(packages ?? {})); | ||
| if (packageVersions.size === 0) { | ||
| return { metadataAvailable: false, packages: [] }; | ||
| } | ||
|
|
||
| return { | ||
| metadataAvailable: true, | ||
| packages: Array.from(new Set(packageNames), (name) => { | ||
| const version = packageVersions.get(name); | ||
| const notListed = version === undefined; | ||
| return version?.trim() | ||
| ? { | ||
| name, | ||
| status: "recorded", | ||
| version: version.slice(0, 256), | ||
| truncated: version.length > 256, | ||
| } | ||
| : { | ||
| name, | ||
| status: notListed ? "not_listed" : "version_not_recorded", | ||
| version: null, | ||
| truncated: false, | ||
| }; | ||
| }), | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,14 @@ export const ParamIssueShortId = z | |
| .trim() | ||
| .describe("The Issue ID. e.g. `PROJECT-1Z43`"); | ||
|
|
||
| export const ParamPackageNames = z | ||
| .array(z.string().min(1).max(256)) | ||
|
Comment on lines
+82
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Risk: Affected versions of zod are vulnerable to Allocation of Resources Without Limits or Throttling. Zod parses every element of an array, set or map schema and records one validation issue per invalid element, with no cap or early stop. Upper size bounds ( Fix: Upgrade this library to at least version 4.6.6 at toolkit/pnpm-lock.yaml:9619.
🍰 Fixed in commit d622ab8 🍰 |
||
| .min(1) | ||
| .max(10) | ||
| .describe( | ||
| "Exact, case-sensitive package names recorded with a specific event (1–10 names, up to 256 characters each). Requires an event lookup. Only selected package versions are added; versions longer than 256 characters are truncated.", | ||
| ); | ||
|
|
||
| export const ParamIssueUrl = z | ||
| .string() | ||
| .url() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High severity issue identified in your code:Risk: Affected versions of zod are vulnerable to Allocation of Resources Without Limits or Throttling. Zod parses every element of an array, set or map schema and records one validation issue per invalid element, with no cap or early stop. Upper size bounds (
.max(),.length(),.size(), orz.maxLength()/z.length()/z.maxSize()/z.size()checks) only ran after all elements had been parsed, so they did not limit the work. An attacker who submits a very large collection (e.g. a million invalid items forz.array(z.string().uuid())) forces the allocation of millions of issue objects, which can exhaust memory and crash the process. Upgrade to zod 4.6.6 or later, which rejects oversized input before parsing its elements when the schema has an upper bound, and add an upper bound (e.g..max(n)) to every collection schema that parses untrusted input: unbounded schemas stay exposed even after the upgrade.Fix: Upgrade this library to at least version 4.6.6 at toolkit/pnpm-lock.yaml:9619.
Reference(s): GHSA-mrhx-c7xc-m3w5, CVE-2023-54404🍰 Fixed in commit d622ab8 🍰