Back to list
5dlabs

codeql

by 5dlabs

Cognitive Task Orchestrator - GitOps on Bare Metal or Cloud for AI Agents

2🍴 1📅 Jan 25, 2026

SKILL.md


name: codeql description: CodeQL static analysis for interprocedural data flow and taint tracking across codebases.

CodeQL Static Analysis

When to Use CodeQL

Ideal scenarios:

  • Source code access with ability to build (for compiled languages)
  • Open-source projects or GitHub Advanced Security license
  • Need for interprocedural data flow and taint tracking
  • Finding complex vulnerabilities requiring AST/CFG analysis
  • Comprehensive security audits where analysis time is not critical

Consider Semgrep instead when:

  • No build capability for compiled languages
  • Licensing constraints
  • Need fast, lightweight pattern matching
  • Simple, single-file analysis is sufficient

Why Interprocedural Analysis Matters

Simple grep/pattern tools only see one function at a time. Real vulnerabilities often span multiple functions:

HTTP Handler → Input Parser → Business Logic → Database Query
     ↓              ↓              ↓              ↓
   source      transforms       passes        sink (SQL)

CodeQL tracks data flow across all these steps. A tainted input in the handler can be traced through 5+ function calls to find where it reaches a dangerous sink.

Installation

CodeQL CLI

# macOS/Linux (Homebrew)
brew install --cask codeql

# Update
brew upgrade codeql

Trail of Bits Queries (Optional)

# Download ToB query packs
codeql pack download trailofbits/cpp-queries trailofbits/go-queries

# Verify installation
codeql resolve qlpacks | grep trailofbits

Core Workflow

1. Create Database

codeql database create codeql.db --language=<LANG> [--command='<BUILD>'] --source-root=.
Language--language=Build Required
PythonpythonNo
JavaScript/TypeScriptjavascriptNo
GogoNo
RustrustYes (--command='cargo build')
Java/KotlinjavaYes (--command='./gradlew build')
C/C++cppYes (--command='make -j8')

2. Run Analysis

# SARIF output (recommended)
codeql database analyze codeql.db \
  --format=sarif-latest \
  --output=results.sarif \
  -- codeql/python-queries:codeql-suites/python-security-extended.qls

# With Trail of Bits queries
codeql database analyze codeql.db \
  --format=sarif-latest \
  --output=results.sarif \
  -- trailofbits/go-queries

Writing Custom Queries

Basic Template

/**
 * @name Find SQL injection vulnerabilities
 * @description Identifies potential SQL injection from user input
 * @kind path-problem
 * @problem.severity error
 * @security-severity 9.0
 * @precision high
 * @id py/sql-injection
 * @tags security
 *       external/cwe/cwe-089
 */

import python
import semmle.python.dataflow.new.DataFlow
import semmle.python.dataflow.new.TaintTracking

module SqlInjectionConfig implements DataFlow::ConfigSig {
  predicate isSource(DataFlow::Node source) {
    // Define taint sources (user input)
    exists(source)
  }
  
  predicate isSink(DataFlow::Node sink) {
    // Define dangerous sinks (SQL execution)
    exists(sink)
  }
}

module SqlInjectionFlow = TaintTracking::Global<SqlInjectionConfig>;

from SqlInjectionFlow::PathNode source, SqlInjectionFlow::PathNode sink
where SqlInjectionFlow::flowPath(source, sink)
select sink.getNode(), source, sink, "SQL injection from $@.", source.getNode(), "user input"

Query Metadata

FieldDescriptionValues
@kindQuery typeproblem, path-problem
@problem.severityIssue severityerror, warning, recommendation
@security-severityCVSS score0.0 - 10.0
@precisionConfidencevery-high, high, medium, low

CI/CD Integration (GitHub Actions)

name: CodeQL Analysis
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  schedule:
    - cron: '0 0 * * 1'  # Weekly

jobs:
  analyze:
    runs-on: ubuntu-latest
    permissions:
      actions: read
      contents: read
      security-events: write
    strategy:
      matrix:
        language: ['python', 'javascript']
    steps:
      - uses: actions/checkout@v4
      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          languages: ${{ matrix.language }}
          queries: security-extended, security-and-quality
      - uses: github/codeql-action/autobuild@v3
      - uses: github/codeql-action/analyze@v3
        with:
          category: "/language:${{ matrix.language }}"

Troubleshooting

IssueSolution
Database creation failsClean build environment, verify build command works independently
Slow analysisUse --threads, narrow query scope, check query complexity
Missing resultsCheck file exclusions, verify source files were parsed
Out of memorySet CODEQL_RAM=48000 environment variable (48GB)

Rationalizations to Reject

ShortcutWhy It's Wrong
"No findings means the code is secure"CodeQL only finds patterns it has queries for
"This code path looks safe"Complex data flow can hide vulnerabilities across 5+ function calls
"Small change, low risk"Small changes can introduce critical bugs; run full analysis
"The query didn't flag it"Default query suites don't cover everything; check custom queries

Resources

Attribution

Based on trailofbits/skills codeql skill.

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon