remix-run/remix · error · Error

invalid bypass pattern ${JSON.stringify(pattern)}: empty pat

Error message

invalid bypass pattern ${JSON.stringify(pattern)}: empty path segments are not allowed

What it means

parseBypassSegment throws when a path segment in a bypass pattern is empty, i.e. the pattern contains '//' or a trailing construction that yields an empty segment. Every segment between slashes must be a static value or a {wildcard}. Empty segments usually indicate a typo like a doubled slash.

Source

Thrown at packages/cop-middleware/src/lib/cop.ts:271

  let matchesSubtree = pathname.endsWith('/')
  let normalizedPathname =
    pathname.length > 1 && matchesSubtree ? pathname.slice(0, pathname.length - 1) : pathname
  let rawSegments = normalizedPathname === '/' ? [] : normalizedPathname.slice(1).split('/')
  let segments = rawSegments.map((segment, index) =>
    parseBypassSegment(pattern, segment, index === rawSegments.length - 1),
  )

  return { method, pathname, segments, matchesSubtree }
}

function parseBypassSegment(
  pattern: string,
  segment: string,
  isLastSegment: boolean,
): BypassSegment {
  if (segment === '') {
    throw new Error(
      `invalid bypass pattern ${JSON.stringify(pattern)}: empty path segments are not allowed`,
    )
  }

  if (!segment.startsWith('{') || !segment.endsWith('}')) {
    return { type: 'static', value: segment }
  }

  let wildcardName = segment.slice(1, segment.length - 1)
  if (wildcardName === '') {
    throw new Error(
      `invalid bypass pattern ${JSON.stringify(pattern)}: empty wildcards are not allowed`,
    )
  }

  if (wildcardName === '$') {
    throw new Error(
      `invalid bypass pattern ${JSON.stringify(pattern)}: "{$}" is not supported in cop-middleware`,

View on GitHub (pinned to 9696913134)

Solutions

  1. Remove the double slash: '/admin/users' instead of '/admin//users'
  2. When concatenating pattern strings, normalize with a join that collapses duplicate slashes

Example fix

// before
const base = '/admin/'
cop.addInsecureBypassPattern(base + '/users') // '/admin//users'
// after
const base = '/admin'
cop.addInsecureBypassPattern(base + '/users')
Defensive patterns

Strategy: validation

Validate before calling

function hasNoEmptySegments(pattern: string): boolean {
  const path = pattern.slice(pattern.indexOf('/'))
  return !path.split('/').slice(1).some((s, i, arr) => s === '' && i < arr.length - 1)
}

Type guard

const isSegmented = (p: string) => { const parts = p.split('/'); return parts.every((s) => s !== '') }

Prevention

When it happens

Trigger: addInsecureBypassPattern('/admin//users') (double slash), or patterns where splitting the normalized pathname on '/' produces an empty component.

Common situations: Typos with doubled slashes; string concatenation building patterns that accidentally inserts an extra '/', e.g. `/admin/ + '/users'`.

Related errors


AI-assisted analysis of remix-run/remix@9696913134 (2026-08-27). Data as JSON: /api/errors/118642aca0113312. Report an issue: GitHub.