bugx-cli 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -185
- package/core/README.md +2 -2
- package/core/agent/README.md +2 -1
- package/core/agent/agent_artifacts.py +8 -6
- package/core/agent/agent_eval.py +136 -54
- package/core/agent/agent_execution.py +218 -52
- package/core/agent/agent_orchestrator.py +14 -8
- package/core/agent/agent_targets.py +8 -2
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/README.md +3 -2
- package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- package/core/assets/axe-core/LICENSE.txt +362 -0
- package/core/assets/axe-core/UPSTREAM.md +10 -0
- package/core/assets/axe-core/axe.min.js +12 -0
- package/core/assets/bugx-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/bugx-social-preview.svg +71 -0
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -0
- package/core/assets/webui-chatgpt.jpg +0 -0
- package/core/assets/webui-session.jpg +0 -0
- package/core/assets/webui-skills.jpg +0 -0
- package/core/assets/webui-studio.jpg +0 -0
- package/core/assets/webui-zcode.jpg +0 -0
- package/core/assets/zcode.png +0 -0
- package/core/audit_packs/README.md +2 -0
- package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
- package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
- package/core/audit_packs/pitfalls/go_backend.json +66 -0
- package/core/audit_packs/pitfalls/java_spring.json +64 -0
- package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
- package/core/audit_packs/pitfalls/python_web.json +82 -0
- package/core/autonomous_cve/SPEC.md +1 -1
- package/core/autonomous_cve/attack_graph_store.py +152 -106
- package/core/autonomous_cve/behavior_graph.py +8 -2
- package/core/autonomous_cve/verifier.py +4 -1
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +43 -8
- package/core/cli-help.txt +66 -0
- package/core/cloud_sync/SPEC.md +1 -1
- package/core/cloud_sync/cloud_client.py +81 -11
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/consent.py +33 -3
- package/core/cloud_sync/flywheel_client.py +186 -15
- package/core/cloud_sync/network_transport.py +24 -3
- package/core/cloud_sync/sensitive_filter.py +2 -2
- package/core/cloud_sync/sync_push.py +12 -10
- package/core/contracts/AGENT_GUIDE.md +6 -9
- package/core/contracts/README.md +2 -2
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/contracts/engine_gap_contracts.py +86 -3
- package/core/coverage/coverage_discovery.py +599 -29
- package/core/coverage/coverage_evidence.py +47 -0
- package/core/coverage/coverage_forensics.py +9 -0
- package/core/coverage/coverage_validate.py +6 -1
- package/core/dev_harness/SPEC.md +1 -1
- package/core/engine-integrity.json +670 -442
- package/core/fuzzing/concurrency_fuzzer.py +53 -0
- package/core/fuzzing/differential_oracle.py +562 -27
- package/core/fuzzing/fuzz_input.py +109 -6
- package/core/fuzzing/stateful_fuzzer.py +72 -0
- package/core/governance/secret_redactor.py +22 -10
- package/core/host_acp/SPEC.md +1 -1
- package/core/host_acp/__init__.py +4 -4
- package/core/host_acp/claude.py +59 -1
- package/core/host_acp/cline.py +64 -1
- package/core/host_acp/codex.py +56 -1
- package/core/host_acp/dsh.py +59 -1
- package/core/host_acp/opencode.py +56 -1
- package/core/host_acp/pi.py +59 -1
- package/core/host_acp/zcode.py +59 -1
- package/core/host_runtime/SPEC.md +1 -1
- package/core/host_runtime/adapters.py +1 -1
- package/core/host_runtime/cline.py +13 -0
- package/core/host_runtime/host_evaluators.py +44 -4
- package/core/host_runtime/host_probe.py +1 -1
- package/core/host_runtime/host_provider_arbitrator.py +116 -62
- package/core/host_runtime/host_registry.py +15 -8
- package/core/host_runtime/mcp_registry_gate.py +12 -1
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -0
- package/core/hosts/SPEC.md +1 -1
- package/core/hosts/__init__.py +6 -2
- package/core/hosts/_dsh_usage.py +1 -1
- package/core/hosts/base.py +32 -4
- package/core/hosts/claude.py +55 -0
- package/core/hosts/cline.py +6 -2
- package/core/hosts/codex.py +58 -0
- package/core/hosts/dsh.py +9 -1
- package/core/hosts/opencode.py +6 -6
- package/core/hosts/pi.py +159 -2
- package/core/infra/README.md +4 -2
- package/core/infra/__init__.py +2 -0
- package/core/infra/build_info.py +22 -3
- package/core/infra/client_metadata.py +1 -1
- package/core/infra/json_utils.py +22 -0
- package/core/launch_phases/README.md +6 -3
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +170 -5
- package/core/launch_phases/finding_settlement.py +188 -1
- package/core/launch_phases/judge_phase.py +69 -12
- package/core/launch_phases/orchestrator_controls.py +11 -7
- package/core/launch_phases/post_coverage_sync.py +9 -2
- package/core/launch_phases/post_phase.py +144 -8
- package/core/launch_phases/post_receipt.py +12 -1
- package/core/launch_phases/pre_phase.py +3 -3
- package/core/launch_phases/pre_recon_scout.py +66 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/report_sharing.py +3 -7
- package/core/launch_phases/round_orchestrator.py +129 -58
- package/core/launch_phases/semantic_recon.py +545 -0
- package/core/launch_phases/session_runtime.py +56 -9
- package/core/launch_phases/startup_gates.py +36 -8
- package/core/launch_phases/startup_interaction.py +68 -12
- package/core/launch_phases/startup_version_gate.py +13 -3
- package/core/launch_phases/supervisor_bridge.py +46 -17
- package/core/launch_phases/supervisor_coverage.py +8 -2
- package/core/launch_phases/supervisor_degraded.py +1 -9
- package/core/launch_phases/verify_loop.py +767 -0
- package/core/launch_phases/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/launch_phases/worker_prior.py +115 -0
- package/core/ledger/README.md +2 -1
- package/core/ledger/SPEC.md +1 -1
- package/core/ledger/_facade.py +2 -1
- package/core/ledger/archive_ops.py +60 -2
- package/core/ledger/cli.py +6 -1
- package/core/ledger/export_ops.py +6 -1
- package/core/ledger/finding_confirmation.py +48 -6
- package/core/ledger/finding_lifecycle.py +428 -5
- package/core/ledger/finding_verification.py +555 -10
- package/core/ledger/fp_ledger.py +255 -0
- package/core/ledger/incidents.py +10 -4
- package/core/ledger/patterns.py +10 -7
- package/core/ledger/receipt_contract.py +17 -1
- package/core/ledger/sync_ops.py +21 -16
- package/core/ledger/tool_experience.py +2 -1
- package/core/ledger/verify_life.py +88 -17
- package/core/locales/en-US.json +2 -2
- package/core/locales/zh-CN.json +2 -2
- package/core/mcp_handlers/SPEC.md +1 -1
- package/core/mcp_handlers/base.py +23 -3
- package/core/mcp_handlers/channel_lifecycle.py +85 -30
- package/core/mcp_handlers/retrieval_handlers.py +11 -1
- package/core/mcp_handlers/rpc_server.py +6 -1
- package/core/mcp_handlers/supervisor_handlers.py +32 -6
- package/core/mcp_handlers/tool_table.py +15 -0
- package/core/mcp_runtime_support/environment.py +0 -38
- package/core/mcp_runtime_support/verifier.py +0 -52
- package/core/metadata.txt +2 -3
- package/core/planning/README.md +2 -1
- package/core/planning/domain_router.py +4 -2
- package/core/planning/dynamic_flow_analyzer.py +219 -14
- package/core/planning/judge_pipeline.py +87 -4
- package/core/planning/prompt_harness.py +57 -15
- package/core/planning/prompt_policy_engine.py +386 -0
- package/core/planning/spec_harvester.py +4 -4
- package/core/probes/INTERFACE.md +11 -1
- package/core/probes/SPEC.md +11 -1
- package/core/probes/__init__.py +46 -40
- package/core/probes/android_probe.py +177 -9
- package/core/probes/codebase_memory_probe.py +57 -0
- package/core/probes/desktop_probe.py +104 -0
- package/core/probes/differential_probe.py +99 -21
- package/core/probes/efficiency_probe.py +64 -0
- package/core/probes/ios_binary_probe.py +105 -1
- package/core/probes/memory_probe.py +66 -0
- package/core/probes/miniprogram_probe.py +75 -13
- package/core/probes/mobile_probe.py +215 -30
- package/core/probes/native_probe.py +88 -0
- package/core/probes/openwiki_probe.py +70 -0
- package/core/probes/pattern_probe.py +106 -0
- package/core/probes/platform_probe.py +81 -0
- package/core/probes/probe_registry.py +108 -7
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +553 -52
- package/core/probes/sast_rules.py +668 -28
- package/core/probes/sca_scanner.py +48 -0
- package/core/probes/ui_accessibility.py +149 -0
- package/core/probes/ui_audit.py +513 -0
- package/core/probes/ui_contract.py +273 -0
- package/core/probes/ui_evidence.py +212 -0
- package/core/probes/ui_measurements.py +314 -0
- package/core/probes/ui_repair.py +250 -0
- package/core/probes/ui_review.py +133 -0
- package/core/probes/ui_storybook.py +107 -0
- package/core/probes/ui_tokens.py +185 -0
- package/core/probes/ui_visual_diff.py +131 -0
- package/core/probes/web_probe.py +373 -18
- package/core/project_profiler/SPEC.md +1 -1
- package/core/project_profiler/arbitrator.py +6 -1
- package/core/project_profiler/detector.py +8 -1
- package/core/project_profiler/strategy.py +51 -15
- package/core/prompts/README.md +4 -2
- package/core/prompts/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/policies/prompt_policies.json +101 -0
- package/core/prompts/stages/stage_repair.md +1 -1
- package/core/prompts/stages/stage_verify.defensive.md +42 -0
- package/core/prompts/stages/stage_verify.md +44 -0
- package/core/repair/README.md +1 -1
- package/core/repair/l7_repair_loop.py +1 -4
- package/core/repair/rsi_fixer.py +4 -4
- package/core/repair/rsi_loop.py +1 -3
- package/core/repair/rsi_repair.py +7 -7
- package/core/repair/rsi_scope.py +27 -8
- package/core/report_engine/SPEC.md +1 -1
- package/core/report_engine/attestation.py +8 -4
- package/core/report_engine/finding_report.py +2 -1
- package/core/report_engine/models.py +7 -9
- package/core/report_engine/report_share.py +0 -8
- package/core/report_engine/sast_bridge.py +2 -2
- package/core/report_engine/server.py +18 -8
- package/core/report_engine/web-conformance.md +123 -18
- package/core/report_engine/web_conformance.py +21 -52
- package/core/retrieval/README.md +2 -1
- package/core/retrieval/SPEC.md +1 -1
- package/core/retrieval/code_analyzer.py +50 -14
- package/core/retrieval/context_assembler.py +7 -1
- package/core/retrieval/knowledge_sync.py +108 -14
- package/core/retrieval/pitfall_packs.py +277 -0
- package/core/retrieval/symbol_index.py +25 -6
- package/core/retrieval/universal_code_matcher.py +234 -49
- package/core/runtime/README.md +1 -1
- package/core/runtime/bugx_logging.py +78 -7
- package/core/runtime/fixture_solidify.py +5 -10
- package/core/runtime/global_telemetry.py +20 -0
- package/core/runtime/incident_eval.py +1 -1
- package/core/runtime/model_runner.py +4 -41
- package/core/runtime/platform_adapter.py +2 -2
- package/core/runtime/prep_validate.py +4 -2
- package/core/runtime/project_settings.py +2 -1
- package/core/runtime/scenario_eval.py +50 -8
- package/core/skills/bugx_docs_mcp_server.py +3 -1
- package/core/skills/bugx_mcp_server.py +29 -2
- package/core/skills/tools_kb.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/SPEC.md +1 -1
- package/core/supervisor/budget_governor.py +503 -9
- package/core/supervisor/checkpoint_pipeline.py +248 -6
- package/core/supervisor/checkpoint_sync.py +13 -0
- package/core/supervisor/claim_events.py +1 -1
- package/core/supervisor/finding_workflow.py +22 -5
- package/core/supervisor/lease_manager.py +1 -1
- package/core/supervisor/lifecycle_blocks.py +6 -1
- package/core/supervisor/rejection_remedies.py +52 -5
- package/core/supervisor/serial_authorization.py +48 -4
- package/core/supervisor/task_scheduler.py +2 -2
- package/core/supervisor/worker_checkpoint.py +8 -1
- package/core/supervisor/worker_runtime.py +8 -2
- package/core/supervisor_types/worker_claim.py +9 -0
- package/core/webui/README.md +1 -1
- package/core/webui/SPEC.md +2 -1
- package/core/webui/adapters/claude.py +5 -1
- package/core/webui/adapters/cline.py +10 -2
- package/core/webui/adapters/codex.py +5 -1
- package/core/webui/adapters/dsh.py +5 -1
- package/core/webui/docs_session_service.py +2 -2
- package/core/webui/mcp_inspector.py +11 -7
- package/core/webui/static/00-base.css +1060 -0
- package/core/webui/static/01-monitoring.css +802 -0
- package/core/webui/static/02-header-actions.css +321 -0
- package/core/webui/static/03-trigger-popover.css +697 -0
- package/core/webui/static/04-composer.css +628 -0
- package/core/webui/static/05-skills-center.css +878 -0
- package/core/webui/static/06-mcp-center.css +623 -0
- package/core/webui/static/07-skill-detail.css +265 -0
- package/core/webui/static/08-files-management.css +167 -0
- package/core/webui/static/09-files-center.css +386 -0
- package/core/webui/static/10-icons.css +105 -0
- package/core/webui/static/11-project-options.css +185 -0
- package/core/webui/static/12-profile-tab.css +383 -0
- package/core/webui/static/design-tokens.css +113 -0
- package/core/webui/static/index.html +14 -1
- package/core/webui/workspace_service.py +1 -1
- package/docs/07_distribution/01_README_NPM.md +193 -185
- package/ecosystem/integrations/README.md +1 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
- package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
- package/ecosystem/integrations/opencode/opencode.json +23 -12
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
- package/interfaces/bin/bugx.js +37 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -2
- package/interfaces/cli/bugx_cli/cli.py +172 -69
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +461 -134
- package/interfaces/cli/bugx_cli/commands/audit.py +10 -9
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +31 -22
- package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
- package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
- package/interfaces/cli/bugx_cli/commands/knowledge.py +5 -4
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +58 -23
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
- package/interfaces/cli/bugx_cli/commands/project.py +6 -13
- package/interfaces/cli/bugx_cli/commands/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +524 -169
- package/interfaces/cli/bugx_cli/common.py +21 -15
- package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
- package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +35 -16
- package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
- package/interfaces/cli/bugx_cli/infra/security.py +13 -6
- package/package.json +30 -15
- package/pyproject.toml +60 -9
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/webui/static/project-settings.css +0 -6458
- package/docs/07_distribution/README.md +0 -16
- package/docs/README.md +0 -121
- package/interfaces/README.md +0 -143
- package/interfaces/bin/README.md +0 -35
- package/interfaces/cli/README.md +0 -90
- package/scripts/README.md +0 -118
|
@@ -82,6 +82,139 @@ WEAK_TRANSFORMS = [
|
|
|
82
82
|
r"\.toLowerCase\(\)", r"\.lower\(\)", r"\(string\)", r"\.to_s\b",
|
|
83
83
|
]
|
|
84
84
|
|
|
85
|
+
# 字符串字面量起始引号(三引号优先,单双引号其次)。
|
|
86
|
+
# 反引号(JS/TS 模板字面量)**不在**此列:``${host}`` 的插值必须能被折叠。
|
|
87
|
+
_LITERAL_QUOTES = ('"""', "'''", '"', "'")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _literal_end(expr: str, start: int, quote: str) -> int:
|
|
91
|
+
"""从 ``start`` 起找 ``quote`` 的收尾位置(返回结束后的下标),找不到返回 -1。"""
|
|
92
|
+
index = start
|
|
93
|
+
while index < len(expr):
|
|
94
|
+
char = expr[index]
|
|
95
|
+
if char == "\\":
|
|
96
|
+
index += 2
|
|
97
|
+
continue
|
|
98
|
+
if expr.startswith(quote, index):
|
|
99
|
+
return index + len(quote)
|
|
100
|
+
# 单行引号不跨行;跨行说明解析器给的实参文本本身不完整,交由调用方兜底。
|
|
101
|
+
if len(quote) == 1 and char == "\n":
|
|
102
|
+
return -1
|
|
103
|
+
index += 1
|
|
104
|
+
return -1
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _matching_brace(text: str, start: int) -> int:
|
|
108
|
+
"""``text[start] == '{'``,返回与之配对的 ``}`` 之后的下标,找不到返回 -1。"""
|
|
109
|
+
depth = 0
|
|
110
|
+
index = start
|
|
111
|
+
while index < len(text):
|
|
112
|
+
char = text[index]
|
|
113
|
+
if char in "\"'":
|
|
114
|
+
end = _literal_end(text, index + 1, char)
|
|
115
|
+
if end < 0:
|
|
116
|
+
return -1
|
|
117
|
+
index = end
|
|
118
|
+
continue
|
|
119
|
+
if char == "\\":
|
|
120
|
+
index += 2
|
|
121
|
+
continue
|
|
122
|
+
if char == "{":
|
|
123
|
+
depth += 1
|
|
124
|
+
elif char == "}":
|
|
125
|
+
depth -= 1
|
|
126
|
+
if depth == 0:
|
|
127
|
+
return index + 1
|
|
128
|
+
index += 1
|
|
129
|
+
return -1
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _fstring_body_spans(body: str, depth: int = 0) -> list[tuple[bool, str]]:
|
|
133
|
+
"""f-string 体内:``{...}`` 是代码(插值),其余是字面量文本。
|
|
134
|
+
|
|
135
|
+
``{{`` / ``}}`` 是转义后的普通花括号,按字面量处理。
|
|
136
|
+
"""
|
|
137
|
+
spans: list[tuple[bool, str]] = []
|
|
138
|
+
buffer: list[str] = []
|
|
139
|
+
index = 0
|
|
140
|
+
while index < len(body):
|
|
141
|
+
char = body[index]
|
|
142
|
+
if char in "{}" and index + 1 < len(body) and body[index + 1] == char:
|
|
143
|
+
buffer.append(char * 2)
|
|
144
|
+
index += 2
|
|
145
|
+
continue
|
|
146
|
+
if char != "{":
|
|
147
|
+
buffer.append(char)
|
|
148
|
+
index += 1
|
|
149
|
+
continue
|
|
150
|
+
end = _matching_brace(body, index)
|
|
151
|
+
if end < 0:
|
|
152
|
+
buffer.append(body[index:])
|
|
153
|
+
break
|
|
154
|
+
if buffer:
|
|
155
|
+
spans.append((False, "".join(buffer)))
|
|
156
|
+
buffer = []
|
|
157
|
+
spans.append((True, "{"))
|
|
158
|
+
spans.extend(_split_code_and_literals(body[index + 1:end - 1], depth + 1))
|
|
159
|
+
spans.append((True, "}"))
|
|
160
|
+
index = end
|
|
161
|
+
if buffer:
|
|
162
|
+
spans.append((False, "".join(buffer)))
|
|
163
|
+
return spans
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _split_code_and_literals(expr: str, depth: int = 0) -> list[tuple[bool, str]]:
|
|
167
|
+
"""把实参文本切成 ``(是否代码, 片段)``。
|
|
168
|
+
|
|
169
|
+
普通字符串字面量(``"..."``、``'...'``、三引号)内部**不是代码**,变量折叠
|
|
170
|
+
不得进入;f-string 的**字面量文本**同样不是代码,只有 ``{...}`` 插值段是。
|
|
171
|
+
反引号模板字面量按代码处理(``${host}`` 必须能被折叠)。
|
|
172
|
+
引号未闭合时退回"整段都是代码",保持与旧实现一致的兜底行为。
|
|
173
|
+
"""
|
|
174
|
+
spans: list[tuple[bool, str]] = []
|
|
175
|
+
buffer: list[str] = []
|
|
176
|
+
index = 0
|
|
177
|
+
while index < len(expr):
|
|
178
|
+
char = expr[index]
|
|
179
|
+
if char not in "\"'":
|
|
180
|
+
buffer.append(char)
|
|
181
|
+
index += 1
|
|
182
|
+
continue
|
|
183
|
+
|
|
184
|
+
# 紧邻引号的标识符字母就是字符串前缀(f / r / b / u / rf ...)。
|
|
185
|
+
prefix_start = index
|
|
186
|
+
while prefix_start > 0 and (expr[prefix_start - 1].isalnum() or expr[prefix_start - 1] == "_"):
|
|
187
|
+
prefix_start -= 1
|
|
188
|
+
prefix = expr[prefix_start:index].lower()
|
|
189
|
+
|
|
190
|
+
quote = next((q for q in _LITERAL_QUOTES if expr.startswith(q, index)), char)
|
|
191
|
+
end = _literal_end(expr, index + len(quote), quote)
|
|
192
|
+
if end < 0:
|
|
193
|
+
buffer.append(expr[index:])
|
|
194
|
+
break
|
|
195
|
+
if "f" in prefix and depth < 3:
|
|
196
|
+
# f-string:插值是代码,必须继续参与折叠(SQLI/SSRF 的插值判据依赖它);
|
|
197
|
+
# 但字面量文本不是代码,不能被同名变量替换。
|
|
198
|
+
buffer.append(quote)
|
|
199
|
+
spans.append((True, "".join(buffer)))
|
|
200
|
+
buffer = []
|
|
201
|
+
spans.extend(
|
|
202
|
+
_fstring_body_spans(expr[index + len(quote):end - len(quote)], depth)
|
|
203
|
+
)
|
|
204
|
+
spans.append((True, quote))
|
|
205
|
+
index = end
|
|
206
|
+
continue
|
|
207
|
+
|
|
208
|
+
if buffer:
|
|
209
|
+
spans.append((True, "".join(buffer)))
|
|
210
|
+
buffer = []
|
|
211
|
+
spans.append((False, expr[index:end]))
|
|
212
|
+
index = end
|
|
213
|
+
|
|
214
|
+
if buffer:
|
|
215
|
+
spans.append((True, "".join(buffer)))
|
|
216
|
+
return spans
|
|
217
|
+
|
|
85
218
|
|
|
86
219
|
@dataclass
|
|
87
220
|
class FlowVariable:
|
|
@@ -180,7 +313,14 @@ class DynamicFlowAnalyzer:
|
|
|
180
313
|
parts.append(val)
|
|
181
314
|
if not c:
|
|
182
315
|
all_const = False
|
|
183
|
-
|
|
316
|
+
folded = "".join(parts)
|
|
317
|
+
# 含插值的 f-string 必须保留 ``f`` 前缀:折叠只做「值归一化」,不能
|
|
318
|
+
# 把动态插值抹平成普通字面量。下游的 SQLi/CMDi 规则靠「这是不是动态
|
|
319
|
+
# 拼出来的串」判定,前缀一丢,`execute(query)` 里 query 的插值痕迹
|
|
320
|
+
# 就彻底不可见(实测靶场种子 ① 因此漏检)。
|
|
321
|
+
if not all_const:
|
|
322
|
+
return 'f"' + folded + '"', False
|
|
323
|
+
return folded, all_const
|
|
184
324
|
|
|
185
325
|
# FormattedValue
|
|
186
326
|
if isinstance(node, ast.FormattedValue):
|
|
@@ -275,6 +415,56 @@ class DynamicFlowAnalyzer:
|
|
|
275
415
|
return m_pure.group(1), True
|
|
276
416
|
return curr, False
|
|
277
417
|
|
|
418
|
+
# 顶层关键字实参的起点(排除 ``==`` 比较)。
|
|
419
|
+
_KWARG_START_RE = re.compile(r",\s*[A-Za-z_][A-Za-z0-9_]*\s*=(?!=)")
|
|
420
|
+
|
|
421
|
+
def payload_portion(self, args: str) -> str:
|
|
422
|
+
"""取第一个关键字实参之前的部分——注入类规则的载荷面。"""
|
|
423
|
+
if not args:
|
|
424
|
+
return args
|
|
425
|
+
match = self._KWARG_START_RE.search(args)
|
|
426
|
+
return args[: match.start()] if match else args
|
|
427
|
+
|
|
428
|
+
# 标识符边界:不替换更长标识符的前缀,也不替换关键字实参名(``timeout=``)。
|
|
429
|
+
_IDENT_RE = re.compile(
|
|
430
|
+
r"(?<![A-Za-z0-9_$])([A-Za-z_$][A-Za-z0-9_$]*)(?![\w$])(?!\s*=(?!=))"
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
def _substitute_vars_once(
|
|
434
|
+
self, expr: str, env: dict[str, FlowVariable]
|
|
435
|
+
) -> tuple[str, bool]:
|
|
436
|
+
"""在表达式上**单次**替换变量引用,替换结果不再参与匹配。
|
|
437
|
+
|
|
438
|
+
返回 ``(替换后表达式, 是否引用了受污染变量)``。
|
|
439
|
+
|
|
440
|
+
替换只在**代码面**上做:普通字符串字面量(含三引号)内部不是代码,
|
|
441
|
+
按标识符直接替换会**凭空篡改分析对象**——实测 ``help="... cloud sync"``
|
|
442
|
+
里的 ``cloud`` 被同名变量替换成 ``subparsers.add_parser('cloud')``,
|
|
443
|
+
静态 DDL 里的列名被替换成 f-string,整段实参变成源码里不存在的东西。
|
|
444
|
+
全仓 317 个调用点存在这种改写。
|
|
445
|
+
|
|
446
|
+
f-string / 模板字面量(``f"..."``、``rf'...'``、JS 反引号)**整体仍按
|
|
447
|
+
代码处理**:``f"SELECT * FROM {table}"`` 的 ``{table}``、``${host}``
|
|
448
|
+
必须能被折叠还原,SQLI 与 SSRF 的插值判据都建立在折叠后的文本上。
|
|
449
|
+
"""
|
|
450
|
+
if not expr or not env:
|
|
451
|
+
return expr, False
|
|
452
|
+
tainted = False
|
|
453
|
+
|
|
454
|
+
def _repl(match: re.Match[str]) -> str:
|
|
455
|
+
nonlocal tainted
|
|
456
|
+
var = env.get(match.group(1))
|
|
457
|
+
if var is None:
|
|
458
|
+
return match.group(0)
|
|
459
|
+
if var.is_tainted:
|
|
460
|
+
tainted = True
|
|
461
|
+
return var.value
|
|
462
|
+
|
|
463
|
+
pieces: list[str] = []
|
|
464
|
+
for is_code, chunk in _split_code_and_literals(expr):
|
|
465
|
+
pieces.append(self._IDENT_RE.sub(_repl, chunk) if is_code else chunk)
|
|
466
|
+
return "".join(pieces), tainted
|
|
467
|
+
|
|
278
468
|
def resolve_call_target(
|
|
279
469
|
self, callee: str, args_raw: str, env: dict[str, FlowVariable], snippet: str = ""
|
|
280
470
|
) -> tuple[str, str, bool]:
|
|
@@ -289,20 +479,31 @@ class DynamicFlowAnalyzer:
|
|
|
289
479
|
if env[callee].is_tainted:
|
|
290
480
|
is_tainted = True
|
|
291
481
|
else:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if var.is_tainted:
|
|
297
|
-
is_tainted = True
|
|
482
|
+
resolved_callee, tainted_by_callee = self._substitute_vars_once(
|
|
483
|
+
resolved_callee, env
|
|
484
|
+
)
|
|
485
|
+
is_tainted = is_tainted or tainted_by_callee
|
|
298
486
|
|
|
299
487
|
# 2. 还原实参中的变量
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
488
|
+
#
|
|
489
|
+
# 必须**单次扫描、不回扫替换结果**。原先按 env 逐项 ``re.sub`` 的写法会让
|
|
490
|
+
# 替换进去的文本被后续变量名再次替换,产生级联污染:实测
|
|
491
|
+
# ``corpus_fetch.py`` 的 ``urlopen(req, timeout=timeout, ...)`` 被还原成
|
|
492
|
+
# 一整段把多个函数里 ``req`` 的赋值、``pool.submit(...)`` 片段拼在一起的
|
|
493
|
+
# 垃圾文本,进而被拼接检测判成动态构造(假 SSRF)。单次替换用一次
|
|
494
|
+
# ``re.sub`` + 回调实现:只在**原始实参**上找标识符,替换结果不再参与匹配。
|
|
495
|
+
resolved_args, _ = self._substitute_vars_once(resolved_args, env)
|
|
496
|
+
# 污点传播同样只看载荷面:`env=environment` 这类配置实参即使本身来自
|
|
497
|
+
# `os.environ`,也不构成注入面(见下方 payload_portion 说明)。
|
|
498
|
+
payload = self.payload_portion(args_raw)
|
|
499
|
+
if any(
|
|
500
|
+
var.is_tainted
|
|
501
|
+
and re.search(
|
|
502
|
+
rf"(?<![A-Za-z0-9_$]){re.escape(var.name)}(?![A-Za-z0-9_$])", payload
|
|
503
|
+
)
|
|
504
|
+
for var in env.values()
|
|
505
|
+
):
|
|
506
|
+
is_tainted = True
|
|
306
507
|
|
|
307
508
|
# 3. 检查 getattr(os, "system") 或 getattr(os, system) 字符串内嵌动态调用还原
|
|
308
509
|
m_getattr = re.search(r"getattr\(([^,]+),\s*['\"]?([A-Za-z0-9_]+)['\"]?\)", resolved_callee)
|
|
@@ -322,7 +523,11 @@ class DynamicFlowAnalyzer:
|
|
|
322
523
|
chain_raw = m_chain.group(1).strip()
|
|
323
524
|
resolved_args = self._resolve_line_vars(chain_raw, env)
|
|
324
525
|
|
|
325
|
-
|
|
526
|
+
# 污点只看**载荷面**(第一个关键字实参之前)。注入类规则的注入点是命令/查询
|
|
527
|
+
# 串本身;把 `env=os.environ.copy()`、`cwd=`、`timeout=` 这类配置实参也算进去,
|
|
528
|
+
# 会让 `subprocess.run(cmd, env=os.environ.copy())` 这种完全正常的调用被判成
|
|
529
|
+
# 命令注入(实测仓库自身就有一条 critical 假阳性)。
|
|
530
|
+
if self.has_framework_source(self.payload_portion(resolved_args)):
|
|
326
531
|
is_tainted = True
|
|
327
532
|
|
|
328
533
|
return resolved_callee, resolved_args, is_tainted
|
|
@@ -186,6 +186,9 @@ _SAFE_MODULES = {"math", "datetime", "itertools", "functools", "typing", "datacl
|
|
|
186
186
|
_RULES_FILE_NAME = "judge-rules.json"
|
|
187
187
|
_PROMOTE_THRESHOLD = 3
|
|
188
188
|
_MAX_ACTIVE_ADDITIONS = 20
|
|
189
|
+
#: 每类 candidates 的驻留上限(F-RSI-20261112-091):防一次性反馈 token
|
|
190
|
+
#: 无界驻留撑爆 rules 文件。晋升会清理对应 candidate;超限时拒绝新增。
|
|
191
|
+
_MAX_CANDIDATE_ENTRIES = 200
|
|
189
192
|
|
|
190
193
|
|
|
191
194
|
def default_rules() -> dict[str, Any]:
|
|
@@ -279,6 +282,11 @@ def harvest_feedback(
|
|
|
279
282
|
if token is None or token in base[key]:
|
|
280
283
|
counts["rejected"] += 1
|
|
281
284
|
continue
|
|
285
|
+
# F-RSI-20261112-091:已晋升生效的 token 直接跳过 candidate
|
|
286
|
+
# 记录——否则后续反馈经 setdefault 复活 candidate,形成
|
|
287
|
+
# active+candidate 双轨死数据。
|
|
288
|
+
if token in active.get(key, []):
|
|
289
|
+
continue
|
|
282
290
|
slot = candidates.setdefault(key, {})
|
|
283
291
|
entry = slot.setdefault(token, {"count": 0, "sources": []})
|
|
284
292
|
if unit not in entry["sources"]:
|
|
@@ -290,6 +298,28 @@ def harvest_feedback(
|
|
|
290
298
|
if token not in lst and len(lst) < _MAX_ACTIVE_ADDITIONS:
|
|
291
299
|
lst.append(token)
|
|
292
300
|
counts["promoted"] += 1
|
|
301
|
+
# F-RSI-20261112-091:晋升即从 candidates 清除——
|
|
302
|
+
# 已 active 的候选残留是死数据(count/sources 永久
|
|
303
|
+
# 驻留 rules 文件)。token in lst 幂等检查保证重复
|
|
304
|
+
# 晋升安全,清理不影响既有 active 语义。
|
|
305
|
+
slot.pop(token, None)
|
|
306
|
+
# F-RSI-20261112-091:candidates 每键上限——一次性反馈 token 无界驻留
|
|
307
|
+
# 会让 rules 文件无限膨胀(每次 harvest 全量读写)。超限时拒绝新增并
|
|
308
|
+
# 留痕(既有条目继续计数),上限按保守值不淘汰既有数据。
|
|
309
|
+
for key, slot in candidates.items():
|
|
310
|
+
overflow = len(slot) - _MAX_CANDIDATE_ENTRIES
|
|
311
|
+
if overflow > 0:
|
|
312
|
+
print(
|
|
313
|
+
f"[judge] ⚠ rule_feedback candidates[{key}] 已达上限 "
|
|
314
|
+
f"{_MAX_CANDIDATE_ENTRIES}(超出 {overflow} 条新增被拒;"
|
|
315
|
+
"清理 knowledge/judge-rules.json 或晋升既有条目可腾位)",
|
|
316
|
+
file=sys.stderr,
|
|
317
|
+
)
|
|
318
|
+
for token in list(slot):
|
|
319
|
+
if len(slot) <= _MAX_CANDIDATE_ENTRIES:
|
|
320
|
+
break
|
|
321
|
+
if token not in active.get(key, []):
|
|
322
|
+
slot.pop(token, None)
|
|
293
323
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
294
324
|
path.write_text(json.dumps(data, ensure_ascii=False, indent=1), encoding="utf-8")
|
|
295
325
|
return counts
|
|
@@ -602,10 +632,8 @@ def run_battery(
|
|
|
602
632
|
"json": "json.loads"}.get(suffix)
|
|
603
633
|
code = f"import pathlib\nraw = pathlib.Path({file_path!r}).read_text(encoding='utf-8', errors='ignore')\nassert raw.strip(), 'empty asset'\nprint('asset_bytes=%d' % len(raw))"
|
|
604
634
|
if parser:
|
|
605
|
-
body = ("import importlib\n"
|
|
606
|
-
f"parser = lambda t: __import__({{{suffix!r}: 'json'}}.get({suffix!r}, 'yaml')).{'loads' if suffix=='json' else 'safe_load'}(t)\n")
|
|
607
635
|
code = (f"import pathlib\nraw = pathlib.Path({file_path!r}).read_text(encoding='utf-8', errors='ignore')\nassert raw.strip(), 'empty asset'\n"
|
|
608
|
-
+ ("import json\
|
|
636
|
+
+ ("import json\nprint('parsed_items=%d' % len(json.loads(raw)))\n" if suffix == "json" else
|
|
609
637
|
"import yaml\ndata = yaml.safe_load(raw)\nassert data is not None, 'unparsable asset'\nprint('parsed_type=%s' % type(data).__name__)\n"))
|
|
610
638
|
all_probes = all_probes + [{"desc": f"asset-integrity[{suffix or 'text'}] {file_path}", "code": code}]
|
|
611
639
|
if has_exec_signal(unit_source, dep_sources=dep_sources, rules=rules):
|
|
@@ -903,6 +931,39 @@ def run_battery_probe(
|
|
|
903
931
|
|
|
904
932
|
|
|
905
933
|
_PROBE_REQUEST_SHELL_TOKENS = (";", "&&", "||", "`", "$(", ">", "<")
|
|
934
|
+
#: probe_requests 的宿主执行身份是引擎进程——被审项目的恶意内容可能提示
|
|
935
|
+
#: 注入 judge 产出 probe_requests(conventions 消毒同款威胁模型)。shell
|
|
936
|
+
#: 字符黑名单挡不住 `import os` + 换行分隔的 python 逃逸,此处按 AST 拒收
|
|
937
|
+
#: 高危导入与动态执行调用(纵深防御;-c 无沙箱,最终信任边界是宿主)。
|
|
938
|
+
_PROBE_REQUEST_BANNED_MODULES = frozenset({
|
|
939
|
+
"os", "subprocess", "socket", "ctypes", "signal", "importlib",
|
|
940
|
+
"shutil", "sys", "pathlib", "builtins",
|
|
941
|
+
})
|
|
942
|
+
_PROBE_REQUEST_BANNED_CALLS = frozenset({
|
|
943
|
+
"eval", "exec", "compile", "__import__", "open", "globals", "locals",
|
|
944
|
+
})
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
def _probe_code_escaped_sandbox(code: str) -> bool:
|
|
948
|
+
"""True = 代码含逃逸出「观测断言」语义的构造(import 高危模块/动态执行)。"""
|
|
949
|
+
try:
|
|
950
|
+
tree = ast.parse(code)
|
|
951
|
+
except (SyntaxError, ValueError):
|
|
952
|
+
return True
|
|
953
|
+
for node in ast.walk(tree):
|
|
954
|
+
if isinstance(node, ast.Import):
|
|
955
|
+
for alias in node.names:
|
|
956
|
+
if alias.name.split(".")[0] in _PROBE_REQUEST_BANNED_MODULES:
|
|
957
|
+
return True
|
|
958
|
+
elif isinstance(node, ast.ImportFrom):
|
|
959
|
+
if (node.module or "").split(".")[0] in _PROBE_REQUEST_BANNED_MODULES:
|
|
960
|
+
return True
|
|
961
|
+
elif isinstance(node, ast.Call):
|
|
962
|
+
fn = node.func
|
|
963
|
+
name = getattr(fn, "id", None) or getattr(fn, "attr", None)
|
|
964
|
+
if name in _PROBE_REQUEST_BANNED_CALLS:
|
|
965
|
+
return True
|
|
966
|
+
return False
|
|
906
967
|
|
|
907
968
|
|
|
908
969
|
def validate_probe_requests(requests: object) -> list[dict[str, str]]:
|
|
@@ -917,6 +978,14 @@ def validate_probe_requests(requests: object) -> list[dict[str, str]]:
|
|
|
917
978
|
desc = str(item.get("desc") or "probe")[:120]
|
|
918
979
|
if not code or any(tok in code for tok in _PROBE_REQUEST_SHELL_TOKENS):
|
|
919
980
|
continue
|
|
981
|
+
# F-RSI-20261112-093:AST 纵深守卫——拒收 import os/subprocess 等
|
|
982
|
+
# 逃逸构造与 eval/exec/open 动态执行(观测断言语义不需要它们)。
|
|
983
|
+
if _probe_code_escaped_sandbox(code):
|
|
984
|
+
print(
|
|
985
|
+
f"[judge] ✗ probe_requests 含越出观测断言语义的构造,已拒收: {desc}",
|
|
986
|
+
file=sys.stderr,
|
|
987
|
+
)
|
|
988
|
+
continue
|
|
920
989
|
out.append({"desc": desc, "code": code})
|
|
921
990
|
return out
|
|
922
991
|
|
|
@@ -974,6 +1043,18 @@ def execute_reproduction(
|
|
|
974
1043
|
artifact_root = (root / artifact_root).resolve() if not Path(artifact_root).is_absolute() else Path(artifact_root).resolve()
|
|
975
1044
|
artifact_root.mkdir(parents=True, exist_ok=True)
|
|
976
1045
|
argv = command.split(" ", 1)
|
|
1046
|
+
# F-RSI-20261112-092:复现脚本的执行边界必须锁定在被审项目 root 内——
|
|
1047
|
+
# judge 给出的相对路径(../)或绝对路径可指向 root 外任意 py 文件
|
|
1048
|
+
# (宿主机脚本/引擎自身代码),越出「复现被审项目缺陷」的边界。
|
|
1049
|
+
if len(argv) > 1:
|
|
1050
|
+
script = Path(argv[1])
|
|
1051
|
+
script = (root / script).resolve() if not script.is_absolute() else script.resolve()
|
|
1052
|
+
if script != root and root not in script.parents:
|
|
1053
|
+
print(
|
|
1054
|
+
f"[judge] ✗ 复现命令越界拒绝:{argv[1]} 不在项目 root 内",
|
|
1055
|
+
file=sys.stderr,
|
|
1056
|
+
)
|
|
1057
|
+
return None
|
|
977
1058
|
started = time.time()
|
|
978
1059
|
try:
|
|
979
1060
|
proc = subprocess.run(
|
|
@@ -1055,7 +1136,9 @@ def checkpoint_payload_from_verdict(
|
|
|
1055
1136
|
) -> dict[str, Any] | None:
|
|
1056
1137
|
"""把裁决映射成 supervisor checkpoint payload(机器构造,无手搓)。
|
|
1057
1138
|
|
|
1058
|
-
- clean
|
|
1139
|
+
- clean 且电池/复现证据可绑定 → 全单元 covered(结构化证据落账)
|
|
1140
|
+
- insufficient_data → 全单元 unverified(judge 明确拒判:不得以电池
|
|
1141
|
+
探针通过冒充已覆盖;artifact_only 例外记 not_applicable)
|
|
1059
1142
|
- bug → 单元 covered,findings 附带,且每条 finding 的复现收据
|
|
1060
1143
|
(宿主实跑)优先作为该单元 evidence;无复现收据时回退电池 evidence,
|
|
1061
1144
|
finding 标记 reproducible=false。
|
|
@@ -123,6 +123,7 @@ _STAGE_MAP = {
|
|
|
123
123
|
"l0": "l0_router.md",
|
|
124
124
|
"gate": "stages/stage_gate.md",
|
|
125
125
|
"explore": "stages/stage_explore.md",
|
|
126
|
+
"verify": "stages/stage_verify.md",
|
|
126
127
|
"mutate": "stages/stage_mutate.md",
|
|
127
128
|
"repair": "stages/stage_repair.md",
|
|
128
129
|
}
|
|
@@ -520,7 +521,11 @@ def load_stage(stage: str, root: Path | None = None) -> str:
|
|
|
520
521
|
prompts_dir = get_prompts_dir(root)
|
|
521
522
|
file_path = prompts_dir / _STAGE_MAP[key]
|
|
522
523
|
if not file_path.is_file():
|
|
523
|
-
|
|
524
|
+
local_fallback = Path(__file__).resolve().parents[1] / "prompts" / _STAGE_MAP[key]
|
|
525
|
+
if local_fallback.is_file():
|
|
526
|
+
file_path = local_fallback
|
|
527
|
+
else:
|
|
528
|
+
raise FileNotFoundError(f"阶段提示词文件缺失: {file_path}")
|
|
524
529
|
content = file_path.read_text(encoding="utf-8").strip()
|
|
525
530
|
# P1:附加 bugx.md 权威章节指针,消除"阶段卡 vs 全文"双源竞争。
|
|
526
531
|
content += _stage_section_pointers(key, root)
|
|
@@ -558,15 +563,46 @@ def get_stage_prompt(
|
|
|
558
563
|
context: Mapping[str, object] | None = None,
|
|
559
564
|
root: Path | None = None,
|
|
560
565
|
locale: str | None = None,
|
|
566
|
+
*,
|
|
567
|
+
host: str | None = None,
|
|
568
|
+
provider: str | None = None,
|
|
569
|
+
model: str | None = None,
|
|
570
|
+
policy: str | None = None,
|
|
571
|
+
last_error: str | None = None,
|
|
561
572
|
) -> str:
|
|
562
|
-
"""
|
|
573
|
+
"""组装阶段提示词,注入动态上下文事实,并按可配置策略引擎适配模型风控边界 (DOC-043, DOC-067, DOC-139)。"""
|
|
574
|
+
from core.planning import prompt_policy_engine
|
|
575
|
+
|
|
563
576
|
key = stage.strip().lower()
|
|
564
|
-
|
|
577
|
+
resolved_policy = prompt_policy_engine.resolve_policy(
|
|
578
|
+
host=host,
|
|
579
|
+
provider=provider,
|
|
580
|
+
model=model,
|
|
581
|
+
last_error=last_error,
|
|
582
|
+
explicit_policy=policy,
|
|
583
|
+
root=root,
|
|
584
|
+
)
|
|
585
|
+
override_rel = prompt_policy_engine.resolve_stage_override_relpath(resolved_policy, key)
|
|
586
|
+
if override_rel:
|
|
587
|
+
override_path = prompt_policy_engine.PROMPTS_ROOT / override_rel
|
|
588
|
+
if override_path.is_file():
|
|
589
|
+
base_prompt = override_path.read_text(encoding="utf-8")
|
|
590
|
+
else:
|
|
591
|
+
base_prompt = load_stage(key, root=root)
|
|
592
|
+
else:
|
|
593
|
+
base_prompt = load_stage(key, root=root)
|
|
594
|
+
|
|
595
|
+
def _finalize(rendered: str) -> str:
|
|
596
|
+
return prompt_policy_engine.apply_policy(
|
|
597
|
+
rendered,
|
|
598
|
+
resolved_policy,
|
|
599
|
+
include_preamble=True,
|
|
600
|
+
include_safe_repro=(key in {"verify", "mutate"}),
|
|
601
|
+
)
|
|
602
|
+
|
|
565
603
|
if not context:
|
|
566
604
|
# L0 是常驻入口,也必须经过和其他注入段相同的硬预算出口。
|
|
567
|
-
|
|
568
|
-
return base_prompt
|
|
569
|
-
return base_prompt
|
|
605
|
+
return _finalize(base_prompt)
|
|
570
606
|
|
|
571
607
|
title = "## 动态运行时事实(Dynamic Context)"
|
|
572
608
|
if i18n is not None:
|
|
@@ -604,11 +640,15 @@ def get_stage_prompt(
|
|
|
604
640
|
"dynamic_context": "Dynamic Context 事实注入",
|
|
605
641
|
},
|
|
606
642
|
)
|
|
607
|
-
return
|
|
608
|
-
|
|
643
|
+
return _finalize(
|
|
644
|
+
sections["l0_router"] + sections["dynamic_context"] + _record_budget_degradations(
|
|
645
|
+
context_degradations + degradations, stage="l0",
|
|
646
|
+
)
|
|
647
|
+
)
|
|
648
|
+
return _finalize(
|
|
649
|
+
base_prompt + context_text + _record_budget_degradations(
|
|
650
|
+
context_degradations, stage=key,
|
|
609
651
|
)
|
|
610
|
-
return base_prompt + context_text + _record_budget_degradations(
|
|
611
|
-
context_degradations, stage=key,
|
|
612
652
|
)
|
|
613
653
|
|
|
614
654
|
|
|
@@ -1370,10 +1410,12 @@ PROBE_SPECIFICATIONS: dict[str, str] = {
|
|
|
1370
1410
|
"- 工具接口: `apk_decompile_manifest` (解析 exported 组件与 DeepLink 过滤器), `adb_send_intent` (跨进程触发 Intent 越权)\n"
|
|
1371
1411
|
"- 操作规范: 验证能否未认证越权拉起私有 Activity/Service,或通过伪造 Intent Extras 提取沙箱 SQLite 敏感数据。"
|
|
1372
1412
|
),
|
|
1373
|
-
"
|
|
1374
|
-
"### [黑盒探针:
|
|
1375
|
-
"- 工具接口: `
|
|
1376
|
-
"
|
|
1413
|
+
"ios_binary": (
|
|
1414
|
+
"### [黑盒探针: ios_binary (Mach-O 加固 / 代码签名 / entitlements / ATS)]\n"
|
|
1415
|
+
"- 工具接口: `codesign`/`otool`/`nm` 宿主二进制审计(PIE、栈保护、cryptid、entitlements), "
|
|
1416
|
+
"Info.plist 静态安全门(ATS 放宽 `NSAllowsArbitraryLoads*`、`UIFileSharingEnabled` 明文落盘)\n"
|
|
1417
|
+
"- 操作规范: 审查 ATS 强制放宽、敏感 entitlements 过宽(keychain-access-groups 等)"
|
|
1418
|
+
"及二进制加固缺失(no-PIE / no-stack-canary)对应的可利用面。"
|
|
1377
1419
|
),
|
|
1378
1420
|
"miniprogram_probe": (
|
|
1379
1421
|
"### [黑盒探针: MiniProgramProbe (Subpackage Router & Cloud Functions)]\n"
|
|
@@ -1492,7 +1534,7 @@ def build_domain_specialized_prompt(
|
|
|
1492
1534
|
elif target_form_norm in ("mobile_android", "android"):
|
|
1493
1535
|
probes = ["android_probe"]
|
|
1494
1536
|
elif target_form_norm in ("mobile_ios", "ios"):
|
|
1495
|
-
probes = ["
|
|
1537
|
+
probes = ["ios_binary"]
|
|
1496
1538
|
elif target_form_norm in ("miniprogram", "wechat"):
|
|
1497
1539
|
probes = ["miniprogram_probe"]
|
|
1498
1540
|
elif target_form_norm in ("binary", "embedded"):
|