Token prefixes: Add support for client-side secret detection

What does this MR do and why?

This MR adds client-side secret detection for tokens with an instance prefix. Before this MR, the prefix was missing from the regex match. Tokens with an instance prefix, e.g. myinstance-glpat-abc were still caught, however they were only matched as glpat-abc. This MR adds the prefix to the regex, so that they will now be matched as myinstance-glpat-abc.

For full background, follow the discussion.

🛠️ with ❤️ at Siemens

References

Screenshots or screen recordings

without-instance with-instance

How to set up and validate locally

  1. Enable feature flag via rails c:
Feature.enable(:custom_prefix_for_all_token_types)
  1. Set an instance wide token prefix: Admin area > General > Account and limit > Instance token prefix, e.g. to instanceprefix
  2. Create a new token, e.g. a PAT.
  3. Submit a comment including the token. You should now see that the warning includes the full token with the prefix. Without this MR, you should see that only the part starting with glpat-.. is mentioned. You can also see the difference in the screenshot. The GitLab Runner token matches the full string, because it contains a very broad pattern.

MR acceptance checklist

MR Checklist ( @nwittstruck)

Related to #388379

Edited by Nicholas Wittstruck

Merge request reports

Loading