Skip to content

增量优化 - #238

Open
Yuai123star wants to merge 18 commits into
lintsinghua:v3.0.0from
Yuai123star:增量优化

Hidden character warning

The head ref may contain hidden characters: "\u589e\u91cf\u4f18\u5316"
Open

Yuai123star wants to merge 18 commits into
lintsinghua:v3.0.0from
Yuai123star:增量优化

Conversation

@Yuai123star

Copy link
Copy Markdown

在既有 Multi-Agent 审计链路(orchestrator → recon → analysis → verification)上做定点增量,不改动核心编排,改动聚焦 18 个文件。欢迎 review,也可以在此基础上继续 rebase。

1.PHP 专属规则集 :

pattern_tool / smart_scan_tool 增加 27 处 PHP 安全模式(危险函数、LFI/命令注入/反序列化等)
让 PHP 从"LLM 泛化看"升级为"规则快速命中 + 为 LLM 提供精确证据上下文"
init_templates.py 注入 php 规则模板

  1. 漏洞知识库扩充

多类漏洞文档补充 PHP 章节
新增 Laravel / ThinkPHP 框架专项知识
接入 RAG(knowledge/rag/indexer.py)

3.报告多格式导出 报告支持 PDF / Markdown / HTML / JSON 四种格式 + 统计概览(各漏洞等级分布、检测器命中、时间线等)。

4.Agent 执行日志

日志可重放(还原执行过程)
按 Agent 维度过滤
导出 JSON / Markdown

Added new PHP security rules for code auditing, including checks for dangerous functions, SQL injection, and insecure deserialization.
Added PHP authentication examples highlighting insecure practices and secure methods.
Added PHP code snippet for safe deserialization practices.
Added examples of unsafe and safe SQL practices in PHP, including raw queries and prepared statements. Included detection keywords and validation methods for SQL injection.
Added PHP code examples for safe file handling and path validation to prevent path traversal vulnerabilities.
Added PHP examples demonstrating SSRF vulnerabilities and safe URL handling.
Add PHP examples for secure output escaping.
Added PHP examples for disabling external entities in XML parsing.
Add Laravel security knowledge document with common vulnerabilities and best practices.
Add security knowledge for ThinkPHP framework including vulnerabilities and safe coding practices.
Enhance report generation service to support multiple output formats (PDF, Markdown, HTML, JSON) and add statistical overview features.
Updated the export_task_report function to support multiple formats (pdf, markdown, html, json) and kept the legacy '/report/pdf' route as an alias. Adjusted the response handling and added format normalization.
Added support for exporting reports in Markdown and HTML formats. Updated export format options and adjusted UI accordingly.
Added functions to get distinct agent names, export logs as JSON and Markdown, and trigger file downloads.
Added agent name filtering and log export functionality.
@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

@Yuai123star is attempting to deploy a commit to the tsinghuaiiilove-2257's projects Team on Vercel.

A member of the Team first needs to authorize it.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Expand PHP auditing, report exports, and agent log tooling

✨ Enhancement 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Adds PHP-specific scanner rules, framework guidance, and vulnerability evidence.
• Exports reports as PDF, Markdown, HTML, or JSON with statistical summaries.
• Filters and exports agent execution logs for portable review and analysis.
Diagram

graph TD
  A["PHP Scanners"] --> C["Audit Pipeline"] --> D[("Audit Results")] --> E["Report API"] --> F["Format Renderer"] --> G["Export UI"]
  B["PHP Knowledge"] --> C --> H["Log Console"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Central declarative PHP rule catalog
  • ➕ Prevents signatures and severities drifting between both scanners and seeded templates
  • ➕ Enables shared fixtures and coverage tests for every PHP rule
  • ➕ Simplifies future framework-specific expansion
  • ➖ Requires refactoring existing scanner schemas and template initialization
  • ➖ May broaden the change beyond the intended incremental scope
2. Adopt Semgrep PHP rules
  • ➕ Provides syntax-aware matching with established community security rules
  • ➕ Reduces brittleness and false positives compared with regular expressions
  • ➕ Supports reusable test cases for individual rules
  • ➖ Adds a runtime dependency and scanner integration work
  • ➖ May not map directly to the existing evidence and prompt model
  • ➖ Requires rule curation to control noise and performance

Recommendation: The targeted additions are appropriate for preserving the existing orchestration and delivering PHP coverage quickly. However, the same signatures now appear across multiple scanners and templates; a central declarative rule catalog is the best follow-up to prevent drift. A Semgrep integration is better reserved for a separate architectural change because it expands deployment and compatibility risk.

Files changed (18) +1435 / -185

Enhancement (8) +1002 / -185
tasks.pyAdd format-selectable task report endpoint +43/-18

Add format-selectable task report endpoint

• Replaces the PDF-only handler with a report endpoint accepting PDF, Markdown, HTML, or JSON. It validates formats, returns matching media types and filenames, and retains the legacy PDF route as an alias.

backend/app/api/v1/endpoints/tasks.py

pattern_tool.pyExpand PHP pattern-based vulnerability detection +20/-0

Expand PHP pattern-based vulnerability detection

• Adds command-execution and unserialize signatures and introduces medium-severity PHP type-juggling detection with CWE metadata.

backend/app/services/agent/tools/pattern_tool.py

smart_scan_tool.pyExpand quick scanning for PHP vulnerabilities +28/-0

Expand quick scanning for PHP vulnerabilities

• Adds PHP signatures for SQL and command injection, XSS, unsafe file access, SSRF, deserialization, and type juggling. New categories receive explicit critical and medium severities.

backend/app/services/agent/tools/smart_scan_tool.py

report_generator.pyRender reports in four formats with statistics +623/-108

Render reports in four formats with statistics

• Generalizes report generation across PDF, Markdown, HTML, and JSON while preserving PDF rendering. It normalizes severity data and adds severity distributions, issue-type counts, and top findings to task and instant reports.

backend/app/services/report_generator.py

ExportReportDialog.tsxExpose four audit report formats +73/-30

Expose four audit report formats

• Expands the report selector to PDF, JSON, Markdown, and HTML using reusable option metadata. It adds format-specific descriptions, icons, export actions, and statistical-summary messaging.

frontend/src/components/reports/ExportReportDialog.tsx

reportExport.tsAdd server-generated Markdown and HTML downloads +23/-1

Add server-generated Markdown and HTML downloads

• Routes PDF exports through the generalized report API and adds Markdown and HTML download helpers with format-specific filenames and errors.

frontend/src/features/reports/services/reportExport.ts

index.tsxFilter and export agent execution logs +112/-28

Filter and export agent execution logs

• Adds agent-name filtering and exports the currently displayed logs as JSON or Markdown. The log count, empty states, filter indicator, and reset behavior now account for the additional filter.

frontend/src/pages/AgentAudit/index.tsx

utils.tsAdd reusable agent log export utilities +80/-0

Add reusable agent log export utilities

• Adds helpers for extracting agent names, serializing logs to JSON or Markdown, and downloading generated text through the browser.

frontend/src/pages/AgentAudit/utils.ts

Documentation (9) +323 / -0
laravel.pyAdd Laravel security knowledge document +94/-0

Add Laravel security knowledge document

• Introduces Laravel-specific guidance covering raw SQL, Blade output, mass assignment, authentication, application keys, uploads, CSRF, and authorization controls.

backend/app/services/agent/knowledge/frameworks/laravel.py

thinkphp.pyAdd ThinkPHP security knowledge document +82/-0

Add ThinkPHP security knowledge document

• Documents historical RCE risks and insecure patterns involving SQL construction, templates, uploads, routing, and production debug settings.

backend/app/services/agent/knowledge/frameworks/thinkphp.py

auth.pyExtend authentication guidance for PHP +25/-0

Extend authentication guidance for PHP

• Adds vulnerable PHP password, comparison, token, and session examples alongside secure password verification, session regeneration, and random token practices.

backend/app/services/agent/knowledge/vulnerabilities/auth.py

deserialization.pyDocument safer PHP deserialization +19/-0

Document safer PHP deserialization

• Adds PHP guidance favoring JSON and demonstrates integrity checks and class allowlisting when unserialize cannot be avoided.

backend/app/services/agent/knowledge/vulnerabilities/deserialization.py

injection.pyAdd PHP SQL injection examples +28/-0

Add PHP SQL injection examples

• Documents vulnerable PHP database query construction and secure PDO, mysqli, Laravel query-builder, and ORM alternatives.

backend/app/services/agent/knowledge/vulnerabilities/injection.py

path_traversal.pyAdd PHP path traversal protections +19/-0

Add PHP path traversal protections

• Adds examples using canonical path validation and filename allowlist mappings to prevent local file inclusion and traversal.

backend/app/services/agent/knowledge/vulnerabilities/path_traversal.py

ssrf.pyExtend SSRF guidance for PHP +31/-0

Extend SSRF guidance for PHP

• Adds unsafe cURL and file retrieval examples plus protocol, host, and redirect restrictions for outbound PHP requests.

backend/app/services/agent/knowledge/vulnerabilities/ssrf.py

xss.pyAdd PHP output escaping guidance +10/-0

Add PHP output escaping guidance

• Documents htmlspecialchars usage and contrasts escaped Laravel Blade output with unescaped template syntax.

backend/app/services/agent/knowledge/vulnerabilities/xss.py

xxe.pyAdd PHP XML parser hardening examples +15/-0

Add PHP XML parser hardening examples

• Adds PHP examples for restricting external entities and network access in libxml, DOMDocument, and SimpleXML processing.

backend/app/services/agent/knowledge/vulnerabilities/xxe.py

Other (1) +110 / -0
init_templates.pySeed a PHP security rule template +110/-0

Seed a PHP security rule template

• Adds ten system rules covering PHP code execution, deserialization, file inclusion, SQL injection, XSS, command injection, cryptography, type juggling, randomness, and file access.

backend/app/services/init_templates.py

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (10) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Missing report API client 🐞 Bug ≡ Correctness
Description
All three server-backed export functions call api.exportTaskReport, but the API object only
defines exportTaskReportPDF. The frontend therefore fails type checking and cannot export PDF,
Markdown, or HTML through the new endpoint.
Code

frontend/src/features/reports/services/reportExport.ts[62]

+        const blob = await api.exportTaskReport(task.id, "pdf");
Evidence
The new calls reference a method absent from the exported API object; the only existing client
method targets the legacy PDF-only route and cannot supply Markdown or HTML formats.

frontend/src/features/reports/services/reportExport.ts[59-89]
frontend/src/shared/api/database.ts[246-253]
backend/app/api/v1/endpoints/tasks.py[299-305]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Implement the `exportTaskReport` API method used by the new report export functions.

## Issue Context
The method must request `/tasks/{taskId}/report`, pass the selected format as a query parameter, request a Blob response, and remain compatible with the legacy PDF method if it is retained.

## Fix Focus Areas
- frontend/src/shared/api/database.ts[246-253]
- frontend/src/features/reports/services/reportExport.ts[59-89]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Framework knowledge never registered 🐞 Bug ≡ Correctness
Description
The new Laravel and ThinkPHP documents are not imported or added to ALL_FRAMEWORK_DOCS. Built-in
loading and RAG indexing therefore omit both documents entirely.
Code

backend/app/services/agent/knowledge/frameworks/laravel.py[R8-11]

+LARAVEL_SECURITY = KnowledgeDocument(
+    id="framework_laravel",
+    title="Laravel Security",
+    category=KnowledgeCategory.FRAMEWORK,
Evidence
The two files define knowledge documents, but the framework registry contains only the six older
frameworks; the RAG loader extends its index from that registry alone.

backend/app/services/agent/knowledge/frameworks/laravel.py[8-14]
backend/app/services/agent/knowledge/frameworks/thinkphp.py[8-14]
backend/app/services/agent/knowledge/frameworks/init.py[7-22]
backend/app/services/agent/knowledge/rag_knowledge.py[85-89]
backend/app/services/agent/knowledge/rag_knowledge.py[103-111]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Register the new Laravel and ThinkPHP documents in the framework knowledge registry.

## Issue Context
RAG loads framework knowledge exclusively through `ALL_FRAMEWORK_DOCS`, so merely defining each document does not make it discoverable.

## Fix Focus Areas
- backend/app/services/agent/knowledge/frameworks/__init__.py[7-32]
- backend/app/services/agent/knowledge/frameworks/laravel.py[8-14]
- backend/app/services/agent/knowledge/frameworks/thinkphp.py[8-14]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. XXE guidance enables entities 🐞 Bug ⛨ Security
Description
The PHP example labeled as disabling external entities passes LIBXML_NOENT | LIBXML_DTDLOAD,
explicitly requesting entity substitution and DTD loading. RAG can consequently recommend a
configuration that enables the behavior the XXE remediation is supposed to prevent.
Code

backend/app/services/agent/knowledge/vulnerabilities/xxe.py[R136-138]

+// 安全 - DOMDocument 禁用网络与外部实体
+$doc = new DOMDocument();
+$doc->loadXML($xml, LIBXML_NONET | LIBXML_NOENT | LIBXML_DTDLOAD);
Evidence
The example's comment claims external entities are disabled, but its own named flags request DTD
loading and entity substitution. Vulnerability documents are loaded into the built-in RAG knowledge
used by agents.

backend/app/services/agent/knowledge/vulnerabilities/xxe.py[129-141]
backend/app/services/agent/knowledge/rag_knowledge.py[76-81]
backend/app/services/agent/knowledge/rag_knowledge.py[103-111]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Correct the PHP XXE remediation so it neither loads DTDs nor substitutes external entities.

## Issue Context
Keep network access disabled and provide version-appropriate safe parser examples without contradictory enabling flags.

## Fix Focus Areas
- backend/app/services/agent/knowledge/vulnerabilities/xxe.py[129-141]
- backend/app/services/agent/knowledge/rag_knowledge.py[76-81]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View action required (1)
4. Path guard accepts siblings 🐞 Bug ⛨ Security
Description
The purportedly safe PHP path check compares only a raw string prefix, so a resolved sibling such as
/srv/uploads-secret/file passes when the base is /srv/uploads. This teaches an
LFI/path-traversal guard that still permits files outside the intended directory.
Code

backend/app/services/agent/knowledge/vulnerabilities/path_traversal.py[R133-136]

+    $base = realpath(__DIR__ . '/uploads');
+    $full = realpath($base . '/' . $user_file);
+    if ($full === false || strpos($full, $base) !== 0) {
+        http_response_code(403);
Evidence
strpos($full, $base) === 0 proves only that the strings share a prefix, not that $full is under
the base directory; no separator boundary is included in the check.

backend/app/services/agent/knowledge/vulnerabilities/path_traversal.py[129-145]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Correct the PHP path example to compare against a normalized base path followed by a directory separator.

## Issue Context
Handle failed `realpath` calls and ensure similarly prefixed sibling directories cannot pass containment validation.

## Fix Focus Areas
- backend/app/services/agent/knowledge/vulnerabilities/path_traversal.py[129-145]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

5. JSON report corrupts text 🐞 Bug ≡ Correctness
Description
generate_task_report HTML-escapes issue fields before dispatching every format, and _render_json
serializes those processed fields directly. JSON consumers receive values such as <script>
and ' instead of the stored code, descriptions, and paths.
Code

backend/app/services/report_generator.py[R1004-1005]

        score = task.get('quality_score', 0)
-        
+        processed = cls._process_issues(issues)
Evidence
The common processing stage applies html.escape to all textual issue fields, after which the JSON
renderer writes the same processed list without decoding it. AuditIssue stores these fields as
ordinary source text.

backend/app/services/report_generator.py[760-777]
backend/app/services/report_generator.py[921-949]
backend/app/services/report_generator.py[1000-1021]
backend/app/models/audit.py[45-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Separate canonical issue normalization from output-specific HTML escaping so JSON contains original values.

## Issue Context
HTML/PDF output needs contextual escaping, while JSON and Markdown must not reuse entity-encoded data.

## Fix Focus Areas
- backend/app/services/report_generator.py[744-780]
- backend/app/services/report_generator.py[921-949]
- backend/app/services/report_generator.py[1000-1021]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Report HTML permits injection 🐞 Bug ⛨ Security
Description
The new HTML renderer uses a Jinja Template without autoescaping while interpolating the raw
project and branch names into the document. A crafted project or branch name is emitted as
executable markup in the downloaded HTML report rather than report text.
Code

backend/app/services/report_generator.py[R914-917]

+    def _render_html(cls, context: Dict[str, Any]) -> bytes:
+        """渲染独立 HTML 报告(纯模板,无 WeasyPrint 依赖)"""
+        template = Template(cls._HTML_TEMPLATE)
+        html_content = template.render(**context)
Evidence
The HTML template is rendered without autoescape, and its subtitle contains raw project and branch
values. Both values originate from request-backed project and scan schemas that impose no HTML-safe
validation.

backend/app/services/report_generator.py[914-918]
backend/app/services/report_generator.py[1007-1010]
backend/app/api/v1/endpoints/projects.py[31-47]
backend/app/api/v1/endpoints/projects.py[489-523]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Render standalone HTML through an autoescaping Jinja environment and stop relying on partial manual escaping.

## Issue Context
Project names and scan branch names are accepted without HTML validation and are included in the report subtitle.

## Fix Focus Areas
- backend/app/services/report_generator.py[914-918]
- backend/app/services/report_generator.py[1007-1010]
- backend/app/api/v1/endpoints/projects.py[31-47]
- backend/app/api/v1/endpoints/projects.py[489-523]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. Strict PHP checks misclassified 🐞 Bug ≡ Correctness
Description
The new type-juggling rules classify !== 0 as a vulnerability and evaluate the in_array negative
lookahead only after the closing parenthesis. Consequently safe strict comparisons and
in_array($value, $list, true) are reported as insecure.
Code

backend/app/services/agent/tools/pattern_tool.py[R264-265]

+                    (r'(!==)\s*0', "神奇哈希 '0e...' 判定"),
+                    (r'in_array\s*\([^)]*\)\s*(?!.*,\s*true)', "in_array未开启严格模式"),
Evidence
!== is itself a strict operator, while both in_array patterns place their negative lookahead
after a regex portion that has already consumed the entire argument list. The scanner emits a
finding for every matching pattern without a later semantic validation stage.

backend/app/services/agent/tools/pattern_tool.py[257-270]
backend/app/services/agent/tools/smart_scan_tool.py[145-149]
backend/app/services/agent/tools/smart_scan_tool.py[316-339]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Replace the type-juggling expressions with patterns that distinguish weak checks from safe strict checks.

## Issue Context
The `in_array` strictness check must inspect arguments inside the call, and `!== 0` must not be treated as weak comparison.

## Fix Focus Areas
- backend/app/services/agent/tools/pattern_tool.py[257-270]
- backend/app/services/agent/tools/smart_scan_tool.py[145-149]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View review recommended (3)
8. Superglobal unserialize double-counted 🐞 Bug ≡ Correctness
Description
The added unserialize(...$_...) expression is a strict subset of the existing
unserialize(...$...) expression. Every direct superglobal call now produces two findings in each
scanner, inflating issue counts and duplicated evidence.
Code

backend/app/services/agent/tools/smart_scan_tool.py[R141-143]

+        "deserialization": [
+            (r'unserialize\s*\(\s*\$', "unserialize用户输入"),
+            (r'unserialize\s*\(\s*\$_', "反序列化超全局变量"),
Evidence
A string beginning $_ necessarily also begins $, so both patterns match the same call. Both scan
loops append independent findings for each regex match.

backend/app/services/agent/tools/smart_scan_tool.py[141-143]
backend/app/services/agent/tools/pattern_tool.py[248-251]
backend/app/services/agent/tools/smart_scan_tool.py[319-339]
backend/app/services/agent/tools/pattern_tool.py[435-454]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Make the unserialize expressions mutually exclusive or retain only the more useful expression.

## Issue Context
Both tools iterate all matching regexes and append one finding per match, so overlapping patterns are not deduplicated automatically.

## Fix Focus Areas
- backend/app/services/agent/tools/smart_scan_tool.py[141-143]
- backend/app/services/agent/tools/pattern_tool.py[248-251]
- backend/app/services/agent/tools/smart_scan_tool.py[319-339]
- backend/app/services/agent/tools/pattern_tool.py[435-454]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Preg_replace rule overmatches 🐞 Bug ≡ Correctness
Description
The new /e detector merely requires the quoted pattern text to end in the letter e; it does not
require an /e modifier. Benign calls such as preg_replace('safe', ...) are therefore emitted as
critical command-injection findings.
Code

backend/app/services/agent/tools/pattern_tool.py[161]

+                    (r'preg_replace\s*\(\s*["\'][^"\']*e["\']', "preg_replace /e修饰符"),
Evidence
The expression [^"']*e["'] accepts any quoted string ending in e, while the encompassing
category assigns every such match critical severity and labels it command injection.

backend/app/services/agent/tools/pattern_tool.py[153-172]
backend/app/services/agent/tools/pattern_tool.py[435-454]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Constrain the preg_replace regex to an actual closing delimiter followed by the `e` modifier.

## Issue Context
Account for optional additional modifiers without treating an arbitrary final letter `e` as the modifier.

## Fix Focus Areas
- backend/app/services/agent/tools/pattern_tool.py[153-172]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


10. Log Markdown fences break 🐞 Bug ≡ Correctness
Description
The log exporter places raw log content inside a fixed triple-backtick fence. Tool or model output
containing its own triple backticks closes the block early, producing a malformed and misleading
Markdown replay.
Code

frontend/src/pages/AgentAudit/utils.ts[R260-263]

+    if (log.content) {
+      lines.push(`\`\`\`text`);
+      lines.push(log.content);
+      lines.push(`\`\`\``);
Evidence
The exporter writes content verbatim between fixed three-backtick delimiters and performs no
escaping or delimiter selection. LogItem content is arbitrary string output, so embedded fences are
valid input.

frontend/src/pages/AgentAudit/utils.ts[230-268]
frontend/src/pages/AgentAudit/types.ts[23-38]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Serialize log content with a fence longer than any backtick run in the content, or indent the block safely.

## Issue Context
Agent and tool output commonly contains Markdown code blocks and must remain verbatim in replay exports.

## Fix Focus Areas
- frontend/src/pages/AgentAudit/utils.ts[230-268]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

export async function exportToPDF(task: AuditTask, _issues: AuditIssue[]) {
try {
const blob = await api.exportTaskReportPDF(task.id);
const blob = await api.exportTaskReport(task.id, "pdf");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Missing report api client 🐞 Bug ≡ Correctness

All three server-backed export functions call api.exportTaskReport, but the API object only
defines exportTaskReportPDF. The frontend therefore fails type checking and cannot export PDF,
Markdown, or HTML through the new endpoint.
Agent Prompt
## Issue description
Implement the `exportTaskReport` API method used by the new report export functions.

## Issue Context
The method must request `/tasks/{taskId}/report`, pass the selected format as a query parameter, request a Blob response, and remain compatible with the legacy PDF method if it is retained.

## Fix Focus Areas
- frontend/src/shared/api/database.ts[246-253]
- frontend/src/features/reports/services/reportExport.ts[59-89]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +8 to +11
LARAVEL_SECURITY = KnowledgeDocument(
id="framework_laravel",
title="Laravel Security",
category=KnowledgeCategory.FRAMEWORK,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Framework knowledge never registered 🐞 Bug ≡ Correctness

The new Laravel and ThinkPHP documents are not imported or added to ALL_FRAMEWORK_DOCS. Built-in
loading and RAG indexing therefore omit both documents entirely.
Agent Prompt
## Issue description
Register the new Laravel and ThinkPHP documents in the framework knowledge registry.

## Issue Context
RAG loads framework knowledge exclusively through `ALL_FRAMEWORK_DOCS`, so merely defining each document does not make it discoverable.

## Fix Focus Areas
- backend/app/services/agent/knowledge/frameworks/__init__.py[7-32]
- backend/app/services/agent/knowledge/frameworks/laravel.py[8-14]
- backend/app/services/agent/knowledge/frameworks/thinkphp.py[8-14]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines 1004 to +1005
score = task.get('quality_score', 0)

processed = cls._process_issues(issues)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. Json report corrupts text 🐞 Bug ≡ Correctness

generate_task_report HTML-escapes issue fields before dispatching every format, and _render_json
serializes those processed fields directly. JSON consumers receive values such as <script>
and ' instead of the stored code, descriptions, and paths.
Agent Prompt
## Issue description
Separate canonical issue normalization from output-specific HTML escaping so JSON contains original values.

## Issue Context
HTML/PDF output needs contextual escaping, while JSON and Markdown must not reuse entity-encoded data.

## Fix Focus Areas
- backend/app/services/report_generator.py[744-780]
- backend/app/services/report_generator.py[921-949]
- backend/app/services/report_generator.py[1000-1021]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +914 to +917
def _render_html(cls, context: Dict[str, Any]) -> bytes:
"""渲染独立 HTML 报告(纯模板,无 WeasyPrint 依赖)"""
template = Template(cls._HTML_TEMPLATE)
html_content = template.render(**context)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

4. Report html permits injection 🐞 Bug ⛨ Security

The new HTML renderer uses a Jinja Template without autoescaping while interpolating the raw
project and branch names into the document. A crafted project or branch name is emitted as
executable markup in the downloaded HTML report rather than report text.
Agent Prompt
## Issue description
Render standalone HTML through an autoescaping Jinja environment and stop relying on partial manual escaping.

## Issue Context
Project names and scan branch names are accepted without HTML validation and are included in the report subtitle.

## Fix Focus Areas
- backend/app/services/report_generator.py[914-918]
- backend/app/services/report_generator.py[1007-1010]
- backend/app/api/v1/endpoints/projects.py[31-47]
- backend/app/api/v1/endpoints/projects.py[489-523]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +264 to +265
(r'(!==)\s*0', "神奇哈希 '0e...' 判定"),
(r'in_array\s*\([^)]*\)\s*(?!.*,\s*true)', "in_array未开启严格模式"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

5. Strict php checks misclassified 🐞 Bug ≡ Correctness

The new type-juggling rules classify !== 0 as a vulnerability and evaluate the in_array negative
lookahead only after the closing parenthesis. Consequently safe strict comparisons and
in_array($value, $list, true) are reported as insecure.
Agent Prompt
## Issue description
Replace the type-juggling expressions with patterns that distinguish weak checks from safe strict checks.

## Issue Context
The `in_array` strictness check must inspect arguments inside the call, and `!== 0` must not be treated as weak comparison.

## Fix Focus Areas
- backend/app/services/agent/tools/pattern_tool.py[257-270]
- backend/app/services/agent/tools/smart_scan_tool.py[145-149]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +141 to +143
"deserialization": [
(r'unserialize\s*\(\s*\$', "unserialize用户输入"),
(r'unserialize\s*\(\s*\$_', "反序列化超全局变量"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

6. Superglobal unserialize double-counted 🐞 Bug ≡ Correctness

The added unserialize(...$_...) expression is a strict subset of the existing
unserialize(...$...) expression. Every direct superglobal call now produces two findings in each
scanner, inflating issue counts and duplicated evidence.
Agent Prompt
## Issue description
Make the unserialize expressions mutually exclusive or retain only the more useful expression.

## Issue Context
Both tools iterate all matching regexes and append one finding per match, so overlapping patterns are not deduplicated automatically.

## Fix Focus Areas
- backend/app/services/agent/tools/smart_scan_tool.py[141-143]
- backend/app/services/agent/tools/pattern_tool.py[248-251]
- backend/app/services/agent/tools/smart_scan_tool.py[319-339]
- backend/app/services/agent/tools/pattern_tool.py[435-454]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

(r'proc_open\s*\(\s*\$', "proc_open变量"),
(r'popen\s*\(\s*\$', "popen变量"),
(r'`[^`]*\$[^`]*`', "反引号命令执行"),
(r'preg_replace\s*\(\s*["\'][^"\']*e["\']', "preg_replace /e修饰符"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

7. Preg_replace rule overmatches 🐞 Bug ≡ Correctness

The new /e detector merely requires the quoted pattern text to end in the letter e; it does not
require an /e modifier. Benign calls such as preg_replace('safe', ...) are therefore emitted as
critical command-injection findings.
Agent Prompt
## Issue description
Constrain the preg_replace regex to an actual closing delimiter followed by the `e` modifier.

## Issue Context
Account for optional additional modifiers without treating an arbitrary final letter `e` as the modifier.

## Fix Focus Areas
- backend/app/services/agent/tools/pattern_tool.py[153-172]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +136 to +138
// 安全 - DOMDocument 禁用网络与外部实体
$doc = new DOMDocument();
$doc->loadXML($xml, LIBXML_NONET | LIBXML_NOENT | LIBXML_DTDLOAD);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

8. Xxe guidance enables entities 🐞 Bug ⛨ Security

The PHP example labeled as disabling external entities passes LIBXML_NOENT | LIBXML_DTDLOAD,
explicitly requesting entity substitution and DTD loading. RAG can consequently recommend a
configuration that enables the behavior the XXE remediation is supposed to prevent.
Agent Prompt
## Issue description
Correct the PHP XXE remediation so it neither loads DTDs nor substitutes external entities.

## Issue Context
Keep network access disabled and provide version-appropriate safe parser examples without contradictory enabling flags.

## Fix Focus Areas
- backend/app/services/agent/knowledge/vulnerabilities/xxe.py[129-141]
- backend/app/services/agent/knowledge/rag_knowledge.py[76-81]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +133 to +136
$base = realpath(__DIR__ . '/uploads');
$full = realpath($base . '/' . $user_file);
if ($full === false || strpos($full, $base) !== 0) {
http_response_code(403);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

9. Path guard accepts siblings 🐞 Bug ⛨ Security

The purportedly safe PHP path check compares only a raw string prefix, so a resolved sibling such as
/srv/uploads-secret/file passes when the base is /srv/uploads. This teaches an
LFI/path-traversal guard that still permits files outside the intended directory.
Agent Prompt
## Issue description
Correct the PHP path example to compare against a normalized base path followed by a directory separator.

## Issue Context
Handle failed `realpath` calls and ensure similarly prefixed sibling directories cannot pass containment validation.

## Fix Focus Areas
- backend/app/services/agent/knowledge/vulnerabilities/path_traversal.py[129-145]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +260 to +263
if (log.content) {
lines.push(`\`\`\`text`);
lines.push(log.content);
lines.push(`\`\`\``);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

10. Log markdown fences break 🐞 Bug ≡ Correctness

The log exporter places raw log content inside a fixed triple-backtick fence. Tool or model output
containing its own triple backticks closes the block early, producing a malformed and misleading
Markdown replay.
Agent Prompt
## Issue description
Serialize log content with a fence longer than any backtick run in the content, or indent the block safely.

## Issue Context
Agent and tool output commonly contains Markdown code blocks and must remain verbatim in replay exports.

## Fix Focus Areas
- frontend/src/pages/AgentAudit/utils.ts[230-268]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant