File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313
1414namespace CaptainHook \Secrets ;
1515
16- use CaptainHook \Secrets \Detector \Result ;
1716use CaptainHook \Secrets \Regex \Supplier ;
1817use RuntimeException ;
1918
@@ -98,7 +97,7 @@ public function useRegex(string ...$regularExpressions): self
9897 * Detect secrets in string
9998 *
10099 * @param string $content
101- * @return \CaptainHook\Secrets\Detector\ Result
100+ * @return \CaptainHook\Secrets\Result
102101 */
103102 public function detectIn (string $ content ): Result
104103 {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of CaptainHook Secrets.
5+ *
6+ * (c) Sebastian Feldmann <sf@sebastian-feldmann.info>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ declare (strict_types=1 );
13+
14+ namespace CaptainHook \Secrets \Regex ;
15+
16+ /**
17+ * Grouped Interface
18+ *
19+ * @package CaptainHook-Secrets
20+ * @author Sebastian Feldmann <sf@sebastian-feldmann.info>
21+ * @link https://github.com/captainhookphp/secrets
22+ * @since Class available since Release 0.9.4
23+ */
24+ interface Grouped extends Supplier
25+ {
26+ /**
27+ * Returns the capture group index of the potential password
28+ *
29+ * @return array<int>
30+ */
31+ public function indexes (): array ;
32+ }
Original file line number Diff line number Diff line change @@ -46,11 +46,11 @@ public function patterns(): array
4646 // AWS secrets, keys, access token
4747 '# ' . Util::OPTIONAL_QUOTE . self ::AWS . '(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key) '
4848 . Util::OPTIONAL_QUOTE . Util::CONNECT
49- . Util::OPTIONAL_QUOTE . '[A-Za-z0-9/ \\+=]{40} ' . Util::OPTIONAL_QUOTE . '# ' ,
49+ . Util::OPTIONAL_QUOTE . '( [A-Za-z0-9/ \\+=]{40}) ' . Util::OPTIONAL_QUOTE . '# ' ,
5050
5151 // AWS account id
5252 '# ' . Util::OPTIONAL_QUOTE . self ::AWS . '(ACCOUNT|account|Account)_?(ID|id|Id)? ' . Util::OPTIONAL_QUOTE
53- . Util::CONNECT . Util::OPTIONAL_QUOTE . '[0-9]{4} \\-?[0-9]{4} \\-?[0-9]{4} ' . Util::OPTIONAL_QUOTE . '# ' ,
53+ . Util::CONNECT . Util::OPTIONAL_QUOTE . '( [0-9]{4} \\-?[0-9]{4} \\-?[0-9]{4}) ' . Util::OPTIONAL_QUOTE . '# ' ,
5454 ];
5555 }
5656}
Original file line number Diff line number Diff line change @@ -36,16 +36,16 @@ public function patterns(): array
3636 {
3737 return [
3838 // Personal Access Token (Classic)
39- '# ' . Util::OPTIONAL_QUOTE . 'ghp_[a-zA-Z0-9]{36} ' . Util::OPTIONAL_QUOTE . '# ' ,
39+ '# ' . Util::OPTIONAL_QUOTE . '( ghp_[a-zA-Z0-9]{36}) ' . Util::OPTIONAL_QUOTE . '# ' ,
4040
4141 // Personal Access Token (Fine-Grained)
42- '# ' . Util::OPTIONAL_QUOTE . 'github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59} ' . Util::OPTIONAL_QUOTE . '# ' ,
42+ '# ' . Util::OPTIONAL_QUOTE . '( github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}) ' . Util::OPTIONAL_QUOTE . '# ' ,
4343
4444 // User-To-Server Access Token
45- '# ' . Util::OPTIONAL_QUOTE . 'ghu_[a-zA-Z0-9]{36} ' . Util::OPTIONAL_QUOTE . '# ' ,
45+ '# ' . Util::OPTIONAL_QUOTE . '( ghu_[a-zA-Z0-9]{36}) ' . Util::OPTIONAL_QUOTE . '# ' ,
4646
4747 // Server-To-Server Access Token
48- '# ' . Util::OPTIONAL_QUOTE . 'ghs_[a-zA-Z0-9]{36} ' . Util::OPTIONAL_QUOTE . '# ' ,
48+ '# ' . Util::OPTIONAL_QUOTE . '( ghs_[a-zA-Z0-9]{36}) ' . Util::OPTIONAL_QUOTE . '# ' ,
4949 ];
5050 }
5151}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public function patterns(): array
3636 {
3737 return [
3838 // API Key
39- '# ' . Util::OPTIONAL_QUOTE . 'AIza[0-9A-Za-z\-_]{35} ' . Util::OPTIONAL_QUOTE . '# ' ,
39+ '# ' . Util::OPTIONAL_QUOTE . '( AIza[0-9A-Za-z\-_]{35}) ' . Util::OPTIONAL_QUOTE . '# ' ,
4040 ];
4141 }
4242}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of CaptainHook Secrets.
5+ *
6+ * (c) Sebastian Feldmann <sf@sebastian-feldmann.info>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace CaptainHook \Secrets \Regex \Supplier ;
13+
14+ use CaptainHook \Secrets \Regex \Grouped ;
15+
16+ /**
17+ * Find any possible string assignment in a php file
18+ *
19+ * Finds:
20+ * - foo = "string"
21+ * - foo = string
22+ */
23+ class Ini implements Grouped
24+ {
25+ /**
26+ * Returns a list of patterns to check
27+ *
28+ * @return array<string>
29+ */
30+ public function patterns (): array
31+ {
32+ return [
33+ '#= \\s*("?)([^\n]*) \\1+ \\s*#i ' ,
34+ ];
35+ }
36+
37+ /**
38+ * Return capture group to access the password
39+ *
40+ * @return array<int>
41+ */
42+ public function indexes (): array
43+ {
44+ return [2 ];
45+ }
46+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of CaptainHook Secrets.
5+ *
6+ * (c) Sebastian Feldmann <sf@sebastian-feldmann.info>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace CaptainHook \Secrets \Regex \Supplier ;
13+
14+ use CaptainHook \Secrets \Regex \Grouped ;
15+
16+ /**
17+ * Find any possible string assignment in a json file
18+ *
19+ * Finds:
20+ * - "foo": "string"
21+ */
22+ class Json implements Grouped
23+ {
24+ /**
25+ * Returns a list of patterns to check
26+ *
27+ * @return array<string>
28+ */
29+ public function patterns (): array
30+ {
31+ return [
32+ // detecting any string assignment
33+ '#: \\s* ' . Util::QUOTE . '(.*?) ' . Util::QUOTE . '#i ' ,
34+ ];
35+ }
36+
37+ /**
38+ * Return capture group to access the password
39+ *
40+ * @return array<int>
41+ */
42+ public function indexes (): array
43+ {
44+ return [2 ];
45+ }
46+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of CaptainHook Secrets.
5+ *
6+ * (c) Sebastian Feldmann <sf@sebastian-feldmann.info>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace CaptainHook \Secrets \Regex \Supplier ;
13+
14+ use CaptainHook \Secrets \Regex \Grouped ;
15+
16+ /**
17+ * Find any possible string assignment in a php file
18+ *
19+ * Finds:
20+ * - $foo = "string"
21+ * - $foo = ["foo" => "string"]
22+ */
23+ class PHP implements Grouped
24+ {
25+ /**
26+ * Returns a list of patterns to check
27+ *
28+ * @return array<string>
29+ */
30+ public function patterns (): array
31+ {
32+ return [
33+ // detecting any string assignment
34+ // = "some string", => 'some-string' return 'some-string
35+ '#(=>?|return) \\s* ' . Util::QUOTE . '(.*?) ' . Util::QUOTE . '#i ' ,
36+ ];
37+ }
38+
39+ /**
40+ * Return capture group to access the password
41+ *
42+ * @return array<int>
43+ */
44+ public function indexes (): array
45+ {
46+ return [3 ];
47+ }
48+ }
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public function patterns(): array
3737 return [
3838 // Generic passwords
3939 '#password ' . Util::OPTIONAL_QUOTE . Util::CONNECT . Util::OPTIONAL_QUOTE
40- . '[a-z \\-_ \\#/ \\+0-9]{16,} ' . Util::OPTIONAL_QUOTE . '#i ' ,
40+ . '( [a-z \\-_ \\#/ \\+0-9]{16,}) ' . Util::OPTIONAL_QUOTE . '#i ' ,
4141 ];
4242 }
4343}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public function patterns(): array
3636 {
3737 return [
3838 // Standard API Key & Restricted API Key
39- '# ' . Util::OPTIONAL_QUOTE . 'sk_live_[0-9a-z]{24} ' . Util::OPTIONAL_QUOTE . '# ' ,
39+ '# ' . Util::OPTIONAL_QUOTE . '( sk_live_[0-9a-z]{24}) ' . Util::OPTIONAL_QUOTE . '# ' ,
4040 ];
4141 }
4242}
You can’t perform that action at this time.
0 commit comments