Skip to content

Draft: Update GitLab PAT detection regex

Jamie Reid requested to merge jrreid-master-patch-30417 into master

Update GitLab PAT detection regex and introduce tests

This new regex courtesy @chill104 uses positive lookaheads to looks for GitLab PATs that have:

  • at least two lowercase characters
  • at least two uppercase characters
  • at least two non alphanumeric characters (i.e. [^\sa-zA-Z\"])
  • and are twenty characters in length

See https://regex101.com/r/H86FYL/1 for an illustration of what this regex will capture.

The previous tests used synthetic PATs that weren't reflective of observed patterns in generated PATs. Until gitlab-org/gitlab#335991 (comment 639062468) and https://gitlab.com/gitlab-com/gl-infra/infrastructure/-/issues/13902 are implemented, this may be the best technique available to identify GitLab PATs in as many contexts as possible.

Edited by Jamie Reid

Merge request reports