Skip to content

Commit 4422f0c

Browse files
committed
feat: implement log scrubbing and security workflows
1 parent 15f5192 commit 4422f0c

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
schedule:
9+
- cron: '34 20 * * 1'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'javascript-typescript', 'python' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v3
31+
with:
32+
languages: ${{ matrix.language }}
33+
34+
- name: Autobuild
35+
uses: github/codeql-action/autobuild@v3
36+
37+
- name: Perform CodeQL Analysis
38+
uses: github/codeql-action/analyze@v3
39+
with:
40+
category: "/language:${{matrix.language}}"

.github/workflows/dast.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: DAST Scan
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
zap_scan:
8+
runs-on: ubuntu-latest
9+
name: Scan the webapplication
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: ZAP Baseline Scan
15+
uses: zaproxy/action-baseline-scan@v0.12.0
16+
with:
17+
target: 'http://localhost:8000'

src/utils/logging_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import os
3+
import re
34
import sys
45
import threading
56

@@ -12,6 +13,26 @@
1213
_logging_initialized = False
1314
_logging_lock = threading.Lock()
1415

16+
# PII Patterns for redaction
17+
PII_PATTERNS = {
18+
# Email pattern
19+
r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b": "[REDACTED_EMAIL]",
20+
# Generic API Key-like pattern (starts with sk- or similar, long alphanumeric)
21+
r"(sk-[a-zA-Z0-9]{20,})": "[REDACTED_API_KEY]",
22+
}
23+
24+
25+
def scrub_sensitive_data(record):
26+
"""
27+
Patch function to scrub sensitive data from the log record.
28+
Modifies record["message"] in place.
29+
"""
30+
message = record["message"]
31+
for pattern, placeholder in PII_PATTERNS.items():
32+
if re.search(pattern, message):
33+
message = re.sub(pattern, placeholder, message)
34+
record["message"] = message
35+
1536

1637
def _should_show_location(level: str) -> bool:
1738
"""Determine if location should be shown for given log level"""
@@ -152,6 +173,9 @@ def setup_logging(*, debug=None, info=None, warning=None, error=None, critical=N
152173
# Remove any existing handlers
153174
logger.remove()
154175

176+
# Configure global patcher for log scrubbing
177+
logger.configure(patcher=scrub_sensitive_data)
178+
155179
# Initialize session_id if not already set
156180
if session_id.get() is None:
157181
session_id.set(generate_id())

0 commit comments

Comments
 (0)