replace std library regex engine with go-re2 (#1669)

This commit is contained in:
ahrav authored and GitHub committed 2024-12-20 09:53:01 -06:00
1 parent 906085fba6
commit a91c6717a0
44 files changed
+92 -77

No files matched your search

+1 -1
View File
@@ -2,9 +2,9 @@ package base
import (
"fmt"
"regexp"
"strings"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config"
)
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
+2 -1
View File
@@ -2,7 +2,8 @@ package rules
import (
"fmt"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -2,7 +2,7 @@ package rules
import (
"fmt"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+8 -8
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
@@ -127,7 +127,7 @@ func GenericCredential() *config.Rule {
`[DEBUG] org.neo4j.neo4j-graphdb-api:jar:3.5.12:test`,
`apiUrl=apigee.corpint.com`,
// TODO: Jetbrains IML files (requires line-level allowlist).
//`<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.directory.api:api-asn1-api:1.0.0-M20" level="projcet" />`
// `<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.directory.api:api-asn1-api:1.0.0-M20" level="projcet" />`
// Auth
`author = "james.fake@ymail.com",`,
@@ -156,9 +156,9 @@ func GenericCredential() *config.Rule {
`minisat-master-keying:x64-uwp=fail`,
`IceSSL.KeyFile=s_rsa1024_priv.pem`,
`"bucket_key": "SalesResults-1.2"`,
//`<TAR key="REF_ID_923.properties" value="/opts/config/alias/"/>`,
// `<TAR key="REF_ID_923.properties" value="/opts/config/alias/"/>`,
`<key tag="SecurityIdentifier" name="SecurityIdentifier" type="STRING" />`,
//`packageKey":` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
// `packageKey":` + newPlausibleSecret(`[a-zA-Z0-9\-_.=]{30}`),
`schemaKey = 'DOC_Vector_5_32'`,
`sequenceKey = "18"`,
`app.keystore.file=env/cert.p12`,
@@ -166,15 +166,15 @@ func GenericCredential() *config.Rule {
` doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;`,
`o.keySelector=n,o.haKey=!1,`,
// TODO: Requires line-level allowlists.
//`<add key="SchemaTable" value="G:\SchemaTable.xml" />`,
// `<add key="SchemaTable" value="G:\SchemaTable.xml" />`,
// `secret:
//secretName: app-decryption-secret
//items:
// secretName: app-decryption-secret
// items:
// - key: app-k8s.yml
// path: app-k8s.yml`,
// TODO: https://learn.microsoft.com/en-us/windows/apps/design/style/xaml-theme-resources
//`<Color x:Key="NormalBrushGradient1">#FFBAE4FF</Color>`,
// `<Color x:Key="NormalBrushGradient1">#FFBAE4FF</Color>`,
// Password
`password combination.
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config"
+2 -1
View File
@@ -2,7 +2,8 @@ package rules
import (
"fmt"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -3,8 +3,8 @@ package rules
import (
b64 "encoding/base64"
"fmt"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
+5 -4
View File
@@ -2,7 +2,8 @@ package rules
import (
"fmt"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config"
@@ -42,7 +43,7 @@ func KubernetesSecret() *config.Rule {
regexp.MustCompile(`[\w.-]+:(?:[ \t]*(?:\||>[-+]?)\s+)?[ \t]*(?:\{\{[ \t\w"|$:=,.-]+}}|""|'')`),
// TODO: Requires multiple allowlists to target match.
// Avoid overreach between directives.
//regexp.MustCompile(`(kind:(.|\s)+\n---\n(.|\s)+\bdata:|data:(.|\s)+\n---\n(.|\s)+\bkind:)`),
// regexp.MustCompile(`(kind:(.|\s)+\n---\n(.|\s)+\bdata:|data:(.|\s)+\n---\n(.|\s)+\bkind:)`),
},
},
},
@@ -250,9 +251,9 @@ type: Opaque
// name: mysecret
// creationPolicy: Owner
//
//---
// ---
//
//kind: ConfigMap
// kind: ConfigMap
// data:
// conversionStrategy: Default
// decodingStrategy: None
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -2,7 +2,7 @@ package rules
import (
"encoding/base64"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
+1 -1
View File
@@ -2,7 +2,7 @@ package rules
import (
"fmt"
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+1 -1
View File
@@ -1,7 +1,7 @@
package rules
import (
"regexp"
regexp "github.com/wasilibs/go-re2"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
"github.com/zricethezav/gitleaks/v8/config"
+25 -24
View File
@@ -6,8 +6,9 @@ package utils
import (
"fmt"
"regexp"
"strings"
regexp "github.com/wasilibs/go-re2"
)
const (
@@ -92,20 +93,20 @@ func GenerateSampleSecrets(identifier string, secret string) []string {
"ini - unquoted2": "{i}Token = {s}",
// JSON
"json - string": "{\n \"{i}_token\": \"{s}\"\n}",
//TODO: "json - escaped string": "\\{\n \\\"{i}_token\\\": \\\"{s}\\\"\n\\}",
//TODO: "json - string key/value": "{\n \"name\": \"{i}_token\",\n \"value\": \"{s}\"\n}",
// TODO: "json - escaped string": "\\{\n \\\"{i}_token\\\": \\\"{s}\\\"\n\\}",
// TODO: "json - string key/value": "{\n \"name\": \"{i}_token\",\n \"value\": \"{s}\"\n}",
// XML
//TODO: "xml - element": "<{i}Token>{s}</{i}Token>",
// TODO: "xml - element": "<{i}Token>{s}</{i}Token>",
"xml - element multiline": "<{i}Token>\n {s}\n</{i}Token>",
//TODO: "xml - attribute": "<entry name=\"{i}Token\" value=\"{s}\" />",
//TODO: "xml - key/value elements": "<entry>\n <name=\"{i}Token\" />\n <value=\"{s}\" />\n</entry>",
// TODO: "xml - attribute": "<entry name=\"{i}Token\" value=\"{s}\" />",
// TODO: "xml - key/value elements": "<entry>\n <name=\"{i}Token\" />\n <value=\"{s}\" />\n</entry>",
// YAML
"yaml - singleline - unquoted": "{i}_token: {s}",
"yaml - singleline - single quote": "{i}_token: '{s}'",
"yaml - singleline - double quote": "{i}_token: \"{s}\"",
//TODO: "yaml - multiline - literal": "{i}_token: |\n {s}",
//TODO: "yaml - multiline - folding": "{i}_token: >\n {s}",
//"": "",
// TODO: "yaml - multiline - literal": "{i}_token: |\n {s}",
// TODO: "yaml - multiline - folding": "{i}_token: >\n {s}",
// "": "",
// Programming Languages
"C#": `string {i}Token = "{s}";`,
@@ -113,26 +114,26 @@ func GenerateSampleSecrets(identifier string, secret string) []string {
"go - short": `{i}Token := "{s}"`,
"go - backticks": "{i}Token := `{s}`",
"java": "String {i}Token = \"{s}\";",
//TODO: "java - escaped quotes": `config.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"JDOE35\" {i}Token=\"{s}\""`,
//TODO:"kotlin - type": "var {i}Token: string = \"{s}\"",
// TODO: "java - escaped quotes": `config.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"JDOE35\" {i}Token=\"{s}\""`,
// TODO:"kotlin - type": "var {i}Token: string = \"{s}\"",
"kotlin - notype": "var {i}Token = \"{s}\"",
"php - string concat": `${i}Token .= "{s}"`,
//TODO: "php - null coalesce": `${i}Token ??= "{s}"`,
// TODO: "php - null coalesce": `${i}Token ??= "{s}"`,
"python - single quote": "{i}Token = '{s}'",
"python - double quote": `{i}Token = "{s}"`,
//"": "",
// "": "",
// Miscellaneous
//TODO: "url - basic auth": `https://{i}:{s}@example.com/`,
//TODO: "url - query parameter": "https://example.com?{i}Token={s}&fooBar=baz",
//TODO: "comment - slash": "//{s} is the password",
//TODO: "comment - slash multiline": "/*{s} is the password",
//TODO: "comment - hashtag": "#{s} is the password",
//TODO: "comment - semicolon": ";{s} is the password",
//TODO: "csv - unquoted": `{i}Token,{s},`,
// TODO: "url - basic auth": `https://{i}:{s}@example.com/`,
// TODO: "url - query parameter": "https://example.com?{i}Token={s}&fooBar=baz",
// TODO: "comment - slash": "//{s} is the password",
// TODO: "comment - slash multiline": "/*{s} is the password",
// TODO: "comment - hashtag": "#{s} is the password",
// TODO: "comment - semicolon": ";{s} is the password",
// TODO: "csv - unquoted": `{i}Token,{s},`,
"logstash": " \"{i}Token\" => \"{s}\"",
//TODO: "sql - tabular": "|{s}|",
//TODO: "sql": "",
// TODO: "sql - tabular": "|{s}|",
// TODO: "sql": "",
// Makefile
// See: https://github.com/gitleaks/gitleaks/pull/1191
@@ -141,9 +142,9 @@ func GenerateSampleSecrets(identifier string, secret string) []string {
"make - shell assignment": "{i}_TOKEN ::= \"{s}\"",
"make - evaluated shell assignment": "{i}_TOKEN :::= \"{s}\"",
"make - conditional assignment": "{i}_TOKEN ?= \"{s}\"",
//TODO: "make - append": "{i}_TOKEN += \"{s}\"",
// TODO: "make - append": "{i}_TOKEN += \"{s}\"",
//"": "",
// "": "",
}
replacer := strings.NewReplacer("{i}", identifier, "{s}", secret)