{"record":{"id":"600e4e1d3e0b428e","repo":"remix-run/remix","slug":"invalid-bypass-pattern-json-stringify-pattern-600e4e","errorCode":null,"errorMessage":"invalid bypass pattern ${JSON.stringify(pattern)}: tail wildcards must be last","messagePattern":"invalid bypass pattern (.+?): tail wildcards must be last","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cop-middleware/src/lib/cop.ts","lineNumber":295,"sourceCode":"    return { type: 'static', value: segment }\n  }\n\n  let wildcardName = segment.slice(1, segment.length - 1)\n  if (wildcardName === '') {\n    throw new Error(\n      `invalid bypass pattern ${JSON.stringify(pattern)}: empty wildcards are not allowed`,\n    )\n  }\n\n  if (wildcardName === '$') {\n    throw new Error(\n      `invalid bypass pattern ${JSON.stringify(pattern)}: \"{$}\" is not supported in cop-middleware`,\n    )\n  }\n\n  if (wildcardName.endsWith('...')) {\n    if (!isLastSegment) {\n      throw new Error(\n        `invalid bypass pattern ${JSON.stringify(pattern)}: tail wildcards must be last`,\n      )\n    }\n\n    if (wildcardName.length === 3) {\n      throw new Error(\n        `invalid bypass pattern ${JSON.stringify(pattern)}: tail wildcards require a name`,\n      )\n    }\n\n    return { type: 'rest' }\n  }\n\n  return { type: 'wildcard' }\n}\n\nfunction matchesBypassPattern(pattern: BypassPattern, context: RequestContext): boolean {\n  if (pattern.method != null && pattern.method !== context.method) {","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/cop-middleware/src/lib/cop.ts#L277-L313","documentation":"parseBypassSegment throws when a tail wildcard '{name...}' appears anywhere except the last path segment. A rest/tail wildcard matches everything remaining, so it can only terminate the pattern. Earlier segments must be static values or single-segment wildcards.","triggerScenarios":"addInsecureBypassPattern('/files/{rest...}/edit') or any pattern where a '...' wildcard is followed by another segment.","commonSituations":"Attempting to express 'match some middle portion then more segments'; adapting glob patterns like '/files/**/edit' into wildcard syntax incorrectly.","solutions":["Move the tail wildcard to the end: '/files/{path...}' instead of '/files/{path...}/edit'","If you need a middle catch-all, restructure into multiple bypass patterns or handle it in middleware logic"],"exampleFix":"// before\ncop.addInsecureBypassPattern('/files/{rest...}/edit')\n// after\ncop.addInsecureBypassPattern('/files/{rest...}')","handlingStrategy":"validation","validationCode":"function tailWildcardIsLast(pattern: string): boolean {\n  const segs = pattern.slice(1).split('/')\n  const tailIdx = segs.findIndex((s) => /^\\{.*\\.\\.\\.\\}$/.test(s))\n  return tailIdx === -1 || tailIdx === segs.length - 1\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember tail wildcards terminate matching; place them last","Express middle-catch-all needs with multiple patterns or middleware logic"],"tags":["cop-middleware","bypass-pattern","wildcard","validation"],"backgroundTag":"invalid-path-pattern","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}