{"record":{"id":"e4574bbe795aa50c","repo":"paperclipai/paperclip","slug":"invalid-teams-file-consent-binding","errorCode":null,"errorMessage":"Invalid Teams file consent binding","messagePattern":"Invalid Teams file consent binding","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/chat-teams-file-consent.ts","lineNumber":74,"sourceCode":"      .int()\n      .positive()\n      .max(Math.min(MAX_ATTACHMENT_BYTES, 60 * 1024 * 1024 - 1)),\n    filename,\n    token: tokenSchema,\n    expiresAt: z.iso.datetime(),\n  })\n  .strict();\nexport type TeamsFileConsentBinding = Readonly<z.infer<typeof bindingSchema>>;\n\nexport function createTeamsFileConsentBinding(\n  input: Omit<TeamsFileConsentBinding, \"schema\" | \"token\">,\n): TeamsFileConsentBinding {\n  const parsed = bindingSchema.safeParse({\n    ...input,\n    schema: SCHEMA,\n    token: `pcfc_${randomBytes(32).toString(\"base64url\")}`,\n  });\n  if (!parsed.success) throw new Error(\"Invalid Teams file consent binding\");\n  return Object.freeze(parsed.data);\n}\n\nexport function parseTeamsFileConsentBinding(\n  input: unknown,\n): TeamsFileConsentBinding | null {\n  const parsed = bindingSchema.safeParse(input);\n  return parsed.success ? Object.freeze(parsed.data) : null;\n}\n\nfunction digest(value: unknown): string {\n  return createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\");\n}\n\nconst privateContextSchema = z\n  .object({\n    companyId: z.uuid(),\n    endpointId: z.uuid(),","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/chat-teams-file-consent.ts#L56-L92","documentation":"createTeamsFileConsentBinding merges the input with a fixed schema marker and a freshly generated pcfc_ token, then validates the whole object against bindingSchema (zod). If validation fails — e.g. missing/invalid thread or user fields — it throws this opaque error. The parsed result is frozen as an immutable binding.","triggerScenarios":"Calling createTeamsFileConsentBinding with input missing required fields, wrong types (e.g. threadId as number), extra/unexpected shapes, or anything failing the bindingSchema.safeParse after schema/token injection.","commonSituations":"Building the binding from a parsed Teams webhook payload that lacks expected fields; version drift where the schema added a required field the caller doesn't supply; malformed consent card data forwarded from a bot handler.","solutions":["Log/reproduce the safeParse failure: temporarily validate the same input with the exported bindingSchema (or call parseTeamsFileConsentBinding) to see field-level issues","Ensure all required fields (thread id, user id, etc.) are present with correct types before the call","Align the caller with the current schema version after upgrades"],"exampleFix":"// before\nconst binding = createTeamsFileConsentBinding(input); // opaque throw\n// after\nconst probe = parseTeamsFileConsentBinding({ ...input, schema: 'teams.file-consent/v1' });\nif (!probe) throw new Error(`invalid consent input: ${JSON.stringify(input)}`);\nconst binding = createTeamsFileConsentBinding(input);","handlingStrategy":"validation","validationCode":"const probe = parseTeamsFileConsentBinding(input); if (!probe) throw new Error('consent binding input failed schema before create');","typeGuard":"function isConsentBindingInput(v: unknown): v is ConsentBindingInput { const x = v as ConsentBindingInput; return typeof x.threadId === 'string' && x.threadId.length > 0 && typeof x.userId === 'string' && x.userId.length > 0; }","tryCatchPattern":"try { const binding = createTeamsFileConsentBinding(input); } catch (err) { if ((err as Error).message === 'Invalid Teams file consent binding') { console.error('rejected consent input', input); return null; } throw err; }","preventionTips":["Pre-validate with parseTeamsFileConsentBinding or the zod schema to get field-level errors","Keep callers updated with schema-required fields across versions","Validate Teams webhook payloads at the boundary before building bindings"],"tags":["teams","schema-validation","zod"],"backgroundTag":"schema-validation-failed","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-10T03:14:50.855Z","contentChangedAt":"2026-09-10T03:14:50.855Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}