chore(security): adopt standard gitleaks scan

This commit is contained in:
2026-10-13 10:11:13 +03:00
parent 00db8f2d85
commit fa987d7ea3
23 changed files with 88 additions and 37 deletions

View File

@@ -40,7 +40,7 @@ FRONTEND_SSL_PORT=443
AUTH_SECRET_KEY=change-me-to-a-random-secret-32-chars-min
# Fernet-ключ шифрования паролей подключений и API-ключей.
# Сгенерировать: python3 -c "import base64,os; print(base64.urlsafe_b64encode(os.urandom(32)).decode())"
ENCRYPTION_KEY=D40dpvWPZxKd41jeaTHtEs2R7nwMVLxbkMRLjAICRls=
ENCRYPTION_KEY=GENERATE_WITH_RUN_SH
# Сервисный токен для agent→backend вызовов.
# Сгенерировать: python3 -c "import secrets; print('svc-' + secrets.token_urlsafe(24))"
SERVICE_JWT=replace-with-random-service-secret

51
.gitleaks.toml Normal file
View File

@@ -0,0 +1,51 @@
title = "ss-tools tracked source secret scan"
minVersion = "8.30.0"
[extend]
useDefault = true
# These are named synthetic JSON fixtures. The rule, file, and field context
# must all match; similarly named fields in production files remain scanned.
[[allowlists]]
description = "Synthetic dashboard-testing JSON fixture fields"
targetRules = ["generic-api-key"]
condition = "AND"
regexTarget = "line"
paths = [
'''(?:^|.*/)backend/tests/fixtures/dashboard_scenarios/admitted_v2_actual_docker\.json$''',
'''(?:^|.*/)frontend/src/routes/dashboard-testing/scenarios/\[id\]/runs/\[runId\]/__tests__/fixtures/actual-mutated-run\.json$''',
'''(?:^|.*/)specs/033-gradio-agent-chat/fixtures/api/service_token_valid\.json$''',
'''(?:^|.*/)specs/038-dashboard-scenario-model/fixtures/api/scenario_(?:cycle|missing_ref)\.json$''',
]
regexes = [
'''"(?:idempotency_key|raw_base64|scenario_key|step_key|service_secret|access_token)"\s*:''',
]
# Public quickstart commands intentionally use a literal placeholder, never a
# credential. Keep the exception tied to the auth-header rule and those lines.
[[allowlists]]
description = "Quickstart curl Authorization placeholder"
targetRules = ["curl-auth-header"]
condition = "AND"
regexTarget = "line"
paths = [
'''(?:^|.*/)specs/008-migration-ui-improvements/quickstart\.md$''',
]
regexes = [
'''(?i)Authorization:\s*Bearer\s+YOUR_TOKEN(?:\s|['"\\]|$)''',
]
# Generated LiteLLM OpenAPI descriptions contain public example tokens. Only
# allow the known placeholder/sample forms within this generated documentation;
# an arbitrary Authorization value still fails the default rule.
[[allowlists]]
description = "Generated LiteLLM OpenAPI documented auth samples"
targetRules = ["curl-auth-header"]
condition = "AND"
regexTarget = "secret"
paths = [
'''(?:^|.*/)docs/openapi/litellm/openapi\.json$''',
]
regexes = [
'''(?i)^(?:YOUR_TOKEN|YOUR[_ -]?(?:API[_ -]?)?KEY|<[^>]+>|sk-(?:1234|12345|\.\.\.)|token|[A-Z][a-z]{7}-[0-9]{4})$''',
]

View File

@@ -143,7 +143,7 @@ def test_patch_profile_preferences_success(profile_route_deps_fixture):
"show_only_slug_dashboards": True,
"git_username": "ivan.ivanov",
"git_email": "ivan@company.local",
"git_personal_access_token": "ghp_1234567890",
"git_personal_access_token": "ghp_1234567890", # gitleaks:allow
"start_page": "reports-logs",
"auto_open_task_drawer": False,
"dashboards_table_density": "free",
@@ -165,7 +165,7 @@ def test_patch_profile_preferences_success(profile_route_deps_fixture):
assert called_kwargs["current_user"] == mock_user
assert called_kwargs["payload"].git_username == "ivan.ivanov"
assert called_kwargs["payload"].git_email == "ivan@company.local"
assert called_kwargs["payload"].git_personal_access_token == "ghp_1234567890"
assert called_kwargs["payload"].git_personal_access_token == "ghp_1234567890" # gitleaks:allow
assert called_kwargs["payload"].show_only_slug_dashboards is True
assert called_kwargs["payload"].start_page == "reports-logs"
assert called_kwargs["payload"].auto_open_task_drawer is False

View File

@@ -50,7 +50,7 @@ def _make_mock_provider(**overrides):
provider.provider_type = overrides.get("provider_type", "openai")
provider.base_url = overrides.get("base_url", "https://api.openai.com/v1")
provider.default_model = overrides.get("default_model", "gpt-4o-mini")
provider.api_key = "encrypted-key-123"
provider.api_key = "encrypted-key-123" # gitleaks:allow
return provider
# endregion Test.Tests.MakeMockProvider

View File

@@ -68,7 +68,7 @@ def seed() -> None:
environment_id="e2e",
status="failed",
phase="completed",
idempotency_key="e2e-scenario-disposition-run",
idempotency_key="e2e-scenario-disposition-run", # gitleaks:allow
target_snapshot={"dashboard_id": 47001},
))
artifact = db.get(ScenarioArtifact, ARTIFACT_ID)

View File

@@ -240,7 +240,7 @@ class TestUpdateUser:
with patch("src.api.routes.admin.AuthRepository", return_value=mock_repo):
client = _make_client({get_auth_db: lambda: mock_session})
resp = client.put("/api/admin/users/user-1", json={
"password": "NewStrongPass1",
"password": "NewStrongPass1", # gitleaks:allow
"is_active": False,
})
assert resp.status_code == 200

View File

@@ -12,7 +12,7 @@ import os
os.environ.setdefault("DATABASE_URL", "sqlite:///:memory:")
os.environ.setdefault("AUTH_DATABASE_URL", "sqlite:///:memory:")
os.environ.setdefault("SECRET_KEY", "test-secret-key-for-tests")
os.environ.setdefault("ENCRYPTION_KEY", "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=")
os.environ.setdefault("ENCRYPTION_KEY", "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=") # gitleaks:allow
import sys
from pathlib import Path

View File

@@ -175,7 +175,7 @@ def _seed(session) -> None:
return __import__("datetime").datetime.fromisoformat(value.replace("Z", "+00:00"))
session.add(ScenarioRegistryEntry(
scenario_id=_SCENARIO, scenario_key="fi-0080_execution-fixture", name="Execution fixture",
scenario_id=_SCENARIO, scenario_key="fi-0080_execution-fixture", name="Execution fixture", # gitleaks:allow
description="canonical", dashboard_id=80, environment_ids=["env-preprod-02"],
# Owned by the non-admin RUN/RUN_PROD principal used by _user_with, so the object ACL lets
# the PROD-gate tests exercise 403/approval instead of collapsing to a 404 foreign run.

View File

@@ -16,7 +16,7 @@ import pytest
from src.core.config_models import AppConfig, Environment, FeaturesConfig, GlobalSettings
# Hardcoded fixture — frozen Fernet key for deterministic encryption tests.
_VALID_FERNET_KEY = "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0="
_VALID_FERNET_KEY = "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0=" # gitleaks:allow
_MODULE = "src.core.config_manager"

View File

@@ -16,7 +16,7 @@ import pytest
# Hardcoded valid Fernet key — generated once, frozen as fixture.
# 32 url-safe base64 bytes. Never recompute at test time (anti-tautology).
_VALID_FERNET_KEY = "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0="
_VALID_FERNET_KEY = "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0=" # gitleaks:allow
# ── _require_fernet_key ─────────────────────────────────────────────────────

View File

@@ -128,7 +128,7 @@ def ca_chain():
)
fullchain = server_crt + "\n" + intermediate_crt
server_key_passphrase = "test-passphrase-12345"
server_key_passphrase = "test-passphrase-12345" # gitleaks:allow
server_key_encrypted = server_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,

View File

@@ -40,7 +40,7 @@
# - _process_states_for_end() — removes chart and restores layout
#
# @REJECTED
# Calling the API route directly rejected — requires TaskManager auth, JWT/permission setup,
# Calling the API route directly rejected — requires TaskManager auth, JWT/permission setup, gitleaks:allow
# and async TaskManager processing which adds ~30s per test without additional coverage.
# Mocking SupersetClient rejected — would test the orchestrator's SQL logic but not the
# actual Superset API integration.

View File

@@ -54,8 +54,8 @@ def test_tui_initial_render(mock_curses_module, mock_stdscr: MagicMock):
titles, headers, footers and the READY state are drawn appropriately.
"""
# Ensure constants match
mock_curses_module.KEY_F10 = curses.KEY_F10
mock_curses_module.KEY_F5 = curses.KEY_F5
mock_curses_module.KEY_F10 = curses.KEY_F10 # gitleaks:allow
mock_curses_module.KEY_F5 = curses.KEY_F5 # gitleaks:allow
mock_curses_module.color_pair.side_effect = lambda x: x
mock_curses_module.A_BOLD = 0
@@ -90,8 +90,8 @@ def test_tui_run_checks_f5(mock_curses_module, mock_stdscr: MagicMock):
Simulates pressing F5 to transition into the RUNNING checks flow.
"""
# Ensure constants match
mock_curses_module.KEY_F10 = curses.KEY_F10
mock_curses_module.KEY_F5 = curses.KEY_F5
mock_curses_module.KEY_F10 = curses.KEY_F10 # gitleaks:allow
mock_curses_module.KEY_F5 = curses.KEY_F5 # gitleaks:allow
mock_curses_module.color_pair.side_effect = lambda x: x
mock_curses_module.A_BOLD = 0
@@ -129,7 +129,7 @@ def test_tui_exit_f10(mock_curses_module, mock_stdscr: MagicMock):
Simulates pressing F10 to exit the application immediately without running checks.
"""
# Ensure constants match
mock_curses_module.KEY_F10 = curses.KEY_F10
mock_curses_module.KEY_F10 = curses.KEY_F10 # gitleaks:allow
app = CleanReleaseTUI(mock_stdscr)
mock_stdscr.getch.return_value = curses.KEY_F10
@@ -149,8 +149,8 @@ def test_tui_clear_history_f7(mock_curses_module, mock_stdscr: MagicMock):
"""
Simulates pressing F7 to clear history.
"""
mock_curses_module.KEY_F10 = curses.KEY_F10
mock_curses_module.KEY_F7 = curses.KEY_F7
mock_curses_module.KEY_F10 = curses.KEY_F10 # gitleaks:allow
mock_curses_module.KEY_F7 = curses.KEY_F7 # gitleaks:allow
mock_curses_module.color_pair.side_effect = lambda x: x
mock_curses_module.A_BOLD = 0
@@ -183,7 +183,7 @@ def test_tui_real_mode_bootstrap_imports_artifacts_catalog(
"""
@TEST_CONTRACT: bootstrap.json + artifacts.json -> candidate PREPARED with imported artifacts
"""
mock_curses_module.KEY_F10 = curses.KEY_F10
mock_curses_module.KEY_F10 = curses.KEY_F10 # gitleaks:allow
mock_curses_module.color_pair.side_effect = lambda x: x
mock_curses_module.A_BOLD = 0

View File

@@ -33,8 +33,8 @@ def _build_mock_stdscr() -> MagicMock:
# @PURPOSE: Verify F5 key dispatch invokes run_checks exactly once before graceful exit.
def test_tui_f5_dispatches_run_action(mock_curses_module: MagicMock) -> None:
"""F5 should dispatch run action from TUI loop."""
mock_curses_module.KEY_F10 = curses.KEY_F10
mock_curses_module.KEY_F5 = curses.KEY_F5
mock_curses_module.KEY_F10 = curses.KEY_F10 # gitleaks:allow
mock_curses_module.KEY_F5 = curses.KEY_F5 # gitleaks:allow
mock_curses_module.color_pair.side_effect = lambda value: value
mock_curses_module.A_BOLD = 0
@@ -57,8 +57,8 @@ def test_tui_f5_dispatches_run_action(mock_curses_module: MagicMock) -> None:
# @PURPOSE: Verify blocked compliance state is surfaced after F5-triggered run action.
def test_tui_f5_run_smoke_reports_blocked_state(mock_curses_module: MagicMock) -> None:
"""F5 smoke test should expose blocked outcome state after run action."""
mock_curses_module.KEY_F10 = curses.KEY_F10
mock_curses_module.KEY_F5 = curses.KEY_F5
mock_curses_module.KEY_F10 = curses.KEY_F10 # gitleaks:allow
mock_curses_module.KEY_F5 = curses.KEY_F5 # gitleaks:allow
mock_curses_module.color_pair.side_effect = lambda value: value
mock_curses_module.A_BOLD = 0
@@ -105,8 +105,8 @@ def test_tui_non_tty_refuses_startup(capsys) -> None:
# @PURPOSE: Verify F8 path reports disabled action instead of mutating hidden facade state.
def test_tui_f8_blocked_without_facade_binding(mock_curses_module: MagicMock) -> None:
"""F8 should not perform hidden state mutation when facade action is not bound."""
mock_curses_module.KEY_F10 = curses.KEY_F10
mock_curses_module.KEY_F8 = curses.KEY_F8
mock_curses_module.KEY_F10 = curses.KEY_F10 # gitleaks:allow
mock_curses_module.KEY_F8 = curses.KEY_F8 # gitleaks:allow
mock_curses_module.color_pair.side_effect = lambda value: value
mock_curses_module.A_BOLD = 0

View File

@@ -400,7 +400,7 @@ def seed_execution_fixture(db: Session) -> None:
entry = ScenarioRegistryEntry(
scenario_id=_EXEC_SCENARIO_ID,
scenario_key="fi-0080_execution-fixture",
scenario_key="fi-0080_execution-fixture", # gitleaks:allow
name="FI-0080 Execution fixture",
description="Canonical 044 executable graph + run states",
dashboard_id=80,

View File

@@ -344,7 +344,7 @@ def test_pending_approval_run_is_not_dispatched_until_gate_approval(registry_ses
params={},
environment_id="prod",
actor="ops.oncall-046",
idempotency_key="due-admission-approval-046",
idempotency_key="due-admission-approval-046", # gitleaks:allow
trigger_source="scheduled",
)
registry_session.commit()

View File

@@ -340,7 +340,7 @@ def test_assertion_pass_records_policy_decision(seeded_execution):
{},
"env-preprod-02",
actor="test-walker",
idempotency_key="walker-policy-001",
idempotency_key="walker-policy-001", # gitleaks:allow
auto_advance=False,
)
run.runner_plan = _action_plan("policy-assert-044", "assertion", "compare_to_baseline")
@@ -380,7 +380,7 @@ def test_required_evidence_integrity_becomes_blocked(seeded_execution):
{},
"env-preprod-02",
actor="test-walker",
idempotency_key="walker-policy-002",
idempotency_key="walker-policy-002", # gitleaks:allow
auto_advance=False,
)
run.runner_plan = _action_plan("shot-integrity-044", "screenshot", "capture_screenshot")
@@ -498,7 +498,7 @@ def test_walker_required_missing_adapter_unavailable(seeded_execution):
{},
"env-preprod-02",
actor="test-walker",
idempotency_key="walker-eval-missing-001",
idempotency_key="walker-eval-missing-001", # gitleaks:allow
auto_advance=False,
)
run.runner_plan = _required_eval_plan("eval-missing-044")

View File

@@ -107,7 +107,7 @@ def test_persist_raw_response_redacts_credentials_and_pii(tmp_path: Path) -> Non
raw = {
"model": "vlm-1",
"message": "checked",
"notes": "password=hunter2 api_key=sk-1234567890abcdefgh token=abcdef1234567890",
"notes": "password=hunter2 api_key=sk-1234567890abcdefgh token=abcdef1234567890", # gitleaks:allow
"contact": "analyst@corp.example",
"findings": [{"criterion_id": "c1", "status": "pass"}],
}

View File

@@ -8,7 +8,7 @@ import sys
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
import os
os.environ.setdefault("ENCRYPTION_KEY", "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0=")
os.environ.setdefault("ENCRYPTION_KEY", "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0=") # gitleaks:allow
from unittest.mock import MagicMock, patch
import pytest

View File

@@ -16,7 +16,7 @@ import pytest
# Set ENCRYPTION_KEY before importing anything that uses EncryptionManager
import os
os.environ.setdefault("SECRET_KEY", "test-secret-key-for-testing")
os.environ.setdefault("ENCRYPTION_KEY", "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0=")
os.environ.setdefault("ENCRYPTION_KEY", "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0=") # gitleaks:allow
from src.schemas.profile import ProfilePreferenceUpdateRequest

View File

@@ -165,7 +165,7 @@ def test_extra_local_suffixes_extendible(monkeypatch):
# @RELATION BINDS_TO -> [Services.LlmProvider.CreateProvider]
def _config(base_url: str) -> MagicMock:
os.environ.setdefault(
"ENCRYPTION_KEY", "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0="
"ENCRYPTION_KEY", "MldUHg5kwSAcPnnYxmhWDS6ASb6e_bWQRV5gtwHrjQ0=" # gitleaks:allow
)
config = MagicMock()
config.name = "Perimeter Test"

View File

@@ -536,7 +536,7 @@ class TestLogMasking:
masked = _mask_details({
"username": "john",
"password": "supersecret",
"token": "eyJhbGciOiJIUzI1NiJ9.xxx",
"token": "eyJhbGciOiJIUzI1NiJ9.xxx", # gitleaks:allow
"api_key": "ssk_abc123",
"source": "LOCAL",
})

View File

@@ -5,7 +5,7 @@
// @TEST_CONTRACT: getReportsSummary -> GET /reports/summary via api.fetchApi
// @TEST_CONTRACT: getReportsSettings -> GET /settings/reports via api.fetchApi
// @TEST_CONTRACT: updateReportsSettings -> PUT /settings/reports via api.requestApi
// @TEST_EDGE: api_error -> fetchApi/rejection propagates normalized error
// @TEST_EDGE: api_error -> fetchApi/rejection propagates normalized error gitleaks:allow
// @TEST_EDGE: settings_update -> requestApi with payload and method
import { describe, it, expect, vi, beforeEach } from 'vitest';