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

This commit is contained in:
soda64 committed 2026-12-02 19:04:38 +01:00
1 parent 011f23e637
commit 33082598fc
19 files changed
+496 -6

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.go`)
1. `SafeJoin(baseDir, relPath string) (string, error)` — bezpiecznie połącz `baseDir` z `relPath`. Odrzuć ścieżki absolutne i próby wyjścia poza `baseDir` (`../../etc/passwd`) błędem `ErrPathTraversal`.
2. `RedactSecrets(logLine string) string` — zamaskuj wartości po `Bearer `, `token=` i `password=` na `***`.
## Uruchomienie testów
```bash
make test PKG=./exercises/02-engineering-2026/06-security-appsec
```
@@ -0,0 +1,13 @@
package appsec
import "errors"
var ErrPathTraversal = errors.New("path escapes base directory")
func SafeJoin(baseDir, relPath string) (string, error) {
panic("TODO: odrzuć filepath.IsAbs(relPath) oraz ścieżki wychodzące poza baseDir (filepath.Rel -> '..')")
}
func RedactSecrets(logLine string) string {
panic("TODO: zamień wartości po 'Bearer ', 'token=' i 'password=' na '***'")
}
@@ -0,0 +1,40 @@
package appsec
import (
"errors"
"path/filepath"
"strings"
"testing"
)
func TestSafeJoinBlocksTraversal(t *testing.T) {
base := t.TempDir()
got, err := SafeJoin(base, filepath.Join("configs", "app.yaml"))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
want := filepath.Join(base, "configs", "app.yaml")
if got != want {
t.Fatalf("got %q, want %q", got, want)
}
if _, err := SafeJoin(base, "../../etc/passwd"); !errors.Is(err, ErrPathTraversal) {
t.Fatalf("expected ErrPathTraversal, got %v", err)
}
if _, err := SafeJoin(base, "/etc/passwd"); !errors.Is(err, ErrPathTraversal) {
t.Fatalf("expected ErrPathTraversal for abs path, got %v", err)
}
}
func TestRedactSecrets(t *testing.T) {
line := "auth failed header=Bearer s3cr3tTok3n user=admin password=hunter2 token=abc_123"
cleaned := RedactSecrets(line)
for _, leaked := range []string{"s3cr3tTok3n", "hunter2", "abc_123"} {
if strings.Contains(cleaned, leaked) {
t.Errorf("secret %q leaked in %q", leaked, cleaned)
}
}
if !strings.Contains(cleaned, "user=admin") {
t.Errorf("non-secret field lost in %q", cleaned)
}
}