feat: add SQL/SQLite, AppSec, Capstone incident-tracker, Gitea Actions CI and spaced repetition
Test and Lint / quality (push) Successful in 34s

This commit is contained in:
soda64 committed 2026-12-02 16:58:44 +01:00
1 parent 0ac80d60d4
commit 9430a194c3
18 files changed
+422 -7

No files matched your search

@@ -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 (`appsec.py`)
1. `safe_join(base_dir: Path, relative_path: str) -> Path` — bezpiecznie połącz `base_dir` z `relative_path`. Jeśli wynikowa ścieżka (po `resolve()`) ucieka poza `base_dir.resolve()` (np. `../../etc/passwd` lub ścieżka absolutna `/etc/passwd`), rzuć `PathTraversalError`.
2. `redact_secrets(log_line: str) -> str` — zamaskuj wartości po `token=`, `password=` lub `Bearer ` na `***`, aby sekrety nigdy nie trafiały do logów.
## Uruchomienie testów
```bash
make test MOD=02-engineering-2026/06-security-appsec
```
@@ -0,0 +1,17 @@
import re
from pathlib import Path
class PathTraversalError(ValueError):
"""Próba wyjścia poza dozwolony katalog bazowy."""
def safe_join(base_dir: Path, relative_path: str) -> Path:
raise NotImplementedError(
"Rozwiąż (base_dir / relative_path).resolve() i sprawdź is_relative_to(base_dir.resolve())"
)
def redact_secrets(log_line: str) -> str:
_ = re
raise NotImplementedError("Zamień wartości po Bearer , token= oraz password= na '***'")
@@ -0,0 +1,24 @@
from pathlib import Path
import pytest
from appsec import PathTraversalError, redact_secrets, safe_join
def test_safe_join_allows_nested_and_blocks_traversal(tmp_path: Path) -> None:
ok = safe_join(tmp_path, "configs/app.yaml")
assert ok == (tmp_path / "configs" / "app.yaml").resolve()
with pytest.raises(PathTraversalError):
safe_join(tmp_path, "../../etc/passwd")
with pytest.raises(PathTraversalError):
safe_join(tmp_path, "/etc/passwd")
def test_redact_secrets_masks_credentials() -> None:
line = "auth failed header=Bearer s3cr3tTok3n user=admin password=hunter2 token=abc_123"
cleaned = redact_secrets(line)
assert "s3cr3tTok3n" not in cleaned
assert "hunter2" not in cleaned
assert "abc_123" not in cleaned
assert "user=admin" in cleaned