SAST Vulnerability Analysis
Purpose
Systematically analyze source code for security vulnerabilities using structured Source→Sink taint tracking,
pattern matching, and vulnerability-class-specific detection heuristics. Produce actionable findings with
severity ratings, affected code locations (file + line number), and remediation guidance.
Scope
This skill covers the following 34 vulnerability classes. Each has a dedicated reference file loaded on demand:
| Category | Vulnerabilities |
|---|
| Injection | SQL Injection, XSS, SSTI, NoSQL Injection, GraphQL Injection, XXE, RCE / Command Injection, Expression Language Injection |
| Access Control & Auth |
IDOR, Privilege Escalation, Authentication/JWT, Default Credentials, Brute Force, Business Logic, HTTP Method Tampering, Verification Code Abuse, Session Fixation |
|
Data Exposure & Crypto | Weak Crypto/Hash, Information Disclosure, Insecure Cookie, Trust Boundary |
|
Server-Side | SSRF, Path Traversal/LFI/RFI, Insecure Deserialization, Arbitrary File Upload, JNDI Injection, Race Conditions |
|
Protocol & Infrastructure | CSRF, Open Redirect, HTTP Request Smuggling/Desync, Denial of Service, CVE Patterns |
|
Language/Platform | PHP Security, Mobile Security (Android/iOS) |
Workflow
Step 1: Understand Scope
Determine:
- - Target: single file, directory, API endpoint, module, or full repo
- Language(s) and framework(s) in use
- User's goal: quick scan, deep audit, specific vuln class, or full report
Step 2: Load Relevant References
Based on the code being reviewed, load the appropriate reference files from references/:
CODEBLOCK0
Loading strategy:
- - For a targeted review (e.g., "check for SQL injection"), load only the relevant reference(s).
- For a full audit, load all 34 references and scan systematically.
- Always load references for the top OWASP risks even if not explicitly requested.
Step 3: Analyze Code — Source→Sink Taint Tracking
For each loaded vulnerability class, perform taint analysis:
- 1. Identify Sources — User-controlled input entry points:
- HTTP params, headers, cookies, request body
- File uploads
- WebSocket messages
- Environment variables
- Database reads of user-supplied data, deserialized objects
- 2. Trace Data Flow — Follow the data through:
- Variable assignments, function arguments, return values
- Framework helpers, ORM calls, template rendering
- Cross-module/service boundaries
- 3. Check Sinks — Dangerous operations receiving tainted data:
- Query execution (SQL, NoSQL, LDAP, XPath)
- Shell/OS command execution
- File system operations
- HTTP client calls
- Template rendering / eval / expression parsing
- Serialization/deserialization
- 4. Evaluate Sanitization — Between source and sink, look for:
- Input validation (allowlist vs denylist)
- Context-appropriate encoding/escaping
- Parameterization (prepared statements)
- Framework-native protections
- 5. Determine Preliminary Verdict:
-
VULN: Taint reaches sink with no effective sanitization
-
LIKELY VULN: Sanitization present but bypassable per reference heuristics
-
SAFE: Effective sanitization or no taint path
Step 4: Business Logic & Auth Analysis
Beyond taint tracking, check for:
- - Missing authentication/authorization on sensitive endpoints
- Insecure state machine transitions
- Race conditions in concurrent operations
- Improper trust boundaries between components
- JWT algorithm confusion, token fixation, session issues
- Default/hardcoded credentials
- Enumeration via timing or response differences
Step 5: Judge — Validity Re-Verification
Before reporting, every preliminary finding (VULN or LIKELY VULN) must pass a Judge review. The Judge acts as an adversarial second opinion to eliminate false positives.
For each candidate finding, answer all of the following:
Reachability Check
- - [ ] Is the source actually user-controlled, or is it internal/trusted data?
- [ ] Is the vulnerable code path reachable from an HTTP endpoint / entry point, or is it dead code / internal-only?
- [ ] Are there upstream guards (auth middleware, input filters) that block the path before it reaches the sink?
Sanitization Re-Evaluation
- - [ ] Is there sanitization that was missed in Step 3? (Check parent functions, middleware, framework internals)
- [ ] Is the sanitization method sufficient for this specific sink and context?
- [ ] Does the framework provide implicit protection for this pattern?
Exploitability Check
- - [ ] Can the tainted value actually reach the sink in a form that triggers the vulnerability?
- [ ] Is exploitation conditional on a specific environment, config, or privilege level?
- [ ] For logic bugs: is the business impact real, or hypothetical?
- [ ] Is the chosen tag the most precise valid label for this finding?
Judge Verdict
| Verdict | Meaning | Action |
|---|
| CONFIRMED | All reachability/sanitization/exploitability checks pass | Include in report |
| LIKELY |
Most checks pass; one uncertainty remains | Include in report, flag uncertainty |
|
NEEDS CONTEXT | Cannot determine without runtime behavior / config / additional files | Note as "unverifiable without X" |
|
FALSE POSITIVE | Positive evidence of protection found — cite the exact file+line of the sanitization, allowlist check, guard, or framework-level auto-protection that makes the sink safe | Drop silently |
Only CONFIRMED and LIKELY findings are reported.
FP burden of proof: UNCERTAIN on any check is NOT sufficient to declare FALSE POSITIVE. If a check result is UNCERTAIN after inspecting the sink, its callers, and the framework internals, use NEEDS CONTEXT instead. Only use FALSE POSITIVE when you have found and can cite positive evidence that the path is protected.
Judge Output Format (internal, before reporting)
CODEBLOCK1
False Positive Guardrails
Tags
- -
default_credentials: require a reachable auth path that accepts the hardcoded credential. - INLINECODE4 : require direct use of weak hash/algo — not just an import or third-party component. Covers both weak algorithms (DES, RC4, ECB) and weak hashes (MD5, SHA-1 for passwords); do not use
weak_crypto as a separate tag. - INLINECODE6 → prefer
command_injection for direct shell/process execution. Do not replace spel_injection with rce/command_injection. - INLINECODE11 in demos: only if the JNDI sink is the primary exploit path.
- Broad tags (
trust_boundary, authentication, privilege_escalation): prefer the narrowest valid tag (xff_spoofing, session_fixation, verification_code). - INLINECODE18 : only if the attacker-controlled redirect is the primary exploit (not infra/parser misconfiguration).
- INLINECODE19 : skip for stateless Bearer-token-only APIs (
SessionCreationPolicy.STATELESS). - INLINECODE21 : skip if
component_vulnerability covers the same sink. - INLINECODE23 : skip for avatar/profile upload with type restrictions and non-webroot storage.
- INLINECODE24 : skip when Spring Security default session management is active.
- INLINECODE25 : skip for DB credentials in config files — deployment issue, not app-level.
Scope
- - Demo/example code: skip any finding whose ONLY vulnerable path is in
examples/, demo/, sample/ (or similar). Report only if the bug is in the library/SDK itself. - Non-default config: verify the DEFAULT value before reporting. Requires non-default/deprecated → cap
Low. Explicitly labeled legacy or deprecated in code/docs → cap Informational.
Trust Boundary
- - Operator self-harm: skip findings where the "attacker" input comes from operator-written config files (YAML/JSON/TOML), CLI flags the operator supplies themselves (
--file, --url, --chain-id), or commands the operator must explicitly run. - Trusted admin role: skip
privilege_escalation/business_logic for actions behind onlyAdmin/onlyOwner/onlyPoolAdmin when that role is trusted by design. Only report if an unprivileged user can reach the same path. - Internal-only service: skip
authentication and information_disclosure when the entire codebase has zero auth AND references internal infra (VPC vars, EC2_INSTANCE_ID, Eureka, Consul). Auth is at the network layer. - Code generators: skip
injection/path_traversal/rce for codegen tools (protoc, swagger-codegen, etc.) whose input comes from developer-controlled source comments, annotations, or local config.
Protocol & Architecture
- - Protocol-designed SSRF: skip
ssrf when fetching a peer-supplied URL is required by spec (LNURL, UMA, OAuth discovery, WebFinger, OIDC discovery). Only report if the impl allows schemes the protocol does not require (e.g., file://) or skips required domain validation. - Blind SSRF: downgrade to
Informational when all three hold: (a) response never reaches the attacker, (b) no meaningful side effect on the target, (c) no error oracle. - Bounded DoS: skip
denial_of_service unless the upper bound of the iterated/allocated data is attacker-controllable and unbounded. Naturally bounded data (blockchain validator set, gas limits, etcd/request-body size caps) → not a finding. - Brute force: skip
brute_force only if rate limiting is visible in code, framework config, or referenced middleware in the repo. Do not assume infrastructure-level rate limiting. - Idempotent replay: skip replay/
business_logic when the operation is idempotent AND parameters are cryptographically signed (no tampering possible). - Library dead path: if no real caller in the codebase triggers the vulnerable parameter combination AND the code has a warning log for that path →
NEEDS CONTEXT, not a finding.
Platform
- - Android app-private storage: skip
insecure_storage/information_disclosure for SharedPreferences/DataStore in app-private storage without android:allowBackup="true" in a production manifest. - Terraform state: skip
information_disclosure for providers writing secrets to state when attributes are marked Sensitive: true. - Intra-org CI/CD: skip
supply_chain for mutable action tags (e.g., @v3) when the action org matches the repo org. Only report third-party org actions. - Local dev tools: skip
authentication for README-described local dev tools with no production docs. Exception: report (reduced severity) if the tool does not bind to localhost, exposes tokens in API responses, or allows destructive ops.
Pre-Report Checklist
- - [ ] Public-facing service, or internal-by-design (zero auth everywhere + internal infra refs)?
- [ ] Production code, or demo/example/sample directory?
- [ ] Attacker is genuinely untrusted, not an admin/operator within their own trust boundary?
- [ ] Verify DEFAULT config value — does the attack work with defaults?
- [ ] SSRF required by protocol spec?
- [ ] SSRF response reachable by attacker (readable / side effect / error oracle)?
- [ ] Sensitive storage protected by OS sandbox (Android app-private)?
- [ ] Replay: is the operation idempotent with signature-bound parameters?
- [ ] Library: does any real caller trigger the vulnerable path?
- [ ] Terraform state with
Sensitive: true — by design? - [ ] DoS: is the upper bound attacker-controllable and unbounded?
- [ ] CI/CD mutable tags: same org or third-party?
- [ ] Admin action within the admin's designed trust boundary?
Step 6: Report Findings
Severity Classification
| Severity | Criteria |
|---|
| Critical | Direct RCE, authentication bypass, unauthenticated data exposure |
| High |
SQLi, SSRF, IDOR with sensitive data, stored XSS, privilege escalation |
|
Medium | Reflected XSS, CSRF, path traversal, insecure deserialization |
|
Low | Information disclosure, open redirect, weak crypto, insecure cookie |
|
Info | Missing security headers, verbose errors, defense-in-depth gaps |
Severity Downgrade Rule: When exploitation requires authentication, specific non-default configuration, chained prerequisites, or is only reachable through an internal/admin-only path, downgrade severity by one level from the class default; LIKELY-verdict findings whose exploitability is marked UNCERTAIN must be capped at one level below the class default regardless of vulnerability type.
Finding Format
CODEBLOCK2
For NEEDS CONTEXT findings:
CODEBLOCK3
Report Structure
When producing a full report, write to sast_report.md (or user-specified path):
CODEBLOCK4
Key Principles
- - Evidence over assertion: always show the vulnerable code path, not just the pattern name
- Context matters: a finding is only valid if the sink is reachable with user-controlled data
- Avoid false positives: if sanitization exists, verify it is bypassable before marking VULN
- Be precise: include exact file paths and line numbers — never approximate
- Fix > flag: always provide a concrete remediation, not just a problem statement
- Language-aware: adapt sink/source patterns to the specific language and framework in use
SAST 漏洞分析
目的
使用结构化的源→汇污点追踪、模式匹配和特定漏洞类别的检测启发式方法,系统性地分析源代码中的安全漏洞。生成可操作的安全发现,包括严重性评级、受影响的代码位置(文件+行号)和修复指导。
范围
本技能涵盖以下34个漏洞类别。每个类别都有按需加载的专用参考文件:
| 类别 | 漏洞 |
|---|
| 注入 | SQL注入、XSS、SSTI、NoSQL注入、GraphQL注入、XXE、RCE/命令注入、表达式语言注入 |
| 访问控制与认证 |
IDOR、权限提升、认证/JWT、默认凭据、暴力破解、业务逻辑、HTTP方法篡改、验证码滥用、会话固定 |
|
数据泄露与加密 | 弱加密/哈希、信息泄露、不安全的Cookie、信任边界 |
|
服务端 | SSRF、路径遍历/LFI/RFI、不安全的反序列化、任意文件上传、JNDI注入、竞态条件 |
|
协议与基础设施 | CSRF、开放重定向、HTTP请求走私/不同步、拒绝服务、CVE模式 |
|
语言/平台 | PHP安全、移动安全(Android/iOS) |
工作流程
步骤1:了解范围
确定:
- - 目标:单个文件、目录、API端点、模块或完整仓库
- 使用的语言和框架
- 用户目标:快速扫描、深度审计、特定漏洞类别或完整报告
步骤2:加载相关参考
根据正在审查的代码,从references/加载适当的参考文件:
references/sql_injection.md — SQL / ORM注入
references/xss.md — 跨站脚本攻击
references/ssrf.md — 服务端请求伪造
references/rce.md — 远程代码执行
references/idor.md — 不安全的直接对象引用
references/authentication_jwt.md — 认证缺陷、JWT弱点
references/csrf.md — 跨站请求伪造
references/pathtraversallfi_rfi.md — 路径遍历、LFI/RFI
references/ssti.md — 服务端模板注入
references/xxe.md — XML外部实体
references/insecure_deserialization.md — 不安全的反序列化
references/arbitraryfileupload.md — 任意文件上传
references/privilege_escalation.md — 权限提升
references/nosql_injection.md — NoSQL注入
references/graphql_injection.md — GraphQL注入
references/weakcryptohash.md — 弱加密/哈希
references/information_disclosure.md — 信息泄露
references/insecure_cookie.md — 不安全的Cookie属性
references/open_redirect.md — 开放重定向
references/trust_boundary.md — 信任边界违反
references/race_conditions.md — 竞态条件/TOCTOU
references/brute_force.md — 暴力破解/凭据填充
references/default_credentials.md — 默认/硬编码凭据
references/verificationcodeabuse.md — 验证码滥用
references/business_logic.md — 业务逻辑缺陷
references/httpmethodtamper.md — HTTP方法篡改
references/smuggling_desync.md — HTTP请求走私/不同步
references/cve_patterns.md — 已知CVE模式
references/expressionlanguageinjection.md — 表达式语言注入(SpEL / OGNL)
references/jndi_injection.md — JNDI注入(Log4Shell类)
references/denialofservice.md — 拒绝服务/资源耗尽
references/php_security.md — PHP特定安全问题
references/mobile_security.md — 移动安全(Android / iOS)
references/session_fixation.md — 会话固定
加载策略:
- - 对于针对性审查(例如,检查SQL注入),仅加载相关参考。
- 对于完整审计,加载所有34个参考并系统性地扫描。
- 即使未明确要求,始终加载OWASP顶级风险的参考。
步骤3:分析代码 — 源→汇污点追踪
对于每个加载的漏洞类别,执行污点分析:
- 1. 识别源 — 用户控制的输入入口点:
- HTTP参数、请求头、Cookie、请求体
- 文件上传
- WebSocket消息
- 环境变量
- 用户提供数据的数据库读取、反序列化对象
- 2. 追踪数据流 — 跟踪数据经过:
- 变量赋值、函数参数、返回值
- 框架辅助函数、ORM调用、模板渲染
- 跨模块/服务边界
- 3. 检查汇点 — 接收污染数据的危险操作:
- 查询执行(SQL、NoSQL、LDAP、XPath)
- Shell/OS命令执行
- 文件系统操作
- HTTP客户端调用
- 模板渲染/求值/表达式解析
- 序列化/反序列化
- 4. 评估净化 — 在源和汇之间,查找:
- 输入验证(白名单与黑名单)
- 上下文适当的编码/转义
- 参数化(预编译语句)
- 框架原生保护
- 5. 确定初步判定:
-
漏洞:污染到达汇点且无有效净化
-
疑似漏洞:存在净化但根据参考启发式方法可绕过
-
安全:有效净化或无污染路径
步骤4:业务逻辑与认证分析
除污点追踪外,检查:
- - 敏感端点缺少认证/授权
- 不安全的状态机转换
- 并发操作中的竞态条件
- 组件间不适当的信任边界
- JWT算法混淆、令牌固定、会话问题
- 默认/硬编码凭据
- 通过时序或响应差异进行枚举
步骤5:判断 — 有效性重新验证
在报告之前,每个初步发现(漏洞或疑似漏洞)必须通过判断审查。判断作为对抗性的第二意见,以消除误报。
对于每个候选发现,回答以下所有问题:
可达性检查
- - [ ] 源是否实际由用户控制,还是内部/受信任的数据?
- [ ] 易受攻击的代码路径是否可从HTTP端点/入口点到达,还是死代码/仅内部使用?
- [ ] 是否存在上游防护(认证中间件、输入过滤器)在到达汇点之前阻止该路径?
净化重新评估
- - [ ] 步骤3中是否遗漏了净化?(检查父函数、中间件、框架内部)
- [ ] 净化方法是否足以应对此特定汇点和上下文?
- [ ] 框架是否为此模式提供隐式保护?
可利用性检查
- - [ ] 污染值是否实际能够以触发漏洞的形式到达汇点?
- [ ] 利用是否依赖于特定环境、配置或权限级别?
- [ ] 对于逻辑错误:业务影响是真实的还是假设的?
- [ ] 所选标签是否是该发现最精确的有效标签?
判断判定
| 判定 | 含义 | 操作 |
|---|
| 已确认 | 所有可达性/净化/可利用性检查通过 | 包含在报告中 |
| 疑似 |
大多数检查通过;存在一个不确定性 | 包含在报告中,标记不确定性 |
|
需要上下文 | 无法在没有运行时行为/配置/附加文件的情况下确定 | 注明无法验证,缺少X |
|
误报 | 找到保护的正面证据 — 引用确切的文件+行号,说明净化、白名单检查、防护或框架级别的自动保护使汇点安全 | 静默丢弃 |
仅报告已确认和疑似的发现。
误报举证责任:任何检查的不确定不足以声明误报。如果在检查汇点、其调用者和框架内部后检查结果仍为不确定,则使用需要上下文替代。仅当找到并可以引用正面证据证明路径受到保护时,才使用误报。
判断输出格式(内部,报告前)
发现:VULN-NNN — <类别>
可达性: 通过 / 失败 / 不确定 — <原因>
净化: 通过 / 失败 / 不确定 — <原因>
可利用性: 通过 / 失败 / 不确定 — <原因>
判断判定: 已确认 / 疑似 / 需要上下文 / 误报
误报防护栏
标签
- - defaultcredentials:需要存在可接受硬编码凭据的可达认证路径。
- weakcryptohash:需要直接使用弱哈希/算法 — 不仅仅是导入或第三方组件。涵盖弱算法(DES、RC4、ECB)和弱哈希(MD5、SHA-1用于密码);不要使用weakcrypto作为单独标签。
- rce → 对于直接shell/进程执行,优先使用commandinjection。不要用rce/commandinjection替换