SAST: статичне тестування безпеки додатку
SAST (Static Application Security Testing) аналізує вихідний код без виконання — знаходить вразливості на етапі розробки. SQL injection, XSS, hardcoded secrets, небезпечні функції — до потрапляння на production.
Інструменти SAST
Semgrep — швидкий, правила для 30+ мов, можна писати спеціальні правила:
# Встановлення
pip install semgrep
# Сканування з набором правил безпеки
semgrep scan --config=p/security-audit \
--config=p/owasp-top-ten \
--config=p/typescript \
--json > semgrep-results.json
# Спеціальне правило: пошук прямої конкатенації SQL
cat > rules/sql-injection.yml << 'EOF'
rules:
- id: raw-sql-concatenation
patterns:
- pattern: |
"SELECT ... " + $VAR
- pattern: |
`SELECT ... ${$VAR}`
message: "Potential SQL injection: use parameterized queries"
severity: ERROR
languages: [typescript, javascript]
EOF
semgrep scan --config=rules/sql-injection.yml src/
GitHub Advanced Security (CodeQL):
# .github/workflows/codeql.yml
name: CodeQL
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 0 * * 1' # Щотижнево
jobs:
analyze:
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
strategy:
matrix:
language: [javascript-typescript]
steps:
- uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Analyze
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
Сканування секретів
# Gitleaks: пошук секретів у коді та історії git
docker run --rm -v $(pwd):/path \
zricethezav/gitleaks:latest detect \
--source /path \
--report-format json \
--report-path /path/gitleaks-report.json
# truffleHog: аналіз історії git
trufflehog git file://. --json > secrets-report.json
# GitHub Actions: pre-commit hook на секреты
- name: Check for secrets
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
Плагіни ESLint Security
npm install --save-dev eslint-plugin-security \
eslint-plugin-no-unsanitized \
@microsoft/eslint-plugin-sdl
// .eslintrc.json
{
"plugins": ["security", "no-unsanitized", "@microsoft/sdl"],
"extends": [
"plugin:security/recommended",
"plugin:@microsoft/sdl/required"
],
"rules": {
"security/detect-object-injection": "error",
"security/detect-non-literal-regexp": "warn",
"security/detect-possible-timing-attacks": "error",
"no-unsanitized/method": "error",
"no-unsanitized/property": "error"
}
}
Інтеграція в CI/CD
# .github/workflows/sast.yml
name: SAST
on: [push, pull_request]
jobs:
semgrep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: returntocorp/semgrep-action@v1
with:
config: >-
p/security-audit
p/owasp-top-ten
p/typescript
auditOn: push
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
secrets-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Правило SAST: не блокуємо PR при кожному попередженню — тільки при HIGH та CRITICAL. Усе інше — у backlog security debt.
Налаштування Semgrep + CodeQL + Gitleaks у CI/CD — 1–2 робочих дні.







