detect.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. package detect
  2. import (
  3. "bufio"
  4. "context"
  5. "fmt"
  6. "os"
  7. "runtime"
  8. "strings"
  9. "sync"
  10. "sync/atomic"
  11. "time"
  12. "github.com/zricethezav/gitleaks/v8/config"
  13. "github.com/zricethezav/gitleaks/v8/detect/codec"
  14. "github.com/zricethezav/gitleaks/v8/logging"
  15. "github.com/zricethezav/gitleaks/v8/regexp"
  16. "github.com/zricethezav/gitleaks/v8/report"
  17. ahocorasick "github.com/BobuSumisu/aho-corasick"
  18. "github.com/fatih/semgroup"
  19. "github.com/rs/zerolog"
  20. "github.com/spf13/viper"
  21. "golang.org/x/exp/maps"
  22. )
  23. const (
  24. gitleaksAllowSignature = "gitleaks:allow"
  25. chunkSize = 100 * 1_000 // 100kb
  26. // SlowWarningThreshold is the amount of time to wait before logging that a file is slow.
  27. // This is useful for identifying problematic files and tuning the allowlist.
  28. SlowWarningThreshold = 5 * time.Second
  29. )
  30. var (
  31. newLineRegexp = regexp.MustCompile("\n")
  32. isWindows = runtime.GOOS == "windows"
  33. )
  34. // Detector is the main detector struct
  35. type Detector struct {
  36. // Config is the configuration for the detector
  37. Config config.Config
  38. // Redact is a flag to redact findings. This is exported
  39. // so users using gitleaks as a library can set this flag
  40. // without calling `detector.Start(cmd *cobra.Command)`
  41. Redact uint
  42. // verbose is a flag to print findings
  43. Verbose bool
  44. // MaxDecodeDepths limits how many recursive decoding passes are allowed
  45. MaxDecodeDepth int
  46. // files larger than this will be skipped
  47. MaxTargetMegaBytes int
  48. // followSymlinks is a flag to enable scanning symlink files
  49. FollowSymlinks bool
  50. // NoColor is a flag to disable color output
  51. NoColor bool
  52. // IgnoreGitleaksAllow is a flag to ignore gitleaks:allow comments.
  53. IgnoreGitleaksAllow bool
  54. // commitMap is used to keep track of commits that have been scanned.
  55. // This is only used for logging purposes and git scans.
  56. commitMap map[string]bool
  57. // findingMutex is to prevent concurrent access to the
  58. // findings slice when adding findings.
  59. findingMutex *sync.Mutex
  60. // findings is a slice of report.Findings. This is the result
  61. // of the detector's scan which can then be used to generate a
  62. // report.
  63. findings []report.Finding
  64. // prefilter is a ahocorasick struct used for doing efficient string
  65. // matching given a set of words (keywords from the rules in the config)
  66. prefilter ahocorasick.Trie
  67. // a list of known findings that should be ignored
  68. baseline []report.Finding
  69. // path to baseline
  70. baselinePath string
  71. // gitleaksIgnore
  72. gitleaksIgnore map[string]struct{}
  73. // Sema (https://github.com/fatih/semgroup) controls the concurrency
  74. Sema *semgroup.Group
  75. // report-related settings.
  76. ReportPath string
  77. Reporter report.Reporter
  78. TotalBytes atomic.Uint64
  79. }
  80. // Fragment contains the data to be scanned
  81. type Fragment struct {
  82. // Raw is the raw content of the fragment
  83. Raw string
  84. Bytes []byte
  85. // FilePath is the path to the file, if applicable.
  86. // The path separator MUST be normalized to `/`.
  87. FilePath string
  88. SymlinkFile string
  89. // WindowsFilePath is the path with the original separator.
  90. // This provides a backwards-compatible solution to https://github.com/gitleaks/gitleaks/issues/1565.
  91. WindowsFilePath string `json:"-"` // TODO: remove this in v9.
  92. // CommitSHA is the SHA of the commit if applicable
  93. CommitSHA string
  94. // newlineIndices is a list of indices of newlines in the raw content.
  95. // This is used to calculate the line location of a finding
  96. newlineIndices [][]int
  97. }
  98. // NewDetector creates a new detector with the given config
  99. func NewDetector(cfg config.Config) *Detector {
  100. return &Detector{
  101. commitMap: make(map[string]bool),
  102. gitleaksIgnore: make(map[string]struct{}),
  103. findingMutex: &sync.Mutex{},
  104. findings: make([]report.Finding, 0),
  105. Config: cfg,
  106. prefilter: *ahocorasick.NewTrieBuilder().AddStrings(maps.Keys(cfg.Keywords)).Build(),
  107. Sema: semgroup.NewGroup(context.Background(), 40),
  108. }
  109. }
  110. // NewDetectorDefaultConfig creates a new detector with the default config
  111. func NewDetectorDefaultConfig() (*Detector, error) {
  112. viper.SetConfigType("toml")
  113. err := viper.ReadConfig(strings.NewReader(config.DefaultConfig))
  114. if err != nil {
  115. return nil, err
  116. }
  117. var vc config.ViperConfig
  118. err = viper.Unmarshal(&vc)
  119. if err != nil {
  120. return nil, err
  121. }
  122. cfg, err := vc.Translate()
  123. if err != nil {
  124. return nil, err
  125. }
  126. return NewDetector(cfg), nil
  127. }
  128. func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error {
  129. logging.Debug().Msgf("found .gitleaksignore file: %s", gitleaksIgnorePath)
  130. file, err := os.Open(gitleaksIgnorePath)
  131. if err != nil {
  132. return err
  133. }
  134. defer func() {
  135. // https://github.com/securego/gosec/issues/512
  136. if err := file.Close(); err != nil {
  137. logging.Warn().Msgf("Error closing .gitleaksignore file: %s\n", err)
  138. }
  139. }()
  140. scanner := bufio.NewScanner(file)
  141. replacer := strings.NewReplacer("\\", "/")
  142. for scanner.Scan() {
  143. line := strings.TrimSpace(scanner.Text())
  144. // Skip lines that start with a comment
  145. if line == "" || strings.HasPrefix(line, "#") {
  146. continue
  147. }
  148. // Normalize the path.
  149. // TODO: Make this a breaking change in v9.
  150. s := strings.Split(line, ":")
  151. switch len(s) {
  152. case 3:
  153. // Global fingerprint.
  154. // `file:rule-id:start-line`
  155. s[0] = replacer.Replace(s[0])
  156. case 4:
  157. // Commit fingerprint.
  158. // `commit:file:rule-id:start-line`
  159. s[1] = replacer.Replace(s[1])
  160. default:
  161. logging.Warn().Str("fingerprint", line).Msg("Invalid .gitleaksignore entry")
  162. }
  163. d.gitleaksIgnore[strings.Join(s, ":")] = struct{}{}
  164. }
  165. return nil
  166. }
  167. // DetectBytes scans the given bytes and returns a list of findings
  168. func (d *Detector) DetectBytes(content []byte) []report.Finding {
  169. return d.DetectString(string(content))
  170. }
  171. // DetectString scans the given string and returns a list of findings
  172. func (d *Detector) DetectString(content string) []report.Finding {
  173. return d.Detect(Fragment{
  174. Raw: content,
  175. })
  176. }
  177. // Detect scans the given fragment and returns a list of findings
  178. func (d *Detector) Detect(fragment Fragment) []report.Finding {
  179. if fragment.Bytes == nil {
  180. d.TotalBytes.Add(uint64(len(fragment.Raw)))
  181. }
  182. d.TotalBytes.Add(uint64(len(fragment.Bytes)))
  183. var (
  184. findings []report.Finding
  185. logger = func() zerolog.Logger {
  186. l := logging.With().Str("path", fragment.FilePath)
  187. if fragment.CommitSHA != "" {
  188. l = l.Str("commit", fragment.CommitSHA)
  189. }
  190. return l.Logger()
  191. }()
  192. )
  193. // check if filepath is allowed
  194. if fragment.FilePath != "" {
  195. // is the path our config or baseline file?
  196. if fragment.FilePath == d.Config.Path || (d.baselinePath != "" && fragment.FilePath == d.baselinePath) {
  197. logging.Trace().Msg("skipping file: matches config or baseline path")
  198. return findings
  199. }
  200. }
  201. // check if commit or filepath is allowed.
  202. if isAllowed, event := checkCommitOrPathAllowed(logger, fragment, d.Config.Allowlists); isAllowed {
  203. event.Msg("skipping file: global allowlist")
  204. return findings
  205. }
  206. // add newline indices for location calculation in detectRule
  207. fragment.newlineIndices = newLineRegexp.FindAllStringIndex(fragment.Raw, -1)
  208. // setup variables to handle different decoding passes
  209. currentRaw := fragment.Raw
  210. encodedSegments := []*codec.EncodedSegment{}
  211. currentDecodeDepth := 0
  212. decoder := codec.NewDecoder()
  213. for {
  214. // build keyword map for prefiltering rules
  215. keywords := make(map[string]bool)
  216. normalizedRaw := strings.ToLower(currentRaw)
  217. matches := d.prefilter.MatchString(normalizedRaw)
  218. for _, m := range matches {
  219. keywords[normalizedRaw[m.Pos():int(m.Pos())+len(m.Match())]] = true
  220. }
  221. for _, rule := range d.Config.Rules {
  222. if len(rule.Keywords) == 0 {
  223. // if no keywords are associated with the rule always scan the
  224. // fragment using the rule
  225. findings = append(findings, d.detectRule(fragment, currentRaw, rule, encodedSegments)...)
  226. continue
  227. }
  228. // check if keywords are in the fragment
  229. for _, k := range rule.Keywords {
  230. if _, ok := keywords[strings.ToLower(k)]; ok {
  231. findings = append(findings, d.detectRule(fragment, currentRaw, rule, encodedSegments)...)
  232. break
  233. }
  234. }
  235. }
  236. // increment the depth by 1 as we start our decoding pass
  237. currentDecodeDepth++
  238. // stop the loop if we've hit our max decoding depth
  239. if currentDecodeDepth > d.MaxDecodeDepth {
  240. break
  241. }
  242. // decode the currentRaw for the next pass
  243. currentRaw, encodedSegments = decoder.Decode(currentRaw, encodedSegments)
  244. // stop the loop when there's nothing else to decode
  245. if len(encodedSegments) == 0 {
  246. break
  247. }
  248. }
  249. return filter(findings, d.Redact)
  250. }
  251. // detectRule scans the given fragment for the given rule and returns a list of findings
  252. func (d *Detector) detectRule(fragment Fragment, currentRaw string, r config.Rule, encodedSegments []*codec.EncodedSegment) []report.Finding {
  253. var (
  254. findings []report.Finding
  255. logger = func() zerolog.Logger {
  256. l := logging.With().Str("rule-id", r.RuleID).Str("path", fragment.FilePath)
  257. if fragment.CommitSHA != "" {
  258. l = l.Str("commit", fragment.CommitSHA)
  259. }
  260. return l.Logger()
  261. }()
  262. )
  263. // check if commit or file is allowed for this rule.
  264. if isAllowed, event := checkCommitOrPathAllowed(logger, fragment, r.Allowlists); isAllowed {
  265. event.Msg("skipping file: rule allowlist")
  266. return findings
  267. }
  268. if r.Path != nil {
  269. if r.Regex == nil && len(encodedSegments) == 0 {
  270. // Path _only_ rule
  271. if r.Path.MatchString(fragment.FilePath) || (fragment.WindowsFilePath != "" && r.Path.MatchString(fragment.WindowsFilePath)) {
  272. finding := report.Finding{
  273. RuleID: r.RuleID,
  274. Description: r.Description,
  275. File: fragment.FilePath,
  276. SymlinkFile: fragment.SymlinkFile,
  277. Match: fmt.Sprintf("file detected: %s", fragment.FilePath),
  278. Tags: r.Tags,
  279. }
  280. return append(findings, finding)
  281. }
  282. } else {
  283. // if path is set _and_ a regex is set, then we need to check both
  284. // so if the path does not match, then we should return early and not
  285. // consider the regex
  286. if !(r.Path.MatchString(fragment.FilePath) || (fragment.WindowsFilePath != "" && r.Path.MatchString(fragment.WindowsFilePath))) {
  287. return findings
  288. }
  289. }
  290. }
  291. // if path only rule, skip content checks
  292. if r.Regex == nil {
  293. return findings
  294. }
  295. // if flag configure and raw data size bigger then the flag
  296. if d.MaxTargetMegaBytes > 0 {
  297. rawLength := len(currentRaw) / 1000000
  298. if rawLength > d.MaxTargetMegaBytes {
  299. logger.Debug().
  300. Int("size", rawLength).
  301. Int("max-size", d.MaxTargetMegaBytes).
  302. Msg("skipping fragment: size")
  303. return findings
  304. }
  305. }
  306. // use currentRaw instead of fragment.Raw since this represents the current
  307. // decoding pass on the text
  308. for _, matchIndex := range r.Regex.FindAllStringIndex(currentRaw, -1) {
  309. // Extract secret from match
  310. secret := strings.Trim(currentRaw[matchIndex[0]:matchIndex[1]], "\n")
  311. // For any meta data from decoding
  312. var metaTags []string
  313. currentLine := ""
  314. // Check if the decoded portions of the segment overlap with the match
  315. // to see if its potentially a new match
  316. if len(encodedSegments) > 0 {
  317. segments := codec.SegmentsWithDecodedOverlap(encodedSegments, matchIndex[0], matchIndex[1])
  318. if len(segments) == 0 {
  319. // This item has already been added to a finding
  320. continue
  321. }
  322. matchIndex = codec.AdjustMatchIndex(segments, matchIndex)
  323. metaTags = append(metaTags, codec.Tags(segments)...)
  324. currentLine = codec.CurrentLine(segments, currentRaw)
  325. } else {
  326. // Fixes: https://github.com/gitleaks/gitleaks/issues/1352
  327. // removes the incorrectly following line that was detected by regex expression '\n'
  328. matchIndex[1] = matchIndex[0] + len(secret)
  329. }
  330. // determine location of match. Note that the location
  331. // in the finding will be the line/column numbers of the _match_
  332. // not the _secret_, which will be different if the secretGroup
  333. // value is set for this rule
  334. loc := location(fragment, matchIndex)
  335. if matchIndex[1] > loc.endLineIndex {
  336. loc.endLineIndex = matchIndex[1]
  337. }
  338. finding := report.Finding{
  339. RuleID: r.RuleID,
  340. Description: r.Description,
  341. StartLine: loc.startLine,
  342. EndLine: loc.endLine,
  343. StartColumn: loc.startColumn,
  344. EndColumn: loc.endColumn,
  345. Line: fragment.Raw[loc.startLineIndex:loc.endLineIndex],
  346. Match: secret,
  347. Secret: secret,
  348. File: fragment.FilePath,
  349. SymlinkFile: fragment.SymlinkFile,
  350. Tags: append(r.Tags, metaTags...),
  351. }
  352. if !d.IgnoreGitleaksAllow && strings.Contains(finding.Line, gitleaksAllowSignature) {
  353. logger.Trace().
  354. Str("finding", finding.Secret).
  355. Msg("skipping finding: 'gitleaks:allow' signature")
  356. continue
  357. }
  358. if currentLine == "" {
  359. currentLine = finding.Line
  360. }
  361. // Set the value of |secret|, if the pattern contains at least one capture group.
  362. // (The first element is the full match, hence we check >= 2.)
  363. groups := r.Regex.FindStringSubmatch(finding.Secret)
  364. if len(groups) >= 2 {
  365. if r.SecretGroup > 0 {
  366. if len(groups) <= r.SecretGroup {
  367. // Config validation should prevent this
  368. continue
  369. }
  370. finding.Secret = groups[r.SecretGroup]
  371. } else {
  372. // If |secretGroup| is not set, we will use the first suitable capture group.
  373. for _, s := range groups[1:] {
  374. if len(s) > 0 {
  375. finding.Secret = s
  376. break
  377. }
  378. }
  379. }
  380. }
  381. // check entropy
  382. entropy := shannonEntropy(finding.Secret)
  383. finding.Entropy = float32(entropy)
  384. if r.Entropy != 0.0 {
  385. // entropy is too low, skip this finding
  386. if entropy <= r.Entropy {
  387. logger.Trace().
  388. Str("finding", finding.Secret).
  389. Float32("entropy", finding.Entropy).
  390. Msg("skipping finding: low entropy")
  391. continue
  392. }
  393. }
  394. // check if the result matches any of the global allowlists.
  395. if isAllowed, event := checkFindingAllowed(logger, finding, fragment, currentLine, d.Config.Allowlists); isAllowed {
  396. event.Msg("skipping finding: global allowlist")
  397. continue
  398. }
  399. // check if the result matches any of the rule allowlists.
  400. if isAllowed, event := checkFindingAllowed(logger, finding, fragment, currentLine, r.Allowlists); isAllowed {
  401. event.Msg("skipping finding: rule allowlist")
  402. continue
  403. }
  404. findings = append(findings, finding)
  405. }
  406. return findings
  407. }
  408. // AddFinding synchronously adds a finding to the findings slice
  409. func (d *Detector) AddFinding(finding report.Finding) {
  410. globalFingerprint := fmt.Sprintf("%s:%s:%d", finding.File, finding.RuleID, finding.StartLine)
  411. if finding.Commit != "" {
  412. finding.Fingerprint = fmt.Sprintf("%s:%s:%s:%d", finding.Commit, finding.File, finding.RuleID, finding.StartLine)
  413. } else {
  414. finding.Fingerprint = globalFingerprint
  415. }
  416. // check if we should ignore this finding
  417. logger := logging.With().Str("finding", finding.Secret).Logger()
  418. if _, ok := d.gitleaksIgnore[globalFingerprint]; ok {
  419. logger.Debug().
  420. Str("fingerprint", globalFingerprint).
  421. Msg("skipping finding: global fingerprint")
  422. return
  423. } else if finding.Commit != "" {
  424. // Awkward nested if because I'm not sure how to chain these two conditions.
  425. if _, ok := d.gitleaksIgnore[finding.Fingerprint]; ok {
  426. logger.Debug().
  427. Str("fingerprint", finding.Fingerprint).
  428. Msgf("skipping finding: fingerprint")
  429. return
  430. }
  431. }
  432. if d.baseline != nil && !IsNew(finding, d.Redact, d.baseline) {
  433. logger.Debug().
  434. Str("fingerprint", finding.Fingerprint).
  435. Msgf("skipping finding: baseline")
  436. return
  437. }
  438. d.findingMutex.Lock()
  439. d.findings = append(d.findings, finding)
  440. if d.Verbose {
  441. printFinding(finding, d.NoColor)
  442. }
  443. d.findingMutex.Unlock()
  444. }
  445. // Findings returns the findings added to the detector
  446. func (d *Detector) Findings() []report.Finding {
  447. return d.findings
  448. }
  449. // AddCommit synchronously adds a commit to the commit slice
  450. func (d *Detector) addCommit(commit string) {
  451. d.commitMap[commit] = true
  452. }
  453. // checkCommitOrPathAllowed evaluates |fragment| against all provided |allowlists|.
  454. //
  455. // If the match condition is "OR", only commit and path are checked.
  456. // Otherwise, if regexes or stopwords are defined this will fail.
  457. func checkCommitOrPathAllowed(
  458. logger zerolog.Logger,
  459. fragment Fragment,
  460. allowlists []*config.Allowlist,
  461. ) (bool, *zerolog.Event) {
  462. if fragment.FilePath == "" && fragment.CommitSHA == "" {
  463. return false, nil
  464. }
  465. for _, a := range allowlists {
  466. var (
  467. isAllowed bool
  468. allowlistChecks []bool
  469. commitAllowed, _ = a.CommitAllowed(fragment.CommitSHA)
  470. pathAllowed = a.PathAllowed(fragment.FilePath) || (fragment.WindowsFilePath != "" && a.PathAllowed(fragment.WindowsFilePath))
  471. )
  472. // If the condition is "AND" we need to check all conditions.
  473. if a.MatchCondition == config.AllowlistMatchAnd {
  474. if len(a.Commits) > 0 {
  475. allowlistChecks = append(allowlistChecks, commitAllowed)
  476. }
  477. if len(a.Paths) > 0 {
  478. allowlistChecks = append(allowlistChecks, pathAllowed)
  479. }
  480. // These will be checked later.
  481. if len(a.Regexes) > 0 {
  482. continue
  483. }
  484. if len(a.StopWords) > 0 {
  485. continue
  486. }
  487. isAllowed = allTrue(allowlistChecks)
  488. } else {
  489. isAllowed = commitAllowed || pathAllowed
  490. }
  491. if isAllowed {
  492. event := logger.Trace().Str("condition", a.MatchCondition.String())
  493. if commitAllowed {
  494. event.Bool("allowed-commit", commitAllowed)
  495. }
  496. if pathAllowed {
  497. event.Bool("allowed-path", pathAllowed)
  498. }
  499. return true, event
  500. }
  501. }
  502. return false, nil
  503. }
  504. // checkFindingAllowed evaluates |finding| against all provided |allowlists|.
  505. //
  506. // If the match condition is "OR", only regex and stopwords are run. (Commit and path should be handled separately).
  507. // Otherwise, all conditions are checked.
  508. //
  509. // TODO: The method signature is awkward. I can't think of a better way to log helpful info.
  510. func checkFindingAllowed(
  511. logger zerolog.Logger,
  512. finding report.Finding,
  513. fragment Fragment,
  514. currentLine string,
  515. allowlists []*config.Allowlist,
  516. ) (bool, *zerolog.Event) {
  517. for _, a := range allowlists {
  518. allowlistTarget := finding.Secret
  519. switch a.RegexTarget {
  520. case "match":
  521. allowlistTarget = finding.Match
  522. case "line":
  523. allowlistTarget = currentLine
  524. }
  525. var (
  526. checks []bool
  527. isAllowed bool
  528. commitAllowed bool
  529. commit string
  530. pathAllowed bool
  531. regexAllowed = a.RegexAllowed(allowlistTarget)
  532. containsStopword, word = a.ContainsStopWord(finding.Secret)
  533. )
  534. // If the condition is "AND" we need to check all conditions.
  535. if a.MatchCondition == config.AllowlistMatchAnd {
  536. // Determine applicable checks.
  537. if len(a.Commits) > 0 {
  538. commitAllowed, commit = a.CommitAllowed(fragment.CommitSHA)
  539. checks = append(checks, commitAllowed)
  540. }
  541. if len(a.Paths) > 0 {
  542. pathAllowed = a.PathAllowed(fragment.FilePath) || (fragment.WindowsFilePath != "" && a.PathAllowed(fragment.WindowsFilePath))
  543. checks = append(checks, pathAllowed)
  544. }
  545. if len(a.Regexes) > 0 {
  546. checks = append(checks, regexAllowed)
  547. }
  548. if len(a.StopWords) > 0 {
  549. checks = append(checks, containsStopword)
  550. }
  551. isAllowed = allTrue(checks)
  552. } else {
  553. isAllowed = regexAllowed || containsStopword
  554. }
  555. if isAllowed {
  556. event := logger.Trace().
  557. Str("finding", finding.Secret).
  558. Str("condition", a.MatchCondition.String())
  559. if commitAllowed {
  560. event.Str("allowed-commit", commit)
  561. }
  562. if pathAllowed {
  563. event.Bool("allowed-path", pathAllowed)
  564. }
  565. if regexAllowed {
  566. event.Bool("allowed-regex", regexAllowed)
  567. }
  568. if containsStopword {
  569. event.Str("allowed-stopword", word)
  570. }
  571. return true, event
  572. }
  573. }
  574. return false, nil
  575. }
  576. func allTrue(bools []bool) bool {
  577. for _, check := range bools {
  578. if !check {
  579. return false
  580. }
  581. }
  582. return true
  583. }