Skip to content

Commit cd78dbc

Browse files
committed
Reorganize scanner code, add secret invalidation
Signed-off-by: Lilly Rose Berner <[email protected]>
1 parent d72896b commit cd78dbc

File tree

11 files changed

+461
-184
lines changed

11 files changed

+461
-184
lines changed

echo/Cargo.lock

Lines changed: 106 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

echo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ figment = { version = "0.10.19", features = ["json"] }
1111
once_cell = "1.20.2"
1212
rand = "0.8.5"
1313
regex = "1.11.1"
14-
reqwest = { version = "0.12.8", default-features = false, features = ["json", "native-tls-alpn", "native-tls-vendored"] }
14+
reqwest = { version = "0.12.8", features = ["json", "native-tls-alpn", "native-tls-vendored"] }
1515
rocket = { version = "0.5.1", features = ["json"] }
1616
rocket-validation = "0.2.0"
1717
rocket_db_pools = { version = "0.2.0", features = ["sqlx_postgres"] }

echo/example.config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"allowed_hosts": ["http://localhost:1234", "https://mystb.in"],
3+
"github_token": "github_pat_KOBfYbSdPtOGcvSMdkoUye_IWEadGCSJxVffBVHZZRSCXBqvhKzKTaddmyBaZcHxWLdJQIOhJbpsbiEWx",
34
"extra_scanners": [
4-
{ "name": "PyPi", "pattern": "pypi-AgEIcHlwaS5vcmc[A-Za-z0-9-_]{70,}" },
5-
{ "name": "GitHub", "pattern": "((ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9_]{36})" }
5+
{ "name": "PyPi", "pattern": "pypi-AgEIcHlwaS5vcmc[A-Za-z0-9-_]{70,}", "invalidate": true },
6+
{ "name": "GitHub", "pattern": "((ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9_]{36})", "invalidate": true }
67
]
78
}

echo/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ use serde::{Deserialize, Serialize};
66
pub struct ScannerConfig {
77
pub name: Arc<String>,
88
pub pattern: String,
9+
pub invalidate: bool,
910
}
1011

1112
#[derive(Debug, Deserialize, Serialize)]
1213
pub struct Config {
14+
// CORS
1315
pub allowed_hosts: Vec<String>,
16+
// Secret Scanning
17+
pub github_token: String,
1418
pub extra_scanners: Vec<ScannerConfig>,
1519
}

echo/src/database/pastes.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ impl Paste {
121121
}
122122
};
123123

124+
let invalidate_secrets = data.password().is_none();
125+
124126
for file in data.files() {
125-
let file = File::create(&mut tx, paste.id(), file).await?;
127+
let file = File::create(&mut tx, paste.id(), file, invalidate_secrets).await?;
126128
paste.add_file(file);
127129
}
128130

@@ -178,6 +180,7 @@ impl File {
178180
tx: &mut Transaction<'_, Postgres>,
179181
paste_id: &str,
180182
file: &'r CreateFile<'r>,
183+
invalidate_secrets: bool,
181184
) -> Result<Self> {
182185
let result = sqlx::query(
183186
"
@@ -196,7 +199,8 @@ impl File {
196199
match result {
197200
Ok(row) => {
198201
let id: i64 = row.get("id");
199-
let annotations = Annotation::create(tx, id, file.content()).await?;
202+
let annotations =
203+
Annotation::create(tx, id, file.content(), invalidate_secrets).await?;
200204

201205
return Ok(File::from_row(row, annotations));
202206
}
@@ -240,12 +244,17 @@ impl Annotation {
240244
tx: &mut Transaction<'_, Postgres>,
241245
file_id: i64,
242246
content: &str,
247+
invalidate_secrets: bool,
243248
) -> Result<Vec<Self>> {
244-
let scans = scan_file(content);
249+
let scans = scan_file(content, invalidate_secrets).await;
245250
let mut annotations = Vec::with_capacity(scans.len());
246251

247252
for scan in scans {
248-
let content = format!("Contains potentially sensitive data from {}.", scan.service);
253+
let mut content = format!("Mystb.in found a secret for {}.", scan.service);
254+
255+
if invalidate_secrets {
256+
content += " This secret has been invalidated.";
257+
}
249258

250259
let result = sqlx::query(
251260
"

echo/src/main.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,10 @@ fn rocket() -> _ {
3333
security::delete_security,
3434
];
3535

36-
let version = env!("CARGO_PKG_VERSION");
37-
let user_agent = format!("Echo/{} (+https://mystb.in)", version);
38-
39-
let client = reqwest::Client::builder()
40-
.https_only(true)
41-
.user_agent(user_agent)
42-
.build()
43-
.unwrap();
44-
4536
let path = env::var("ECHO_CONFIG").expect("ECHO_CONFIG not set");
4637
let provider = rocket::Config::figment().merge(Json::file(path));
4738

4839
rocket::custom(provider)
49-
.manage(client)
5040
.mount("/", routes)
5141
.attach(AdHoc::config::<Config>())
5242
.attach(PgDatabase::init())

0 commit comments

Comments
 (0)