introducing GitLab Plugin analogous to GitHubTokenDetector #782
+198
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As (partially) described on:
(I have no experience with Ruby/Rails, but figured out most of the token form from the code and parts from the issues referenced above and can confirm with the 'official'
gitleaks.toml
and the current GitLab version.)Tokens
There are 2 main ways to create tokens in GitLab:
Devise.friendly_token(N)
(orSecureRandom.urlsafe_base64
ref )return a base64 URL-safe (-'friendly') string that may contain underscores or dashes_
/-
. This method is used for the common tokens like Project Access Tokens . Those are typically of the form:glpat-[a-zA-Z_\-]{20}
, ie. ~20 char token 'suffix' with a set of prefixes separated by-
, as documented on the site referenced above.E.g.:
glpat-xXy_yyyZxy2892-28-AB
.>= 50
: code, teststhe
SecureRandom
lib is used in different ways for different types of token, sometimes it's encoded into hex (base-16), sometimes base-64, but not necessarily URL-friendly, etc. These don't necessarily contain-
/_
.SecureRandom.hex(20)
, 40 (not 20) hexadecimal characters, so no-
/_
, just[a-f0-9]
e.g.glptt-be8f1262d76a3bef8397633d277629ab78582e47
SecureRandom.hex(32)
SecureRandom.hex.to_i(16).to_s(36)
🤷I've decided to go with 20 to 50 chars per token and
[a-zA-Z_\-]
- not only hex - to be on the safe side, since the implementation or GitLab settings may change etc.Feature: Plugin for GitLab tokens with a certain prefix contained in the documented prefix-list.
We only found GitHub. :)
Strings like
glpat-XYXYXYXYXY
,gldt-XYXYXYXYXY
andglagent-XYXYXYX...
get flagged as well.no