V2 match dotfiles

I’m working on a block that recursively forbids access to dotfiles. The approach I thought I’d take is with a named matcher that uses path_regexp, but it’s not working the way I would have expected. Maybe I’m not clear on what path the regexp gets.

@dotfiles {
  path_regexp ^\/?(?:\w+\/)*(\.\w+)
}
respond @dotfiles 403

It works for requests to /.dotfile, but not for /long/path/.dotfile.

Maybe it’s just my poor regex, but maybe there’s something else for me to learn here. Help is appreciated.

I copied the regex from a stack overflow and tested it in a regex program that was using go’s regex.

It was a regex issue… this works to recursively forbid access to dotfiles in v2

  @dotfiles {
    path_regexp (^|\/)\.[^\.\/]+
  }
  respond @dotfiles 403

Thanks @solderjs

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.