feat: add SQL/SQLite, AppSec, Capstone incident-tracker, Gitea Actions CI and spaced repetition
Test and Lint / quality (push) Successful in 1m50s
Test and Lint / quality (push) Successful in 1m50s
This commit is contained in:
1 parent
015eae08c3
commit
9130af822e
19 files changed
+722
-7
No files matched your search
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "eng06-security-appsec"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
@@ -0,0 +1,12 @@
|
||||
# 06 — Bezpieczeństwo Kodu (AppSec: Path Traversal, Redakcja Sekretów)
|
||||
|
||||
Teoria: [notes/07-appsec-and-secure-coding.md](../../../notes/07-appsec-and-secure-coding.md)
|
||||
|
||||
## Zadania (`src/lib.rs`)
|
||||
1. `safe_join(base_dir: &Path, relative_path: &str) -> Result<PathBuf, SecurityError>` — odrzuć ścieżki absolutne (`Path::is_absolute`) oraz zawierające `Component::ParentDir` (`..`), w przeciwnym razie zwróć `Ok(base_dir.join(relative_path))`.
|
||||
2. `redact_secrets(log_line: &str) -> String` — zamaskuj wartości po `Bearer `, `token=` oraz `password=` na `***`.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test PKG=eng06-security-appsec
|
||||
```
|
||||
@@ -0,0 +1,50 @@
|
||||
#![allow(unused_variables, dead_code)]
|
||||
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum SecurityError {
|
||||
PathTraversal,
|
||||
}
|
||||
|
||||
pub fn safe_join(base_dir: &Path, relative_path: &str) -> Result<PathBuf, SecurityError> {
|
||||
let _ = Component::ParentDir;
|
||||
todo!("Odrzuć ścieżki absolutne i zawierające Component::ParentDir jako PathTraversal")
|
||||
}
|
||||
|
||||
pub fn redact_secrets(log_line: &str) -> String {
|
||||
todo!("Zamień tokeny po 'Bearer ', 'token=' i 'password=' na '***'")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn blocks_path_traversal() {
|
||||
let base = Path::new("/srv/app");
|
||||
assert_eq!(
|
||||
safe_join(base, "configs/app.toml"),
|
||||
Ok(base.join("configs/app.toml"))
|
||||
);
|
||||
assert_eq!(
|
||||
safe_join(base, "../../etc/passwd"),
|
||||
Err(SecurityError::PathTraversal)
|
||||
);
|
||||
assert_eq!(
|
||||
safe_join(base, "/etc/passwd"),
|
||||
Err(SecurityError::PathTraversal)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redacts_secrets_from_logs() {
|
||||
let line =
|
||||
"auth failed header=Bearer s3cr3tTok3n user=admin password=hunter2 token=abc_123";
|
||||
let cleaned = redact_secrets(line);
|
||||
assert!(!cleaned.contains("s3cr3tTok3n"));
|
||||
assert!(!cleaned.contains("hunter2"));
|
||||
assert!(!cleaned.contains("abc_123"));
|
||||
assert!(cleaned.contains("user=admin"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user