Codeql security scanner

From seaworld008/Commonly-used-high-value-skills · View interactive version

Codeql security scanner is an AI agent skill from the GitHub repository seaworld008/Commonly-used-high-value-skills. Use when running CodeQL semantic code scanning: build databases, run security or custom query suites, and produce SARIF for GitHub code scanning.

How to use this skill

Skill file

CodeQL Security Scanner

Trigger / When to Use

Use this skill when the user wants deep semantic code scanning, GitHub Advanced Security style analysis, custom CodeQL queries, SARIF output, or vulnerability investigation with CodeQL databases.

Good trigger phrases:

Core Capabilities

Workflow

1. Identify Languages

Inspect the repository:

rg --files | sed -n '1,160p'

Determine:

2. Verify CodeQL CLI

codeql version

If missing, use official GitHub CodeQL CLI installation guidance. For GitHub-hosted workflows, prefer github/codeql-action.

3. Create a Database

For compiled languages, provide the real build command:

codeql database create codeql-db --language=java --command="mvn -DskipTests package"

For JavaScript or TypeScript:

codeql database create codeql-db --language=javascript-typescript

For Python:

codeql database create codeql-db --language=python

If database creation fails, fix dependency installation or build steps before analyzing.

4. Run Queries

Default query suite:

codeql database analyze codeql-db --format=sarif-latest --output=codeql.sarif

Security extended suite:

codeql database analyze codeql-db codeql/javascript-queries:codeql-suites/javascript-security-extended.qls --format=sarif-latest --output=codeql.sarif

Adapt the query pack path to the detected language and installed CodeQL pack layout.

5. Triage Alerts

For each alert:

Prioritize:

  1. Dataflow alerts with realistic user-controlled input.
  2. Authentication, authorization, injection, deserialization, SSRF, and path traversal.
  3. Alerts in deployed services over test-only code.
  4. Alerts recurring across many files.

6. Write or Run Custom Queries

Use custom queries when a project has its own framework wrappers:

/**
 * @name Example dangerous API use
 * @kind problem
 * @problem.severity warning
 * @security-severity 6.0
 * @id custom/dangerous-api
 */
import javascript

from CallExpr call
where call.getCalleeName() = "dangerousEval"
select call, "Avoid dangerousEval with untrusted input."

Keep custom queries versioned with tests where possible.

Common Patterns

GitHub Actions CodeQL

name: codeql
on:
  pull_request:
  push:
    branches: [main]
jobs:
  analyze:
    runs-on: ubuntu-latest
    permissions:
      security-events: write
      contents: read
    steps:
      - uses: actions/checkout@v4
      - uses: github/codeql-action/init@v3
        with:
          languages: javascript-typescript
          queries: security-extended
      - uses: github/codeql-action/analyze@v3

Local Investigation Checklist

1. Reproduce the alert with CodeQL CLI.
2. Open path explanation and inspect each step.
3. Confirm source is user-controllable.
4. Confirm sink is security-sensitive.
5. Fix with framework-native safe API.
6. Add regression test.
7. Re-run the relevant query.

Alert Report Template

## CodeQL Alert

- Query:
- Severity:
- Location:
- Source:
- Sink:
- Path summary:
- Exploit condition:
- Fix:
- Test:

Interpretation Rules

Boundaries

Reference Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.