detect.go 19 KB

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