Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .java-audit.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ extra_rules: []
public_endpoints:
- /login
- /health
# 可选的专业报告档案字段;不会据此自动声明已经获得授权
report_owner: ""
authorization_ref: ""
scope_note: ""
retention_note: ""
# 添加团队规则时改为:
# extra_rules: [.java-audit/rules/team-rules.yaml]
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- 版本升级到 1.9.0,报告 JSON schema 升级到 1.4
- 为每条发现生成不含攻击载荷的验证任务卡,记录入口、鉴权、执行人、尝试次数、成功判据、进展、证据路径与结果
- 新增验证台账和实时统计,区分尚未开始、验证中、阻塞、已验证、确认漏洞与误报
- 新增八类常见误报归因,并将验证字段随 `review.json` 导出和导入
- 新增 `jal` 短命令;`jal .` 可直接扫描当前项目,同时保留 `java-audit scan` 兼容入口
- 新增 `s`、`d`、`r`、`b` 子命令别名及常用扫描参数的短选项;`jal . -O` 可在扫描完成后直接打开报告
- 新增匿名语料库试点:4 类规则、12 个 vulnerable/safe/edge Maven 案例及标准答案
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jal . -O
jal .
```

旧命令 `java-audit scan .` 继续兼容。已发布的 v1.8.0 wheel 可继续使用旧命令;`jal` 是当前源码版和下一版本的推荐入口。
旧命令 `java-audit scan .` 继续兼容。已发布的 v1.8.0 wheel 可继续使用旧命令;`jal` 是 v1.9.0 源码版的推荐入口。

### 常用短命令

Expand Down Expand Up @@ -153,6 +153,7 @@ jal s -h
| 稳定 | Git 增量审计 | 变更范围、权限放宽、同类位置、修复残留 |
| 稳定 | 多引擎归并 | SARIF、Semgrep、SpotBugs、Dependency-Check、CodeQL |
| 稳定 | 复核档案 | 本地保存、导入导出、基线新增与已修复分类 |
| 稳定 | 验证台账 | 任务卡、执行进度、成功判据、证据路径和误报归因 |
| 试点 | 匿名评测语料 | 四类 vulnerable / safe / edge 试点样本 |

**状态说明:** 稳定=已纳入常规测试 · 测试中=功能可用但仍在完善 · 试点=用于验证方向和评测流程
Expand Down Expand Up @@ -216,9 +217,13 @@ fail_on: high
cache: true
exclude_paths: [src/test/*, generated/*]
extra_rules: [.java-audit/rules/team-rules.yaml]
report_owner: security-team
authorization_ref: AUTH-2026-001
scope_note: 本次仅扫描后端服务目录
retention_note: 项目结束后按授权约定清理源码和缓存
```

命令行参数覆盖配置文件。放在 `.java-audit/rules/` 中的 YAML 或 JSON 规则会自动加载。
命令行参数覆盖配置文件。放在 `.java-audit/rules/` 中的 YAML 或 JSON 规则会自动加载。报告档案字段仅用于记录使用者提供的信息,工具不会据此自动声明已经获得授权。

## 可选 AI 解释

Expand All @@ -234,10 +239,13 @@ jal . -a -l beginner

路线图表示当前开发方向,不代表已经实现或承诺具体发布日期。

### 近期:下一版本
### v1.9:验证闭环

- [x] `jal` 短命令、默认扫描和常用参数别名
- [x] 完整中英文 README
- [x] 为每条发现生成不含攻击载荷的验证任务卡
- [x] 增加验证状态、执行人、尝试次数、成功判据和证据路径
- [x] 增加误报归因、验证台账和动态结果统计
- [ ] 将匿名语料扩展到更多规则、真实脱敏案例和独立 holdout 集
- [ ] 为 CLI 增加稳定的机器可读摘要和更清晰的退出码文档
- [ ] 增加 GitHub Actions 示例,让 Pull Request 自动执行增量审计
Expand All @@ -248,6 +256,8 @@ jal . -a -l beginner
- [ ] 更精确的调用图、接口实现和继承关系解析
- [ ] Spring WebFlux、Dubbo、gRPC 和更多消息框架入口
- [ ] 对象级权限与 IDOR 场景的所有权证据
- [ ] 在授权靶场中生成安全的人工验证步骤与修复复测记录
- [ ] 从复核结论生成脱敏回归案例
- [ ] 规则抑制、风险接受和审计结论的团队配置

### 长期:可扩展工作台
Expand Down
16 changes: 13 additions & 3 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jal . -O
jal .
```

The legacy `java-audit scan .` command remains supported. The published v1.8.0 wheel continues to use the legacy command; `jal` is the recommended entry point for the current source tree and the next release.
The legacy `java-audit scan .` command remains supported. The published v1.8.0 wheel continues to use the legacy command; `jal` is the recommended entry point for the v1.9.0 source tree.

### Short command reference

Expand Down Expand Up @@ -150,6 +150,7 @@ Each stage records available and missing evidence. Scanner output and human answ
| Stable | Git differential audit | Change scope, weakened authorization, related locations, residual findings |
| Stable | Multi-engine consolidation | SARIF, Semgrep, SpotBugs, Dependency-Check, and CodeQL |
| Stable | Review archive | Local storage, import/export, and baseline classification |
| Stable | Verification ledger | Task cards, progress, success criteria, evidence paths, and false-positive attribution |
| Pilot | Anonymous evaluation corpus | Four pilot families with vulnerable, safe, and edge cases |

**Status definitions:** Stable = covered by routine tests · Beta = usable and still evolving · Pilot = validating the direction and evaluation workflow
Expand Down Expand Up @@ -213,9 +214,13 @@ fail_on: high
cache: true
exclude_paths: [src/test/*, generated/*]
extra_rules: [.java-audit/rules/team-rules.yaml]
report_owner: security-team
authorization_ref: AUTH-2026-001
scope_note: Scan only the backend service directory
retention_note: Remove source and cache files according to the authorization agreement
```

Command-line options override project configuration. YAML and JSON rules placed under `.java-audit/rules/` are loaded automatically.
Command-line options override project configuration. YAML and JSON rules placed under `.java-audit/rules/` are loaded automatically. Report dossier fields record user-supplied context and do not make an authorization claim on the user's behalf.

## Optional AI explanations

Expand All @@ -233,10 +238,13 @@ Explanation levels are `beginner`, `intermediate`, and `advanced`.

The roadmap communicates current direction. It does not represent completed work or a promised release date.

### Near term: next release
### v1.9: verification loop

- [x] `jal` short command, default scan behavior, and common option aliases
- [x] Complete Chinese and English README files
- [x] Generate a review-only verification task card for every finding
- [x] Track verification status, assignee, attempts, success criteria, and evidence paths
- [x] Add false-positive attribution, a verification ledger, and live outcome metrics
- [ ] Expand the anonymous corpus across more rules, redacted real cases, and an independent holdout split
- [ ] Add a stable machine-readable CLI summary and document exit codes
- [ ] Add a GitHub Actions example for pull-request differential review
Expand All @@ -247,6 +255,8 @@ The roadmap communicates current direction. It does not represent completed work
- [ ] More precise call graphs, interface implementations, and inheritance
- [ ] Spring WebFlux, Dubbo, gRPC, and additional messaging entry points
- [ ] Ownership evidence for object-level authorization and IDOR review
- [ ] Safe manual validation steps and remediation retest records for authorized labs
- [ ] Generate redacted regression cases from human review outcomes
- [ ] Team configuration for suppression, accepted risk, and review verdicts

### Long term: extensible workbench
Expand Down
13 changes: 7 additions & 6 deletions RELEASE_CHECKLIST.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Java Audit Lab 1.8.0 发布清单
# Java Audit Lab 1.9.0 发布清单

## 发布前

- [x] 源码、包元数据和命令行版本统一为 1.8.0
- [x] 源码、包元数据和命令行版本统一为 1.9.0
- [x] 单元与回归测试通过
- [x] 内置规则基准通过
- [x] HTML 内联 JavaScript 语法通过 Node.js 校验
- [x] 验证任务卡不生成攻击载荷,也不会自动连接目标
- [x] 配置凭据扫描不会把原值写入证据或指纹
- [x] 用独立真实 Java 项目完成复扫
- [x] 在新的虚拟环境安装 wheel,并验证版本、内置基准和新增扫描器可导入
- [x] 在新的虚拟环境安装 wheel,并验证版本、内置基准和验证台账可用
- [x] 检查待提交文件:项目自身配置扫描为 0,真实业务报告、本机缓存和内部复核记录均已忽略

## 开源平台

- [ ] 创建远程仓库并推送 `main`
- [ ] 设置仓库简介、主题标签和 MIT License 展示
- [ ] 创建 `v1.8.0` 标签与 Release,附 wheel 和变更说明
- [x] 创建远程仓库并推送 `main`
- [x] 设置仓库简介、主题标签和 MIT License 展示
- [ ] 创建 `v1.9.0` 标签与 Release,附 wheel 和变更说明
- [ ] 开启 Issues 与安全漏洞私密报告
- [ ] 配置分支保护和测试工作流

Expand Down
2 changes: 1 addition & 1 deletion audit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Java Audit Lab."""

__version__ = "1.8.0"
__version__ = "1.9.0"
4 changes: 3 additions & 1 deletion audit/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import json
from pathlib import Path

from typing import Any

from .findings import Finding


Expand All @@ -21,7 +23,7 @@ def compare_with_baseline(findings: list[Finding], baseline_path: Path | None) -
}


def load_reviews(review_path: Path | None) -> dict[str, dict[str, str]]:
def load_reviews(review_path: Path | None) -> dict[str, dict[str, Any]]:
if review_path is None:
return {}
payload = json.loads(review_path.read_text(encoding="utf-8-sig"))
Expand Down
10 changes: 9 additions & 1 deletion audit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,15 @@ def _scan(args: argparse.Namespace) -> int:
findings.sort(key=lambda item: (-item.review_priority, SEVERITY_ORDER.get(item.severity, 99), item.location.path, item.location.line))
playbook = evaluate_playbook(project, surface, results, findings, reviews, baseline, ["JSON", "SARIF", "HTML", "Markdown"], authz)
output_dir = Path(args.output).resolve()
json_path, html_path, md_path = write_reports(output_dir, project, findings, results, baseline, reviews, surface.to_dict(), playbook, authz.to_dict(), incremental)
engagement = {
"report_owner": str(config.get("report_owner") or "未填写"),
"authorization_ref": str(config.get("authorization_ref") or "未填写;授权状态由使用者自行确认"),
"scope_note": str(config.get("scope_note") or f"当前命令指定的项目根目录:{project.root}"),
"retention_note": str(config.get("retention_note") or "请按授权约定保留或删除源代码、缓存和报告;公开报告前检查路径、密钥与业务信息。"),
"excluded_paths": exclude_paths,
"validity_note": "报告仅反映本次扫描时的代码、配置与依赖状态;任一项发生变更后应重新扫描。",
}
json_path, html_path, md_path = write_reports(output_dir, project, findings, results, baseline, reviews, surface.to_dict(), playbook, authz.to_dict(), incremental, engagement)
progress = playbook["progress"]
print(f"\n完成:{len(findings)} 条待复核发现;新增 {len(baseline['new'])};已修复 {len(baseline['fixed'])}")
print(f"审计阶段:已完成 {progress['completed']}/{progress['total']},部分完成 {progress['partial']}")
Expand Down
7 changes: 7 additions & 0 deletions audit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"exclude_paths": [],
"extra_rules": [],
"public_endpoints": [],
"report_owner": "",
"authorization_ref": "",
"scope_note": "",
"retention_note": "",
}


Expand All @@ -36,6 +40,9 @@ def load_config(path: Path | None) -> dict[str, Any]:
raise ValueError("extra_rules 必须是列表")
if not isinstance(result["public_endpoints"], list):
raise ValueError("public_endpoints 必须是列表")
for key in ("report_owner", "authorization_ref", "scope_note", "retention_note"):
if not isinstance(result[key], str):
raise ValueError(f"{key} 必须是字符串")
return result


Expand Down
62 changes: 62 additions & 0 deletions audit/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import fnmatch
import os
import subprocess
import tempfile
from dataclasses import asdict, dataclass
from pathlib import Path


IGNORED_DIRS = {".git", ".gradle", ".idea", ".mvn", ".java-audit-cache", "audit-report", "build", "dist", "node_modules", "out", "output", "target"}
CONFIG_SUFFIXES = {".yml", ".yaml", ".properties", ".xml", ".json", ".env"}
SOURCE_SUFFIXES = {".java", ".kt", ".kts", ".groovy", ".scala"}
WEB_SUFFIXES = {".jsp", ".jspx", ".html", ".htm", ".js", ".ts", ".css", ".vue"}
TEXT_SUFFIXES = SOURCE_SUFFIXES | WEB_SUFFIXES | CONFIG_SUFFIXES | {".sql", ".gradle"}

# Glob patterns applied to repo-relative posix paths, e.g. "src/test/*".
# Mutated at runtime by set_excluded_globs(); we keep it as a module-level list
Expand Down Expand Up @@ -84,6 +88,9 @@ class ProjectInfo:
java_files: int
manifests: list[str]
frameworks: list[str]
inventory: dict[str, object]
revision: str
branch: str

def to_dict(self) -> dict[str, object]:
return asdict(self)
Expand Down Expand Up @@ -121,6 +128,57 @@ def source_scope(path: str | Path) -> str:
return "production"


def collect_inventory(root: Path) -> dict[str, object]:
"""Build a small, reproducible scope manifest without retaining file contents."""
by_extension: dict[str, int] = {}
total_files = source_files = config_files = web_files = estimated_lines = counted_files = 0
for path in root.rglob("*"):
if not path.is_file():
continue
rel_parts = path.relative_to(root).parts
if _is_excluded(rel_parts):
continue
total_files += 1
suffix = path.suffix.lower() or "[no extension]"
by_extension[suffix] = by_extension.get(suffix, 0) + 1
if suffix in SOURCE_SUFFIXES:
source_files += 1
if path.name == ".env" or suffix in CONFIG_SUFFIXES:
config_files += 1
if suffix in WEB_SUFFIXES:
web_files += 1
if suffix in TEXT_SUFFIXES:
try:
if path.stat().st_size <= 5 * 1024 * 1024:
data = path.read_bytes()
estimated_lines += data.count(b"\n") + (1 if data else 0)
counted_files += 1
except OSError:
pass
return {
"total_files": total_files,
"source_files": source_files,
"config_files": config_files,
"web_files": web_files,
"estimated_lines": estimated_lines,
"line_counted_files": counted_files,
"by_extension": dict(sorted(by_extension.items(), key=lambda item: (-item[1], item[0]))[:12]),
}


def _git_metadata(root: Path) -> tuple[str, str]:
def value(*args: str) -> str:
try:
completed = subprocess.run(
["git", "-C", str(root), *args], capture_output=True, text=True,
encoding="utf-8", errors="replace", timeout=3, check=False,
)
return completed.stdout.strip() if completed.returncode == 0 else ""
except (OSError, subprocess.SubprocessError):
return ""
return value("rev-parse", "--short=12", "HEAD"), value("branch", "--show-current")


def detect_project(target: str | Path) -> ProjectInfo:
root = Path(target).expanduser().resolve()
if not root.exists():
Expand Down Expand Up @@ -150,11 +208,15 @@ def detect_project(target: str | Path) -> ProjectInfo:
"Struts": ("struts",), "Jersey": ("jersey",), "WebFlux": ("spring-webflux",),
}
frameworks = [name for name, markers in framework_markers.items() if any(marker in manifest_text for marker in markers)]
revision, branch = _git_metadata(root)
return ProjectInfo(
root=str(root),
name=root.name,
build_system=build_system,
java_files=sum(1 for _ in iter_java_files(root)),
manifests=manifests,
frameworks=frameworks,
inventory=collect_inventory(root),
revision=revision,
branch=branch,
)
Loading
Loading