Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Experiment: allowlist expressions using CEL#1874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
rgmz wants to merge3 commits intogitleaks:master
base:master
Choose a base branch
Loading
fromrgmz:feat/allowlist-cel

Conversation

rgmz
Copy link
Contributor

@rgmzrgmz commentedMay 25, 2025
edited
Loading

Description:

This allows users to define custom expressions usinghttps://cel.dev/. I've provided two practical examples of this.

  1. Stricter Atlassian token detection, based on@CameronLonsdale's effort to reverse-engineer the checksum logic.
$echo'VALID_V1_JIRA_TOKEN: jORnHA8DuENu55HknpV9d04dINVALID_V1_JIRA_TOKEN: jORnHA8DuENu55hknpV9d04dVALID_V2_JIRA_TOKEN=ATATT3xFfGF0K3irG5tKKi-6u-wwaXQFeGwZ-IHR-hQ3CulkKtMSuteRQFfLZ6jihHThzZCg_UjnDt-4Wl_gIRf4zrZJs5JqaeuBhsfJ4W5GD6yGg3W7903gbvaxZPBjxIQQ7BgFDSkPS8oPispw4KLz56mdK-G6CIvLO6hHRrZHY0Q3tvJ6JxE=C63992E6INVALID_V2_JIRA_TOKEN=ATATT3xFfGF0K3irG5tKKi-6u-wwaXQFeGwZ-IHR-hQ3CulkKtMSuteRQFfLZ6jihHThzZCg_UjnDt-4Wl_gIRf4zrZJs5JqaeuBhsfJ4W5GD6yGg3W7903gbvaxZPBjxIQQ7BgFDSkPS8oPispw4KLz56mdK-G6CIvLO6hHRrZHY0Q3tvJ6JxE=D74003F7'> /tmp/jira.txt# Without expressions$ ./gitleaks dir /tmp/jira.txt --no-banner --verbose...9:35PM INF scanned~523 bytes (523 bytes)in 3.42ms9:35PM WRN leaks found: 4# With expressions$ ./gitleaks dir /tmp/jira.txt --no-banner --verbose --enable-rule=atlassian-api-token --experimental-expressions...9:36PM INF scanned~523 bytes (523 bytes)in 3.6ms9:36PM WRN leaks found: 2
  1. Thegeneric-api-key allowlist only tests "access"-related regexes whenaccess was detected in the fragment.

Checklist:

  • Does your PR pass tests?
  • Have you written new tests for your changes?
  • Have you lint your code locally prior to submission?

@rgmzrgmzforce-pushed thefeat/allowlist-cel branch fromc3cd042 toa34875cCompareMay 25, 2025 02:33
tps := utils.GenerateSampleSecrets("atlassian", secrets.NewSecret(utils.AlphaNumeric("24")))
tps = append(tps, utils.GenerateSampleSecrets("confluence", secrets.NewSecret(utils.AlphaNumeric("24")))...)
tps = append(tps, utils.GenerateSampleSecrets("jira", secrets.NewSecret(utils.AlphaNumeric("24")))...)
v1Secret := func() string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

v1?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This rule is a compound of two distinct formats. I wasn't sure what to call the "old" one.

// Compile the expression
if useExpression && a.Expression != "" {
// Build the environment: variables and functions available to the users.
// TODO: Is it safe to reuse this across multiple expressions?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would hope so 🤔

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

i.e., canenv be declared as a top-level variable instead of being declared for each whitelist?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

yep, correctomundo


// ExpressionAllowed returns the result of the predicate expression.
func (a *Allowlist) ExpressionAllowed(
// Miserable workaround to import-cycles.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

hmmm maybe it's timefinding got its own package. Outside of the scope for this PR though

rgmz reacted with thumbs up emoji
@@ -604,10 +607,18 @@ regexes = [
'''^[a-zA-Z_.-]+$''',
]
[[rules.allowlists]]
description = "Allowlist for Generic API Keys matching the `access` keyword"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If evaluating CEL is slower than regex, does this new allowlist actually benefit us?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Albeit, it's a good demonstration on the power of introducing CEL

Copy link
ContributorAuthor

@rgmzrgmzMay 25, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This occurred to me as well — though you're right, it was mostly for demonstration purposes. Rudimentary benchmarks show it to be faster.

Using expression

$ go generate ./...Checking finding: rA1wk0Y45YCufyfq10:58AM INF Evaluated expression duration="15.178µs"<<<Lazy initialization? The first call is much slower. 10:58AM INF Evaluated regex duration="1.633µs"Checking finding: e8e4df51-2054-49b0-ab1c-516ac95c691d10:58AM INF Evaluated expression duration="6.214µs"10:58AM INF Evaluated regex duration="1.663µs"Checking finding: 0736f5ef-7e88-499a-80cc-90c85d2a518010:58AM INF Evaluated expression duration="2.206µs"10:58AM INF Evaluated regex duration=746nsChecking finding: _LIBCPP_CONSTEXPR_AFTER_CXX1110:58AM INF Evaluated expression duration="2.54µs"10:58AM INF Evaluated regex duration="1.021µs"

Using combined regex

$ go generate ./...Checking finding: rA1wk0Y45YCufyfq11:01AM INF Evaluated regex duration="23.093µs"Checking finding: e8e4df51-2054-49b0-ab1c-516ac95c691d11:01AM INF Evaluated regex duration="27.992µs"Checking finding: 0736f5ef-7e88-499a-80cc-90c85d2a518011:01AM INF Evaluated regex duration="22.343µs"Checking finding: _LIBCPP_CONSTEXPR_AFTER_CXX1111:01AM INF Evaluated regex duration="23.505µs"

@rgmzrgmzforce-pushed thefeat/allowlist-cel branch from7580c5a to16381e6CompareMay 25, 2025 16:23
Allowlists: githubAllowlist,
Allowlists: []*config.Allowlist{
{
Expression: `secret.substring(34) != base62encode(crc32(secret.substring(4, 34)))`,
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@zricethezav@bplaxco I added areally sloppy expression to validate the checksum of GitHubghp_ tokens.

A 32 bit checksum in the last 6 digits of each token strikes the optimal balance between keeping the random token portion at a consistent entropy and enough confidence in the checksum. We start the implementation with a CRC32 algorithm, a standard checksum algorithm. We then encode the result with a Base62 implementation, using leading zeros for padding as needed.
https://github.blog/engineering/platform-security/behind-githubs-new-authentication-token-formats/

@rgmzrgmzforce-pushed thefeat/allowlist-cel branch from98969b5 to04dbec5CompareJune 1, 2025 17:13
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@zricethezavzricethezavzricethezav left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@rgmz@zricethezav

[8]ページ先頭

©2009-2025 Movatter.jp