forked from claw/flaskpaste
ci: update linting and security checks
- Fix bandit suppressions (use # nosec B608 for bandit) - Add # noqa: S608 for ruff compatibility - CI workflow: add coverage reporting (informational) - CI workflow: track mypy error baseline - CI workflow: improve documentation
This commit is contained in:
@@ -29,10 +29,10 @@ jobs:
|
|||||||
git clone --depth 1 --branch "${GITHUB_REF_NAME}" \
|
git clone --depth 1 --branch "${GITHUB_REF_NAME}" \
|
||||||
"https://oauth2:${{ github.token }}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git" .
|
"https://oauth2:${{ github.token }}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git" .
|
||||||
|
|
||||||
- name: Install tools
|
- name: Install dev tools
|
||||||
run: pip install -q ruff mypy
|
run: pip install -q ruff mypy
|
||||||
|
|
||||||
- name: Syntax check
|
- name: Python syntax check
|
||||||
run: python -m py_compile run.py wsgi.py app/*.py app/**/*.py
|
run: python -m py_compile run.py wsgi.py app/*.py app/**/*.py
|
||||||
|
|
||||||
- name: Ruff lint
|
- name: Ruff lint
|
||||||
@@ -41,8 +41,14 @@ jobs:
|
|||||||
- name: Ruff format
|
- name: Ruff format
|
||||||
run: ruff format --check app/ tests/ fpaste
|
run: ruff format --check app/ tests/ fpaste
|
||||||
|
|
||||||
- name: Type check
|
- name: Type check (informational)
|
||||||
run: mypy app/ --ignore-missing-imports --no-error-summary || echo "::warning::mypy found issues"
|
run: |
|
||||||
|
# mypy strict mode - track progress, don't fail CI yet
|
||||||
|
errors=$(mypy app/ --ignore-missing-imports 2>&1 | grep -c "error:" || true)
|
||||||
|
echo "mypy found $errors type errors"
|
||||||
|
if [ "$errors" -gt 20 ]; then
|
||||||
|
echo "::warning::mypy errors increased to $errors (baseline: 20)"
|
||||||
|
fi
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
security:
|
security:
|
||||||
@@ -58,17 +64,23 @@ jobs:
|
|||||||
git clone --depth 1 --branch "${GITHUB_REF_NAME}" \
|
git clone --depth 1 --branch "${GITHUB_REF_NAME}" \
|
||||||
"https://oauth2:${{ github.token }}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git" .
|
"https://oauth2:${{ github.token }}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git" .
|
||||||
|
|
||||||
- name: Upgrade pip and install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
pip install -q --upgrade pip
|
pip install -q --upgrade pip
|
||||||
pip install -q -r requirements.txt
|
pip install -q -r requirements.txt
|
||||||
pip install -q bandit pip-audit
|
pip install -q bandit pip-audit
|
||||||
|
|
||||||
- name: Bandit scan
|
- name: Bandit security scan
|
||||||
run: bandit -r app/ -ll -q
|
run: |
|
||||||
|
# -ll = medium and high severity only
|
||||||
|
# -q = quiet, only show issues
|
||||||
|
bandit -r app/ -ll -q
|
||||||
|
|
||||||
- name: Dependency audit
|
- name: Dependency audit (informational)
|
||||||
run: pip-audit --progress-spinner=off || echo "::warning::pip-audit found issues"
|
run: |
|
||||||
|
# Check for known vulnerabilities in dependencies
|
||||||
|
# Warnings only - container base packages often have issues
|
||||||
|
pip-audit --progress-spinner=off || echo "::warning::pip-audit found vulnerabilities"
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@@ -88,7 +100,13 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
pip install -q -r requirements.txt
|
pip install -q -r requirements.txt
|
||||||
pip install -q pytest
|
pip install -q pytest pytest-cov
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: pytest tests/ -v --tb=short
|
run: pytest tests/ -v --tb=short
|
||||||
|
|
||||||
|
- name: Run tests with coverage
|
||||||
|
run: |
|
||||||
|
pytest tests/ --cov=app --cov-report=term-missing --cov-fail-under=70 || \
|
||||||
|
echo "::warning::Coverage below 70%"
|
||||||
|
continue-on-error: true
|
||||||
|
|||||||
@@ -420,9 +420,7 @@ def generate_challenge(difficulty_override: int | None = None) -> dict[str, Any]
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def verify_pow(
|
def verify_pow(token: str, solution: str, min_difficulty: int | None = None) -> tuple[bool, str]:
|
||||||
token: str, solution: str, min_difficulty: int | None = None
|
|
||||||
) -> tuple[bool, str]:
|
|
||||||
"""Verify proof-of-work solution. Returns (valid, error_message).
|
"""Verify proof-of-work solution. Returns (valid, error_message).
|
||||||
|
|
||||||
Accepts tokens with difficulty >= min_difficulty. The solution must meet the
|
Accepts tokens with difficulty >= min_difficulty. The solution must meet the
|
||||||
@@ -1019,9 +1017,7 @@ class RegisterView(MethodView):
|
|||||||
if ca_info is None or "certificate_pem" not in ca_info:
|
if ca_info is None or "certificate_pem" not in ca_info:
|
||||||
ca_info = get_ca_info(skip_enabled_check=True)
|
ca_info = get_ca_info(skip_enabled_check=True)
|
||||||
ca_cert = x509.load_pem_x509_certificate(ca_info["certificate_pem"].encode())
|
ca_cert = x509.load_pem_x509_certificate(ca_info["certificate_pem"].encode())
|
||||||
client_cert = x509.load_pem_x509_certificate(
|
client_cert = x509.load_pem_x509_certificate(cert_info["certificate_pem"].encode())
|
||||||
cert_info["certificate_pem"].encode()
|
|
||||||
)
|
|
||||||
client_key = serialization.load_pem_private_key(
|
client_key = serialization.load_pem_private_key(
|
||||||
cert_info["private_key_pem"].encode(), password=None
|
cert_info["private_key_pem"].encode(), password=None
|
||||||
)
|
)
|
||||||
@@ -1044,9 +1040,7 @@ class RegisterView(MethodView):
|
|||||||
|
|
||||||
# Return PKCS#12 as binary download
|
# Return PKCS#12 as binary download
|
||||||
response = Response(p12_data, mimetype="application/x-pkcs12")
|
response = Response(p12_data, mimetype="application/x-pkcs12")
|
||||||
response.headers["Content-Disposition"] = (
|
response.headers["Content-Disposition"] = f'attachment; filename="{common_name}.p12"'
|
||||||
f'attachment; filename="{common_name}.p12"'
|
|
||||||
)
|
|
||||||
response.headers["X-Fingerprint-SHA1"] = cert_info["fingerprint_sha1"]
|
response.headers["X-Fingerprint-SHA1"] = cert_info["fingerprint_sha1"]
|
||||||
response.headers["X-Certificate-Expires"] = str(cert_info["expires_at"])
|
response.headers["X-Certificate-Expires"] = str(cert_info["expires_at"])
|
||||||
return response
|
return response
|
||||||
@@ -1211,7 +1205,7 @@ class PasteView(MethodView):
|
|||||||
return error_response("No updates provided", 400)
|
return error_response("No updates provided", 400)
|
||||||
|
|
||||||
# Execute update (fields are hardcoded strings, safe from injection)
|
# Execute update (fields are hardcoded strings, safe from injection)
|
||||||
update_sql = f"UPDATE pastes SET {', '.join(update_fields)} WHERE id = ?" # noqa: S608
|
update_sql = f"UPDATE pastes SET {', '.join(update_fields)} WHERE id = ?" # noqa: S608 # nosec B608
|
||||||
update_params.append(paste_id)
|
update_params.append(paste_id)
|
||||||
db.execute(update_sql, update_params)
|
db.execute(update_sql, update_params)
|
||||||
db.commit()
|
db.commit()
|
||||||
@@ -1376,7 +1370,7 @@ class PastesListView(MethodView):
|
|||||||
|
|
||||||
# Count total pastes matching filters (where_sql is safe, built from constants)
|
# Count total pastes matching filters (where_sql is safe, built from constants)
|
||||||
count_row = db.execute(
|
count_row = db.execute(
|
||||||
f"SELECT COUNT(*) as total FROM pastes WHERE {where_sql}", # noqa: S608
|
f"SELECT COUNT(*) as total FROM pastes WHERE {where_sql}", # noqa: S608 # nosec B608
|
||||||
params,
|
params,
|
||||||
).fetchone()
|
).fetchone()
|
||||||
total = count_row["total"] if count_row else 0
|
total = count_row["total"] if count_row else 0
|
||||||
@@ -1389,7 +1383,7 @@ class PastesListView(MethodView):
|
|||||||
FROM pastes
|
FROM pastes
|
||||||
WHERE {where_sql}
|
WHERE {where_sql}
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT ? OFFSET ?""", # noqa: S608
|
LIMIT ? OFFSET ?""", # noqa: S608 # nosec B608
|
||||||
[*params, limit, offset],
|
[*params, limit, offset],
|
||||||
).fetchall()
|
).fetchall()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user