detect-secrets 0.0.0-development
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/config.json +11 -0
- package/.github/.markdownlint.yml +9 -0
- package/.github/CODE_OF_CONDUCT.md +73 -0
- package/.github/ISSUE_TEMPLATE/1-bug-report.md +44 -0
- package/.github/ISSUE_TEMPLATE/2-feature-request.md +19 -0
- package/.github/ISSUE_TEMPLATE/3-help.md +8 -0
- package/.github/ISSUE_TEMPLATE.md +11 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +44 -0
- package/.github/dependabot.yml +59 -0
- package/.github/labeler.yml +20 -0
- package/.github/workflows/automerge.yml +39 -0
- package/.github/workflows/ci.yml +38 -0
- package/.github/workflows/labeler.yml +14 -0
- package/.github/workflows/links-checker-schedule.yml +43 -0
- package/.github/workflows/lock-threads.yml +34 -0
- package/.github/workflows/markdown-lint.yml +29 -0
- package/.github/workflows/release.yml +43 -0
- package/.github/workflows/repo-init.yml +37 -0
- package/.markdownlintignore +16 -0
- package/.prettierrc.js +9 -0
- package/CONTRIBUTING.md +74 -0
- package/LICENSE +191 -0
- package/README.md +100 -0
- package/__tests__/cli.test.js +46 -0
- package/__tests__/cli.unit.test.js +37 -0
- package/__tests__/executeStrategy.test.js +69 -0
- package/__tests__/isExecutableAvailableInPath.test.js +17 -0
- package/bin/detect-secrets-launcher.js +45 -0
- package/jsdoc.json +19 -0
- package/package.json +196 -0
- package/src/cli.js +26 -0
- package/src/strategies.js +63 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for taking the time to contribute! Issues, ideas, and PRs are all welcome.
|
|
4
|
+
The notes below are guidelines to help your contribution land smoothly. If in doubt, open the thing anyway and we'll figure it out together.
|
|
5
|
+
|
|
6
|
+
## Opening an issue
|
|
7
|
+
|
|
8
|
+
A good issue gives us enough to reproduce or understand the ask. Useful things to include:
|
|
9
|
+
|
|
10
|
+
- **For bugs:** what you expected, what actually happened, and the shortest repro you can manage. Versions (runtime, OS, package) and stack traces help.
|
|
11
|
+
- **For features:** the problem you're trying to solve, not just the solution you have in mind. A concrete example of how you'd use it is gold.
|
|
12
|
+
|
|
13
|
+
A quick search of existing issues helps avoid duplicates, but don't agonize over it.
|
|
14
|
+
|
|
15
|
+
## Proposing a PR
|
|
16
|
+
|
|
17
|
+
PRs are expected to meet a few baseline requirements before review:
|
|
18
|
+
|
|
19
|
+
- **Tests are required** for any behavior change, new features need new tests, bug fixes need a regression test that fails without the fix.
|
|
20
|
+
- **Existing tests must pass** locally and in CI. Don't disable or skip tests to make a PR green.
|
|
21
|
+
- **Coverage should not regress.** If your change drops coverage meaningfully, add tests or explain why in the PR description.
|
|
22
|
+
- **Linters and type checks must pass.** Run them locally before pushing; CI will reject otherwise.
|
|
23
|
+
- **One logical change per PR.** Refactors, formatting churn, and unrelated fixes belong in separate PRs, it makes review and revert sane.
|
|
24
|
+
- **Describe what and why.** A PR title and a few lines of context go a long way, reviewers shouldn't have to reverse-engineer your intent from the diff.
|
|
25
|
+
- **Link the issue you're closing.** If your PR resolves an open issue, include a `Related issues` section in the description with `Fixes: #<issue-number>` (or `Closes: #<issue-number>`) so GitHub auto-closes it on merge.
|
|
26
|
+
- **Breaking changes need a heads-up** in the PR description, plus a migration note for users.
|
|
27
|
+
|
|
28
|
+
Large or speculative changes: open an issue first to align on direction before investing time.
|
|
29
|
+
|
|
30
|
+
## Commit guidelines
|
|
31
|
+
|
|
32
|
+
This project follows [Conventional Commits](https://www.conventionalcommits.org/). The format is:
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
<type>(<optional scope>): <short summary>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Common types:
|
|
39
|
+
|
|
40
|
+
- `feat:` — a new feature
|
|
41
|
+
- `fix:` — a bug fix
|
|
42
|
+
- `docs:` — documentation only
|
|
43
|
+
- `refactor:` — code change that neither fixes a bug nor adds a feature
|
|
44
|
+
- `test:` — adding or fixing tests
|
|
45
|
+
- `chore:` — tooling, build, dependencies
|
|
46
|
+
- `perf:` — performance improvement
|
|
47
|
+
|
|
48
|
+
Examples:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
feat: support multiple input files
|
|
52
|
+
fix(parser): handle empty input gracefully
|
|
53
|
+
docs: clarify install instructions
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Breaking changes: add `!` after the type (`feat!: ...`) and explain the break in the commit body.
|
|
57
|
+
|
|
58
|
+
This format drives changelog generation and release automation, so it matters more than the average commit-style guide.
|
|
59
|
+
|
|
60
|
+
## Local development
|
|
61
|
+
|
|
62
|
+
1. Fork and clone the repository.
|
|
63
|
+
2. Install dependencies using the project's package manager (see `package.json`, or equivalent).
|
|
64
|
+
3. Run the test suite to confirm a clean baseline before making changes.
|
|
65
|
+
4. Run the linter and type checker (if configured) the same way.
|
|
66
|
+
5. Make your change on a feature branch, commit using the format above, and open a PR.
|
|
67
|
+
|
|
68
|
+
If any of the above doesn't work on a fresh checkout, that's a bug, please open an issue.
|
|
69
|
+
|
|
70
|
+
## For automated agents
|
|
71
|
+
|
|
72
|
+
If you are an AI coding agent or automated bot opening a PR, please add 🤖🤖🤖 to the end of the PR title. This helps maintainers triage agent-authored contributions and is a baseline expectation for this repo — PRs without the marker that turn out to be automated may be closed without review.
|
|
73
|
+
|
|
74
|
+
The same applies to issues: prefix the title with 🤖🤖🤖 if it was opened by an agent on your behalf.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
https://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2019 Liran Tal <liran.tal@gmail.com>.
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<p align="center"><h1 align="center">
|
|
2
|
+
detect-secrets
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
A developer-friendly secrets detection tool for CI and pre-commit hooks
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.org/package/detect-secrets"><img src="https://badgen.net/npm/v/detect-secrets" alt="npm version"/></a>
|
|
11
|
+
<a href="https://www.npmjs.org/package/detect-secrets"><img src="https://badgen.net/npm/license/detect-secrets" alt="license"/></a>
|
|
12
|
+
<a href="https://www.npmjs.org/package/detect-secrets"><img src="https://badgen.net/npm/dt/detect-secrets" alt="downloads"/></a>
|
|
13
|
+
<a href="https://github.com/lirantal/detect-secrets/actions/workflows/ci.yml"><img src="https://github.com/lirantal/detect-secrets/actions/workflows/ci.yml/badge.svg?branch=master" alt="build"/></a>
|
|
14
|
+
<a href="https://codecov.io/gh/lirantal/detect-secrets"><img src="https://badgen.net/codecov/c/github/lirantal/detect-secrets" alt="codecov"/></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
# About
|
|
18
|
+
|
|
19
|
+
The `detect-secrets` npm package is a Node.js-based wrapper for Yelp's [detect-secrets](https://github.com/Yelp/detect-secrets) tool that aims to provide an accessible and developer-friendly method of introducing secrets detection in pre-commit hooks.
|
|
20
|
+
|
|
21
|
+
Yelp's detect-secrets is based on Python and requires explicit installation from developers. Moreover, its installation may be challenging in different operating systems. `detect-secrets` aims to alleviate this challenge by:
|
|
22
|
+
|
|
23
|
+
1. Attempt to locate Yelp's detect-secrets tool, and if it exists in the path to execute it.
|
|
24
|
+
|
|
25
|
+
If it fails it continues to:
|
|
26
|
+
|
|
27
|
+
2. Attempt to locate the docker binary and if it exists it will download and execute the docker container for [lirantal/detect-secrets](https://github.com/lirantal/docker-detect-secrets) which has Yelp's detect-secrets inside the image.
|
|
28
|
+
|
|
29
|
+
If this fails as well:
|
|
30
|
+
|
|
31
|
+
3. Exit with a warning message
|
|
32
|
+
|
|
33
|
+
--
|
|
34
|
+
|
|
35
|
+
The above described fallback strategy is used to find an available method of executing the detect-secrets tool to protect the developer from leaking secrets into source code control.
|
|
36
|
+
|
|
37
|
+
# Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install --save detect-secrets
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This will expose `detect-secrets-launcher` Node.js executable file.
|
|
44
|
+
|
|
45
|
+
Another way to invoke it is with npx which will download and execute the detect-secrets wrapper on the fly:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx detect-secrets [arguments]
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
# Usage
|
|
52
|
+
|
|
53
|
+
If you're using `husky` to manage pre-commit hooks configuration, then enabling secrets detection is as simple as adding another hook entry.
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
"husky": {
|
|
57
|
+
"hooks": {
|
|
58
|
+
"pre-commit": "detect-secrets-launcher src/*"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
If you're using `husky` and `lint-staged` to manage pre-commit hooks configuration and running static code analysis on staged files, then enabling secrets detection is as simple as adding another lint-staged entry.
|
|
64
|
+
|
|
65
|
+
A typical setup will look like this as an example:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
"husky": {
|
|
69
|
+
"hooks": {
|
|
70
|
+
"pre-commit": "lint-staged"
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
"lint-staged": {
|
|
74
|
+
"linters": {
|
|
75
|
+
"**/*.js": [
|
|
76
|
+
"detect-secrets-launcher --baseline .secrets-baseline"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
If you're not using a baseline file (it is created using Yelp's server-side detect-secrets tool) then you can simply omit this out and keep it as simple as `detect-secrets-launcher`.
|
|
83
|
+
|
|
84
|
+
# Example
|
|
85
|
+
|
|
86
|
+
To scan the `index.js` file within a repository for the potential of leaked secrets inside it run the following:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
detect-secrets-launcher index.js
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Note that `index.js` has to be staged and versioned control. Any other plain file that is not known to git will not be scanned.
|
|
93
|
+
|
|
94
|
+
# Contributing
|
|
95
|
+
|
|
96
|
+
Please consult [CONTIRBUTING](./CONTRIBUTING.md) for guidelines on contributing to this project.
|
|
97
|
+
|
|
98
|
+
# Author
|
|
99
|
+
|
|
100
|
+
**detect-secrets** © [Liran Tal](https://github.com/lirantal), Released under the [Apache-2.0](./LICENSE) License.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* eslint-disable security/detect-child-process */
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
const cli = require('../src/cli')
|
|
5
|
+
|
|
6
|
+
describe('detect-secrets-launcher CLI', () => {
|
|
7
|
+
test('when successful to spawn detect-secrets-hook should use exit code 1', () => {
|
|
8
|
+
const executableStrategies = [
|
|
9
|
+
{
|
|
10
|
+
type: 'ls',
|
|
11
|
+
filePath: 'ls'
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
const result = cli.start(executableStrategies)
|
|
16
|
+
expect(result.strategyExitCode).toBe(0)
|
|
17
|
+
expect(result.strategiesInvoked).toBe(true)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('when failed to spawn executable should return exit code 1', () => {
|
|
21
|
+
const executableStrategies = [
|
|
22
|
+
{
|
|
23
|
+
type: 'made up command',
|
|
24
|
+
filePath: 'ls',
|
|
25
|
+
// fake command arguments to make 'ls' command fail
|
|
26
|
+
prefixCommandArguments: ['-ala-s33s']
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
const result = cli.start(executableStrategies)
|
|
31
|
+
expect(result.strategyExitCode).not.toBe(0)
|
|
32
|
+
expect(result.strategiesInvoked).toBe(true)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('should not invoke strategy when not existing', () => {
|
|
36
|
+
const executableStrategies = [
|
|
37
|
+
{
|
|
38
|
+
type: 'made up command',
|
|
39
|
+
filePath: 'made up command'
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
const result = cli.start(executableStrategies)
|
|
44
|
+
expect(result.strategiesInvoked).toBe(false)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
describe('Unit testing CLI', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
jest.resetModules()
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
test('should only invoke one strategy if more than one exists', () => {
|
|
9
|
+
jest.doMock('../src/strategies.js', () => {
|
|
10
|
+
return {
|
|
11
|
+
executeStrategy: jest.fn(() => {
|
|
12
|
+
return 0
|
|
13
|
+
}),
|
|
14
|
+
isExecutableAvailableInPath: jest.fn(() => {
|
|
15
|
+
return true
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
const strategies = require('../src/strategies')
|
|
20
|
+
const cli = require('../src/cli')
|
|
21
|
+
|
|
22
|
+
const executableStrategies = [
|
|
23
|
+
{
|
|
24
|
+
type: 'ls',
|
|
25
|
+
filePath: 'ls'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'ls',
|
|
29
|
+
filePath: 'ls'
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
const result = cli.start(executableStrategies)
|
|
34
|
+
expect(result.strategiesInvoked).toEqual(true)
|
|
35
|
+
expect(strategies.executeStrategy.mock.calls.length).toBe(1)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* eslint-disable security/detect-child-process */
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
const ChildProcess = require('child_process')
|
|
5
|
+
jest.mock('child_process', () => {
|
|
6
|
+
return {
|
|
7
|
+
spawnSync: jest.fn()
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
process.exit = jest.fn()
|
|
12
|
+
|
|
13
|
+
const {executeStrategy} = require('../src/strategies')
|
|
14
|
+
|
|
15
|
+
describe('Strategies: executeStrategy', () => {
|
|
16
|
+
beforeAll(() => {
|
|
17
|
+
process.exit.mockClear()
|
|
18
|
+
ChildProcess.spawnSync.mockClear()
|
|
19
|
+
ChildProcess.spawnSync.mockReset()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('when no arguments provided it shouldnt add anything to the spawned process', () => {
|
|
23
|
+
process.argv = []
|
|
24
|
+
|
|
25
|
+
const mockStrategy = {
|
|
26
|
+
type: 'ls',
|
|
27
|
+
filePath: 'ls'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ChildProcess.spawnSync = jest.fn(() => {
|
|
31
|
+
return {
|
|
32
|
+
status: 0,
|
|
33
|
+
stdout: '',
|
|
34
|
+
stderr: ''
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const exitCode = executeStrategy(mockStrategy)
|
|
39
|
+
|
|
40
|
+
expect(exitCode).toBe(0)
|
|
41
|
+
expect(ChildProcess.spawnSync.mock.calls.length).toBe(1)
|
|
42
|
+
expect(ChildProcess.spawnSync.mock.calls[0][1]).toEqual([])
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('when arguments provided it should add them to the arguments of the command being spawned', () => {
|
|
46
|
+
process.argv = []
|
|
47
|
+
|
|
48
|
+
const mockedArguments = ['a', 'b', 'c']
|
|
49
|
+
const mockStrategy = {
|
|
50
|
+
type: 'ls',
|
|
51
|
+
filePath: 'ls',
|
|
52
|
+
prefixCommandArguments: mockedArguments
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
ChildProcess.spawnSync = jest.fn(() => {
|
|
56
|
+
return {
|
|
57
|
+
status: 1,
|
|
58
|
+
stdout: '',
|
|
59
|
+
stderr: ''
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const exitCode = executeStrategy(mockStrategy)
|
|
64
|
+
|
|
65
|
+
expect(exitCode).toBe(1)
|
|
66
|
+
expect(ChildProcess.spawnSync.mock.calls.length).toBe(1)
|
|
67
|
+
expect(ChildProcess.spawnSync.mock.calls[0][1]).toEqual(mockedArguments)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {isExecutableAvailableInPath} = require('../src/strategies')
|
|
4
|
+
|
|
5
|
+
describe('Strategies: isExecutableAvailableInPath', () => {
|
|
6
|
+
test('should find a binary and result in success', () => {
|
|
7
|
+
const executable = 'ls'
|
|
8
|
+
const result = isExecutableAvailableInPath(executable)
|
|
9
|
+
expect(result).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('should not find a made up binary name and result in error', () => {
|
|
13
|
+
const executable = 'c3c3c2'
|
|
14
|
+
const result = isExecutableAvailableInPath(executable)
|
|
15
|
+
expect(result).toBe(false)
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-process-exit */
|
|
3
|
+
const debug = require('debug')('detect-secrets')
|
|
4
|
+
const pkg = require('../package.json')
|
|
5
|
+
const cli = require('../src/cli')
|
|
6
|
+
|
|
7
|
+
const PYTHON_PACKAGE_EXEC = 'detect-secrets-hook'
|
|
8
|
+
const DOCKER_EXEC = 'docker'
|
|
9
|
+
const DOCKER_IMAGE_NAME = 'lirantal/detect-secrets'
|
|
10
|
+
|
|
11
|
+
const pwd = process.cwd()
|
|
12
|
+
const executableStrategies = [
|
|
13
|
+
{
|
|
14
|
+
type: 'python',
|
|
15
|
+
filePath: PYTHON_PACKAGE_EXEC
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: 'docker',
|
|
19
|
+
filePath: DOCKER_EXEC,
|
|
20
|
+
prefixCommandArguments: [
|
|
21
|
+
'run',
|
|
22
|
+
'--rm',
|
|
23
|
+
'--volume',
|
|
24
|
+
`${pwd}:/usr/src/app`,
|
|
25
|
+
`${DOCKER_IMAGE_NAME}`
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
debug(`${pkg.name} ${pkg.version}`)
|
|
31
|
+
const {strategyExitCode, strategiesInvoked} = cli.start(executableStrategies)
|
|
32
|
+
if (strategiesInvoked) {
|
|
33
|
+
process.exit(strategyExitCode)
|
|
34
|
+
} else {
|
|
35
|
+
console.log(`${pkg.name} ${pkg.version}`)
|
|
36
|
+
console.log('WARNING: could not execute tool to prevent you from committing secrets')
|
|
37
|
+
console.log(
|
|
38
|
+
'to remedy the situation and enable secrets detection in your commits, consider one of:'
|
|
39
|
+
)
|
|
40
|
+
console.log(
|
|
41
|
+
' 1. follow instructions on https://github.com/Yelp/detect-secrets to install detect-secrets'
|
|
42
|
+
)
|
|
43
|
+
console.log(' 2. install docker and this Node.js CLI will use it to execute an image')
|
|
44
|
+
console.log('')
|
|
45
|
+
}
|
package/jsdoc.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tags": {
|
|
3
|
+
"allowUnknownTags": true,
|
|
4
|
+
"dictionaries": ["jsdoc", "closure"]
|
|
5
|
+
},
|
|
6
|
+
"source": {
|
|
7
|
+
"include": ["./index.js"],
|
|
8
|
+
"exclude": ["./node_modules", "./.nyc_output", "./coverage", "./out", "./tests"],
|
|
9
|
+
"includePattern": ".+\\.js(doc|x)?$",
|
|
10
|
+
"excludePattern": "(^|\\/|\\\\)_"
|
|
11
|
+
},
|
|
12
|
+
"plugins": [],
|
|
13
|
+
"templates": {},
|
|
14
|
+
"opts": {
|
|
15
|
+
"destination": "./out",
|
|
16
|
+
"recurse": true,
|
|
17
|
+
"private": true
|
|
18
|
+
}
|
|
19
|
+
}
|