Docs/Deploy/Security scan

Security scan

6 min read
On this page

dokwe security scans a codebase for security problems before they reach production. It runs entirely on your machine: no code, file names or dependency lists are sent anywhere, and it uses no AI.

bash
dokwe security

It checks four things:

  • Vulnerable dependencies: every lockfile is matched against the OSV vulnerability database, kept on your machine.
  • Leaked secrets: API keys, tokens and private keys in your files, and with --history in your git history.
  • Insecure code: patterns behind common attacks, such as SQL built from strings, shell commands built from input, and TLS checks turned off.
  • Deploy configuration: containers running as root, secrets in Dockerfiles, committed .env files, debug mode left on.

You don't need to be logged in.

First run#

The scanner is a separate download, so the CLI itself stays small. The first time you run dokwe security, it asks first:

text
The security scanner isn't installed yet. It's a one-time download of 45.2 MB,
and it scans your code on this machine: nothing is uploaded.
Download it now? [Y/n]

It then shows a progress bar, checks the file against its published SHA-256 checksum, and runs the scan. The scanner lives in ~/.dokwe/bin. After you update the CLI, the next dokwe security offers the matching scanner the same way.

The first scan of each kind of project also downloads that ecosystem's vulnerability database, once. Sizes vary: about 210 MB for npm, 36 MB for PyPI, and 3 to 12 MB for Go, Packagist, RubyGems, crates.io and Maven. It's kept in ~/.dokwe/osv.

Reading the report#

text
Leaked secrets (1)
  CRITICAL Stripe access token in app/settings.py
           app/settings.py:3
           This file contains what looks like a Stripe access token (sk_l••••••).
           Fix: Remove it from the code, load it from an environment variable, and revoke the key
                with whoever issued it: anyone who has seen this file may have it.

Vulnerable dependencies (1)
  CRITICAL django 3.2.0 has 38 known vulnerabilities
           requirements.txt
           CVE-2021-35042 (critical 9.8): SQL Injection in Django. Fixed in 3.2.5
           ...
           Fix: Upgrade django to 5.2.17 or later, which fixes all of them.

15 problems: 2 critical, 9 high, 3 medium, 1 low
Scanned 6 files and 2 packages in 2.1s, on this machine. Vulnerability data from 26 hours ago.

Findings are sorted by severity: critical, high, medium, low. Each one has the file and line, what's wrong, and how to fix it.

  • Dependencies show one finding per vulnerable package, with its worst advisories and the version that fixes them for the release line you're on.
  • Secrets are never printed, only their first few characters. Keys matching a known provider's format (Stripe, AWS, GitHub and hundreds more) are critical, because they work as they stand; generic key-shaped values are medium ("Possible secret"); anything found in a test file is low, because it's usually a fake.

On every deploy#

The same scanner also runs on Dokwe before each deploy builds, on whatever builds it: Dokwe's build servers, or your own server's agent. If it finds critical problems, the deploy waits for an owner or admin to proceed (with a reason, recorded in the audit log) or cancel. Each project chooses the level under Settings → Security: hold on critical, hold on high or critical, scan but never hold, or off. On the deploy page, Export downloads the findings as a spreadsheet (CSV), Markdown for a ticket or pull request, or JSON.

Audit what's running#

New vulnerabilities are published every day, so code that passed its scan when it deployed can have a known problem now. Open a project's Observability → Security and click Run security audit to scan the commit that's live in each environment again. Anyone in the workspace except viewers can run one.

  • Where it runs: the same place that environment's deploys are scanned. That's Dokwe's build servers for projects Dokwe builds, or your own server, through its agent, for projects built there. On your server, the code is cloned to a temporary folder, scanned and deleted, and only the findings are sent to Dokwe. Scanning on your server needs agent 0.5.2 or later.
  • What it scans: the exact commit that's live, not whatever the branch points at now. Environments running the same commit are scanned once.
  • It only reports. An audit never holds, stops or changes anything.
  • New since the last audit: findings that weren't in that environment's previous audit (or, the first time, in the deploy's own scan) are tagged New. If the code didn't change, the vulnerability database did.
  • Every Monday morning, Dokwe audits each project again on its own. Owners and admins get an email and a push notification only when it finds something new at the project's hold level: critical, or high and critical when the project holds on high. Turn the weekly audit off under Settings → Security.
  • History: the last 12 audits of each environment are kept. Export downloads the findings as CSV, Markdown or JSON.

Projects deployed from a ready-made Docker image have no source code on Dokwe, so there's nothing to audit. Run dokwe security where the image is built.

What stays on your machine#

Everything. While it scans, the scanner blocks every network request except downloads of the public OSV database from osv-vulnerabilities.storage.googleapis.com. Those requests fetch whole-ecosystem files (for example npm/all.zip), so they don't reveal anything about your project. If anything else tries to connect, the request is refused and the report says so.

The vulnerability database refreshes at most every 3 days, and the report says how old it is. Use --update-db to refresh it now, or --offline to never download anything.

What it skips#

  • Folders that aren't your code: node_modules, vendor, .git, dist, build, .next, .venv, __pycache__, coverage and similar.
  • Files over 1 MB, binary files, minified files and lockfiles (lockfiles are covered by the dependency scan).
  • Your local .env: secrets are meant to live there. A .env that's committed to git is reported.
  • Tests and fixtures, for the insecure-code checks. Use --include-tests to include them.

Silencing a finding#

After you've reviewed a line and it's fine, add a comment on it or on the line above:

js
db.query(`SELECT * FROM ${table}`) // dokwe-ignore: js-sql-template

dokwe-ignore on its own silences every check on that line; dokwe-ignore: <rule-id> silences one rule (the ID is in --json output). For secrets, use dokwe-ignore: secret. Lines already marked #nosec or nolint:gosec for other scanners are skipped too.

To leave out whole paths, use --exclude:

bash
dokwe security --exclude "design/**" --exclude scripts/seed.ts

Use it in CI#

The scan exits with status 1 when it finds a problem at --fail-on severity or above (default high), and 2 if it couldn't run. In CI, pass --yes so it downloads the scanner without asking.

This GitHub Actions workflow scans every push and shows the findings on the code in the pull request:

yaml
name: Security scan
on: [push, pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      security-events: write
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # full history, for --history
      - run: curl -sSL https://dokwe.com/install-cli.sh | bash
      - run: dokwe security --yes --history --sarif results.sarif --fail-on critical
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with:
          sarif_file: results.sarif

Checks#

Insecure-code checks are kept to patterns that are rarely wrong. A pattern can't follow data through your code, so checks that depend on user input only fire when the input is visibly on the same line.

LanguageChecks
JavaScript, TypeScriptSQL from template strings or +, Prisma $queryRawUnsafe, exec with interpolated values, eval / new Function on a variable, rejectUnauthorized: false, CORS with any origin and credentials, JWT none algorithm, MD5 or SHA-1 for passwords, Math.random for tokens, httpOnly: false cookies
PythonSQL built with f-strings, %, .format() or +, subprocess with shell=True, os.system with formatted strings, yaml.load without a safe loader, pickle.load, verify=False, eval / exec on a variable, Flask debug=True, MD5 or SHA-1 for passwords
PHPSQL, shell commands, include and unserialize with $_GET / $_POST / $_REQUEST / $_COOKIE, eval on a variable
GoInsecureSkipVerify: true, SQL built with fmt.Sprintf, sh -c commands built by joining strings
RubySQL built with string interpolation
Deploy configDockerfile: running as root, unpinned base image, secrets in ENV / ARG, copying .env, ADD from a URL. Compose: privileged: true, database ports published on every interface. Django DEBUG = True and ALLOWED_HOSTS = ['*'], Laravel APP_DEBUG=true in production settings, committed .env files

Flags#

text
dokwe security [folder] [flags]
FlagTypeDefaultDescription
--jsonboolfalsePrint the result as JSON
--sarifstringAlso write SARIF 2.1.0 to this file (GitHub code scanning)
--fail-onstringhighExit with status 1 at this severity or above: critical, high, medium, low
--historyboolfalseAlso scan git history for secrets (slower)
--update-dbboolfalseRefresh the vulnerability database now
--offlineboolfalseNever download anything; use the vulnerability data already on this machine
--include-testsboolfalseAlso check tests and fixtures for insecure code
--excludestring arrayPaths or globs to leave out (repeatable)
--skipstring arrayLeave out a check: deps, secrets, code, config
-y, --yesboolfalseDownload the scanner without asking (for CI)