Skip to content

Commit 88efb99

Browse files
authored
Version: 0.2.0_apply scan leaks on git repository (#5)
* standardize code formatting and detect local directory Signed-off-by: sonichen <[email protected]> * standardize code formatting and detect local directory Signed-off-by: sonichen <[email protected]> * delete compiled binary file Signed-off-by: sonichen <[email protected]> --------- Signed-off-by: sonichen <[email protected]>
1 parent 846d4f0 commit 88efb99

File tree

13 files changed

+1545
-349
lines changed

13 files changed

+1545
-349
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sensleak"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -18,3 +18,5 @@ serde_json = "1.0"
1818
chrono = "0.4"
1919
assert_cmd = "2.0.10"
2020
tempfile = "3.2.0"
21+
git2 = "0.17.1"
22+
mockito = "1.0.2"

README.md

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,62 +33,88 @@ sensleaks-rs
3333
Usage: sensleak.exe [OPTIONS] --repo <REPO>
3434

3535
Options:
36-
-r, --repo <REPO> Target repository
37-
-c, --config <CONFIG> Config path.. [default: gitleaks.toml]
38-
-o, --report <REPORT> Path to write json leaks file [default: ]
39-
-v, --verbose Show verbose output from scan
40-
-e, --pretty Pretty print json if leaks are present
41-
-h, --help Print help (see more with '--help')
42-
-V, --version Print version
36+
--repo <REPO> Target repository
37+
--config <CONFIG> Config path.. [default: gitleaks.toml]
38+
--report <REPORT> Path to write json leaks file [default: ]
39+
-v, --verbose Show verbose output from scan
40+
--pretty Pretty print json if leaks are present
41+
--commit <COMMIT> sha of commit to scan or "latest" to scan the last commit of the repository
42+
--commits <COMMITS> comma separated list of a commits to scan
43+
--commits-file <COMMITS_FILE> file of new line separated list of a commits to scan
44+
--commit-since <COMMIT_SINCE> Scan commits more recent than a specific date. Ex: '2006-01-02' or '2023-01-02T15:04:05-0700' format
45+
--commit-until <COMMIT_UNTIL> Scan commits older than a specific date. Ex: '2006-01-02' or '2006-10-02T15:04:05-0700' format
46+
--commit-from <COMMIT_FROM> Commit to start scan from
47+
--commit-to <COMMIT_TO> Commit to stop scan
48+
--branch <BRANCH> Branch to scan (comming soon)
49+
--uncommitted run gitleaks on uncommitted code (comming soon)
50+
--user <USER> user to scan (comming soon)
51+
-h, --help Print help (see more with '--help')
52+
-V, --version Print version
53+
54+
4355

4456
Repository: https://github.com/open-rust-initiative/sensleak-rs
4557
```
4658
47-
Examples: (test the file in src\tests\files\test)
59+
Examples: (Test repo: https://github.com/sonichen/TestGitOperation)
4860
4961
```shell
50-
sensleak -r="tests\files\test" -v -e
62+
sensleak --repo="D:/Workplace/Git/TestGitOperation" --commit="8bdca802af0514ce29947e20c6be1719974ad866" -v --pretty
5163
```
5264
5365
Output:
5466
5567
```shell
68+
[INFO][2023-05-26 11:51:04] Open repo ...
5669
[
57-
OutputItem {
58-
line: "token = sk_test_abcd1234567890efghijklmno",
59-
line_number: 5,
60-
secret: "sk_test_abcd1234567890efghijklmno",
61-
entropy: "",
62-
commit: "",
63-
repo: "",
64-
rule: "Stripe Access Token",
65-
commit_message: "",
66-
author: "",
67-
email: "",
68-
file: "tests\\files\\test\\file2.txt",
69-
date: "",
70+
Leak {
71+
line: "twilio_api_key = SK12345678901234567890123456789012",
72+
line_number: 6,
73+
secret: "api_key = SK12345678901234567890123456789012",
74+
entropy: "3.5",
75+
commit: "8bdca802af0514ce29947e20c6be1719974ad866",
76+
repo: "TestGitOperation",
77+
rule: "Generic API Key",
78+
commit_message: "test\n",
79+
author: "sonichen",
80+
81+
file: "/src/key.java",
82+
date: "2023-05-23 23:55:12 -08:00",
7083
tags: "",
71-
operation: "",
84+
operation: "addition",
7285
},
73-
OutputItem {
86+
...
87+
Leak {
7488
line: "twilio_api_key = SK12345678901234567890123456789012",
75-
line_number: 6,
89+
line_number: 2,
7690
secret: "SK12345678901234567890123456789012",
7791
entropy: "",
78-
commit: "",
79-
repo: "",
92+
commit: "8bdca802af0514ce29947e20c6be1719974ad866",
93+
repo: "TestGitOperation",
8094
rule: "Twilio API Key",
81-
commit_message: "",
82-
author: "",
83-
email: "",
84-
file: "tests\\files\\test\\file2.txt",
85-
date: "",
95+
commit_message: "test\n",
96+
author: "sonichen",
97+
98+
file: "/src/mykey.java",
99+
date: "2023-05-23 23:55:12 -08:00",
86100
tags: "",
87-
operation: "",
101+
operation: "addition",
88102
},
89-
....
90103
]
91-
WARN:[2023-05-17 09:45:07]10 leaks detected. XXX commits scanned in 66.6222ms
104+
[WARN][2023-05-26 11:51:05]10 leaks detected. 1 commits scanned in 1.7318395s
105+
106+
```
107+
108+
109+
110+
More examples:
111+
112+
```shell
113+
cargo run -- --repo="D:/Workplace/Git/TestGitOperation" --commit="8bdca802af0514ce29947e20c6be1719974ad866" -v --pretty
114+
cargo run -- --repo="D:/Workplace/Git/TestGitOperation" --commits="4362fc4df48df74a46b56368d7fff1b02d01be72,8bdca802af0514ce29947e20c6be1719974ad866" -v --pretty
115+
cargo run -- --repo="D:/Workplace/Git/TestGitOperation" --commits-file="tests/files/commits.txt" -v --pretty
116+
cargo run -- --repo="D:/Workplace/Git/TestGitOperation" --commit-since="2023-05-20" --commit-until="2023-05-26" -v --pretty
117+
cargo run -- --repo="D:/Workplace/Git/TestGitOperation" --commit-to="4362fc4df48df74a46b56368d7fff1b02d01be72" --commit-from="8bdca802af0514ce29947e20c6be1719974ad866" -v --pretty
92118
```
93119
94120

0 commit comments

Comments
 (0)