{"record":{"id":"54332d283539cc97","repo":"nexu-io/open-design","slug":"invalid-brand-id-brandid","errorCode":null,"errorMessage":"invalid brand id: ${brandId}","messagePattern":"invalid brand id: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/brands/index.ts","lineNumber":2168,"sourceCode":"  targetPrefix: string,\n): Promise<void> {\n  for (const file of collectFiles(sourceDir)) {\n    const projectPath = toPosixPath(path.join(targetPrefix, file.rel));\n    await writeProjectFile(projectsRoot, projectId, projectPath, fs.readFileSync(file.abs), { overwrite: true }, metadata);\n  }\n}\n\nfunction syncBrandSystemToUserDesignSystem(\n  userDesignSystemsRoot: string,\n  designSystemId: string,\n  brandsRoot: string,\n  brandId: string,\n  designMd: string,\n): void {\n  const dir = userDesignSystemDir(userDesignSystemsRoot, designSystemId);\n  if (!dir) throw new Error(`invalid design system id: ${designSystemId}`);\n  const brandRoot = resolveBrandFile(brandsRoot, brandId, []);\n  if (!brandRoot) throw new Error(`invalid brand id: ${brandId}`);\n\n  fs.writeFileSync(path.join(dir, 'DESIGN.md'), designMd, 'utf8');\n  copyDirectorySync(brandSystemDir(brandsRoot, brandId), path.join(dir, 'system'));\n  copyOptionalDirectorySync(path.join(brandRoot, 'logos'), path.join(dir, 'logos'));\n  copyOptionalDirectorySync(path.join(brandRoot, 'fonts'), path.join(dir, 'fonts'));\n  copyOptionalDirectorySync(path.join(brandRoot, 'imagery'), path.join(dir, 'imagery'));\n  copyOptionalDirectorySync(path.join(brandRoot, 'prefetch'), path.join(dir, 'prefetch'));\n  const brandJson = resolveBrandFile(brandsRoot, brandId, ['brand.json']);\n  if (brandJson && isFile(brandJson)) {\n    fs.copyFileSync(brandJson, path.join(dir, 'brand.json'));\n  }\n}\n\nfunction userDesignSystemDir(root: string, id: string): string | null {\n  if (!id.startsWith('user:')) return null;\n  const dirId = id.slice('user:'.length);\n  if (!/^[a-z0-9][a-z0-9-]*$/u.test(dirId)) return null;\n  const base = path.resolve(root);","sourceCodeStart":2150,"sourceCodeEnd":2186,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/brands/index.ts#L2150-L2186","documentation":"Thrown by syncBrandSystemToUserDesignSystem when resolveBrandFile returns null for the brandId. The brand id must match /^[a-z0-9][a-z0-9-]*$/ and must not contain '..', else the traversal-safe resolver refuses it. This guards the brand -> user-design-system copy path so a stray id can never escape the brands root.","triggerScenarios":"A call to the route that copies a built brand system into a user design system (brands/index.ts:1483) with a brandId that fails isValidBrandId, e.g. 'My_Brand', 'UPPER', 'brand.json', '', '../x', or an id with slashes/spaces.","commonSituations":"Calling the sync endpoint directly with a hand-typed id; passing a brand.json filename instead of the dir id; corrupted/partial extraction that wrote no valid brand dir before sync was triggered; tests that synthesize ids without going through newBrandId().","solutions":["Resolve the brand id from listBrandIds(brandsRoot) or newBrandId(sourceUrl) instead of constructing it by hand.","Validate the id with isValidBrandId (exported from store.ts) before calling the sync route, and 404 the client on failure.","Confirm the brand dir actually exists (readBrand(brandsRoot, id) is non-null) before invoking sync.","If a stale design-system id is the real issue, regenerate it from the brands list rather than retrying the same string."],"exampleFix":"// before\nsyncBrandSystemToUserDesignSystem(udsRoot, dsId, brandsRoot, 'My_Brand', md);\n// after\nimport { isValidBrandId } from './store.js';\nif (!isValidBrandId(brandId)) throw new HttpError(404, `no such brand: ${brandId}`);\nsyncBrandSystemToUserDesignSystem(udsRoot, dsId, brandsRoot, brandId, md);","handlingStrategy":"validation","validationCode":"import { isValidBrandId, readBrand } from './store.js';\nfunction assertSyncableBrandId(brandsRoot, id) {\n  if (!isValidBrandId(id)) throw new Error(`invalid brand id: ${id}`);\n  if (!readBrand(brandsRoot, id)) throw new Error(`brand not found: ${id}`);\n}","typeGuard":"import { isValidBrandId } from './store.js';\nconst isSyncableBrandId = (id: unknown): id is string =>\n  typeof id === 'string' && isValidBrandId(id);","tryCatchPattern":null,"preventionTips":["Mint brand ids only through newBrandId(sourceUrl); never construct them from raw input.","Validate ids at the API boundary so the sync layer never sees an invalid one.","Confirm readBrand is non-null before any sync/rebuild call."],"tags":["brand","validation","path-traversal","id-validation"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}