Skip to content

#2250 - carrot #2359

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export class RunAttemptSystem {
machinePreset: true,
runTags: true,
isTest: true,
concurrencyKey: true,
idempotencyKey: true,
startedAt: true,
maxAttempts: true,
Expand Down Expand Up @@ -248,6 +249,7 @@ export class RunAttemptSystem {
]);

return {
concurrencyKey: run.concurrencyKey ?? undefined,
run: {
id: run.friendlyId,
tags: run.runTags,
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/v3/schemas/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ export const V3TaskRunExecution = z.object({
export type V3TaskRunExecution = z.infer<typeof V3TaskRunExecution>;

export const TaskRunContext = z.object({
/** The concurrency key used when triggering this run, if any */
concurrencyKey: z.string().optional(),
attempt: TaskRunExecutionAttempt,
Comment on lines +401 to 403
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider bounding the size of concurrencyKey

concurrencyKey is persisted in the DB and now flows straight into user-space task code. Unbounded strings (or even very long ones) can:

  • degrade index performance if the column is indexed for concurrency control,
  • inflate payload sizes when the context is serialised to the worker,
  • open the door to accidental PII / secrets leakage in logs.

A light-weight guard is to cap the length (and optionally disallow empty strings):

-  concurrencyKey: z.string().optional(),
+  concurrencyKey: z.string().max(256).optional(),

A 256-byte ceiling is usually more than enough for concurrency keys such as "user-123" or "order:abc-def", while still preventing pathological cases.

Also applies to: 425-427

🤖 Prompt for AI Agents
In packages/core/src/v3/schemas/common.ts around lines 401 to 403, the
concurrencyKey string is currently unbounded, which can cause performance and
security issues. Fix this by adding a maximum length constraint of 256
characters to concurrencyKey using the appropriate zod string method, and
optionally disallow empty strings. Apply the same length bounding to the
concurrencyKey field at lines 425 to 427 as well.

run: TaskRun.omit({
payload: true,
Expand All @@ -420,6 +422,8 @@ export const V3TaskRunExecutionEnvironment = z.object({
export type V3TaskRunExecutionEnvironment = z.infer<typeof V3TaskRunExecutionEnvironment>;

export const V3TaskRunContext = z.object({
/** The concurrency key used when triggering this run, if any */
concurrencyKey: z.string().optional(),
attempt: V3TaskRunExecutionAttempt.omit({
backgroundWorkerId: true,
backgroundWorkerTaskId: true,
Expand Down