bugx-cli 0.0.0-stage → 0.1.0
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/LICENSE +55 -0
- package/README.md +280 -2
- package/core/CATALOG.json +141 -0
- package/core/README.md +254 -0
- package/core/adapters/README.md +35 -0
- package/core/adapters/android-interaction.json +81 -0
- package/core/adapters/android.json +24 -0
- package/core/adapters/desktop-macos.json +20 -0
- package/core/adapters/ios-interaction.json +34 -0
- package/core/adapters/ios.json +23 -0
- package/core/adapters/memory-macos.json +24 -0
- package/core/agent/README.md +50 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +764 -0
- package/core/agent/agent_eval.py +1073 -0
- package/core/agent/agent_execution.py +552 -0
- package/core/agent/agent_orchestrator.py +1345 -0
- package/core/agent/agent_targets.py +871 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/assets/README.md +24 -0
- package/core/assets/bugx-avatar-1024.png +0 -0
- package/core/assets/bugx-avatar-512.png +0 -0
- package/core/assets/bugx-avatar-tight.svg +23 -0
- package/core/assets/bugx-avatar.svg +28 -0
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/assets/project-layout.md +42 -0
- package/core/audit_packs/README.md +37 -0
- package/core/audit_packs/data-audit/manifest.json +94 -0
- package/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- package/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- package/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/desktop-audit/manifest.json +123 -0
- package/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- package/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- package/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- package/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- package/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- package/core/audit_packs/memory-testing.md +227 -0
- package/core/audit_packs/mobile-audit/manifest.json +155 -0
- package/core/audit_packs/mobile-audit/modules/android.md +19 -0
- package/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- package/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- package/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- package/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- package/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- package/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- package/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- package/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- package/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- package/core/audit_packs/native-audit/manifest.json +127 -0
- package/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- package/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- package/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- package/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/platform-testing.md +174 -0
- package/core/audit_packs/web-audit/manifest.json +191 -0
- package/core/audit_packs/web-audit/modules/graphql.md +5 -0
- package/core/audit_packs/web-audit/modules/h5.md +18 -0
- package/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- package/core/audit_packs/web-audit/modules/oauth.md +4 -0
- package/core/audit_packs/web-audit/modules/upload.md +4 -0
- package/core/audit_packs/web-audit/modules/websocket.md +4 -0
- package/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- package/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- package/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- package/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- package/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- package/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- package/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- package/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- package/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- package/core/autonomous_cve/INTERFACE.md +61 -0
- package/core/autonomous_cve/README.md +58 -0
- package/core/autonomous_cve/SPEC.md +25 -0
- package/core/autonomous_cve/__init__.py +109 -0
- package/core/autonomous_cve/attack_graph.py +1096 -0
- package/core/autonomous_cve/attack_graph_store.py +1822 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +459 -0
- package/core/autonomous_cve/ghsa_advisories.py +174 -0
- package/core/autonomous_cve/models.py +93 -0
- package/core/autonomous_cve/mutator.py +87 -0
- package/core/autonomous_cve/patcher.py +126 -0
- package/core/autonomous_cve/scout.py +278 -0
- package/core/autonomous_cve/synthesizer.py +207 -0
- package/core/autonomous_cve/verifier.py +100 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1846 -0
- package/core/cloud_sync/INTERFACE.md +32 -0
- package/core/cloud_sync/README.md +62 -0
- package/core/cloud_sync/SPEC.md +25 -0
- package/core/cloud_sync/__init__.py +23 -0
- package/core/cloud_sync/auto_sync.py +398 -0
- package/core/cloud_sync/cloud_client.py +1199 -0
- package/core/cloud_sync/cloud_onboard.py +702 -0
- package/core/cloud_sync/cloud_schema.py +648 -0
- package/core/cloud_sync/consent.py +81 -0
- package/core/cloud_sync/device_identity.py +307 -0
- package/core/cloud_sync/endpoint_router.py +415 -0
- package/core/cloud_sync/flywheel_client.py +760 -0
- package/core/cloud_sync/network_transport.py +275 -0
- package/core/cloud_sync/onboard_wizard.py +493 -0
- package/core/cloud_sync/sensitive_filter.py +285 -0
- package/core/cloud_sync/sync_pull.py +695 -0
- package/core/cloud_sync/sync_push.py +721 -0
- package/core/contracts/AGENT_GUIDE.md +362 -0
- package/core/contracts/README.md +34 -0
- package/core/contracts/bugx-blackbox.md +541 -0
- package/core/contracts/bugx-opencode.md +469 -0
- package/core/contracts/bugx-quick.md +44 -0
- package/core/contracts/bugx-runtime-contract.md +353 -0
- package/core/contracts/bugx-worker.md +470 -0
- package/core/contracts/engine_gap_contracts.py +390 -0
- package/core/coverage/README.md +70 -0
- package/core/coverage/__init__.py +106 -0
- package/core/coverage/coverage_ai_review.py +185 -0
- package/core/coverage/coverage_backfill.py +54 -0
- package/core/coverage/coverage_bootstrap.py +713 -0
- package/core/coverage/coverage_business.py +36 -0
- package/core/coverage/coverage_cli.py +715 -0
- package/core/coverage/coverage_discovery.py +859 -0
- package/core/coverage/coverage_evidence.py +977 -0
- package/core/coverage/coverage_forensics.py +115 -0
- package/core/coverage/coverage_gate.py +277 -0
- package/core/coverage/coverage_intelligence.py +734 -0
- package/core/coverage/coverage_manifest.py +396 -0
- package/core/coverage/coverage_platform.py +77 -0
- package/core/coverage/coverage_validate.py +236 -0
- package/core/coverage/module_coverage.py +157 -0
- package/core/dev_harness/INTERFACE.md +20 -0
- package/core/dev_harness/README.md +21 -0
- package/core/dev_harness/SPEC.md +25 -0
- package/core/dev_harness/__init__.py +5 -0
- package/core/dev_harness/interaction_preset.py +408 -0
- package/core/engine-integrity.json +2625 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +382 -0
- package/core/fuzzing/differential_oracle.py +629 -0
- package/core/fuzzing/fuzz_input.py +1188 -0
- package/core/fuzzing/stateful_fuzzer.py +332 -0
- package/core/governance/README.md +61 -0
- package/core/governance/__init__.py +130 -0
- package/core/governance/capacity_planner.py +124 -0
- package/core/governance/dependency_lock.py +317 -0
- package/core/governance/goal_governor.py +754 -0
- package/core/governance/guide_budget.py +458 -0
- package/core/governance/lockdown.sh +50 -0
- package/core/governance/readonly_enforcer.py +154 -0
- package/core/governance/runtime_tool_gate.py +373 -0
- package/core/governance/secret_redactor.py +772 -0
- package/core/governance/token_budget.py +38 -0
- package/core/host_acp/INTERFACE.md +36 -0
- package/core/host_acp/README.md +51 -0
- package/core/host_acp/SPEC.md +25 -0
- package/core/host_acp/__init__.py +121 -0
- package/core/host_acp/base.py +111 -0
- package/core/host_acp/claude.py +41 -0
- package/core/host_acp/cline.py +235 -0
- package/core/host_acp/codex.py +245 -0
- package/core/host_acp/dsh.py +48 -0
- package/core/host_acp/opencode.py +154 -0
- package/core/host_acp/pi.py +36 -0
- package/core/host_acp/zcode.py +41 -0
- package/core/host_runtime/INTERFACE.md +24 -0
- package/core/host_runtime/README.md +62 -0
- package/core/host_runtime/SPEC.md +25 -0
- package/core/host_runtime/__init__.py +21 -0
- package/core/host_runtime/adapters.py +412 -0
- package/core/host_runtime/autonomous_runner.py +1152 -0
- package/core/host_runtime/cline.py +435 -0
- package/core/host_runtime/common.py +103 -0
- package/core/host_runtime/free_models.py +786 -0
- package/core/host_runtime/host_bootstrap.py +389 -0
- package/core/host_runtime/host_evaluators.py +721 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +777 -0
- package/core/host_runtime/host_registry.py +655 -0
- package/core/host_runtime/host_usage.py +127 -0
- package/core/host_runtime/mcp_process_tracker.py +509 -0
- package/core/host_runtime/mcp_registry_gate.py +368 -0
- package/core/hosts/INTERFACE.md +51 -0
- package/core/hosts/README.md +67 -0
- package/core/hosts/SPEC.md +25 -0
- package/core/hosts/__init__.py +136 -0
- package/core/hosts/_base_usage.py +152 -0
- package/core/hosts/_codex_usage.py +297 -0
- package/core/hosts/_dsh_usage.py +184 -0
- package/core/hosts/_mcp_toml.py +365 -0
- package/core/hosts/_zcode_usage.py +269 -0
- package/core/hosts/base.py +451 -0
- package/core/hosts/claude.py +157 -0
- package/core/hosts/cline.py +225 -0
- package/core/hosts/codex.py +948 -0
- package/core/hosts/dsh.py +518 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +151 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +39 -0
- package/core/infra/__init__.py +15 -0
- package/core/infra/build_info.py +86 -0
- package/core/infra/client_metadata.py +185 -0
- package/core/infra/python_runtime.py +540 -0
- package/core/infra/safe_xml.py +221 -0
- package/core/launch_bugx.py +118 -0
- package/core/launch_phases/INTERFACE.md +31 -0
- package/core/launch_phases/README.md +106 -0
- package/core/launch_phases/SPEC.md +25 -0
- package/core/launch_phases/__init__.py +29 -0
- package/core/launch_phases/candidate_revalidation.py +484 -0
- package/core/launch_phases/common.py +1041 -0
- package/core/launch_phases/finding_confirm_phase.py +387 -0
- package/core/launch_phases/finding_settlement.py +1245 -0
- package/core/launch_phases/findings_adjudication.py +666 -0
- package/core/launch_phases/findings_snapshot.py +357 -0
- package/core/launch_phases/judge_phase.py +791 -0
- package/core/launch_phases/lesson_context.py +536 -0
- package/core/launch_phases/lifecycle_reporter.py +627 -0
- package/core/launch_phases/orchestrator_controls.py +682 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +591 -0
- package/core/launch_phases/post_dry_run.py +817 -0
- package/core/launch_phases/post_observability.py +367 -0
- package/core/launch_phases/post_phase.py +1087 -0
- package/core/launch_phases/post_receipt.py +362 -0
- package/core/launch_phases/post_round_lifecycle.py +786 -0
- package/core/launch_phases/pre_phase.py +1029 -0
- package/core/launch_phases/pre_recon_scout.py +862 -0
- package/core/launch_phases/pre_state_builder.py +1286 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1133 -0
- package/core/launch_phases/session_runtime.py +1623 -0
- package/core/launch_phases/startup_gates.py +1022 -0
- package/core/launch_phases/startup_interaction.py +947 -0
- package/core/launch_phases/startup_version_gate.py +873 -0
- package/core/launch_phases/supervisor_bridge.py +1224 -0
- package/core/launch_phases/supervisor_coverage.py +417 -0
- package/core/launch_phases/supervisor_degraded.py +1219 -0
- package/core/launch_phases/worker_barriers.py +414 -0
- package/core/launch_phases/worker_orchestrator.py +1166 -0
- package/core/launch_phases/worker_prior.py +749 -0
- package/core/ledger/INTERFACE.md +35 -0
- package/core/ledger/README.md +160 -0
- package/core/ledger/SPEC.md +25 -0
- package/core/ledger/__init__.py +67 -0
- package/core/ledger/_facade.py +226 -0
- package/core/ledger/archive_ops.py +572 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +270 -0
- package/core/ledger/export_ops.py +549 -0
- package/core/ledger/finding_confirmation.py +1274 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +307 -0
- package/core/ledger/finding_verification.py +369 -0
- package/core/ledger/incidents.py +999 -0
- package/core/ledger/lesson-replay-cases.json +20 -0
- package/core/ledger/lesson_ledger.py +241 -0
- package/core/ledger/lesson_replay.py +272 -0
- package/core/ledger/life_ledger.py +668 -0
- package/core/ledger/mistake-book.md +130 -0
- package/core/ledger/patterns.py +681 -0
- package/core/ledger/receipt_contract.py +253 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +935 -0
- package/core/ledger/tool_experience.py +682 -0
- package/core/ledger/verify_life.py +1526 -0
- package/core/lesson-ledger.json +275 -0
- package/core/locales/README.md +19 -0
- package/core/locales/en-US.json +462 -0
- package/core/locales/zh-CN.json +462 -0
- package/core/mcp_handlers/INTERFACE.md +75 -0
- package/core/mcp_handlers/README.md +62 -0
- package/core/mcp_handlers/SPEC.md +25 -0
- package/core/mcp_handlers/__init__.py +128 -0
- package/core/mcp_handlers/base.py +697 -0
- package/core/mcp_handlers/channel_lifecycle.py +696 -0
- package/core/mcp_handlers/graph_handlers.py +222 -0
- package/core/mcp_handlers/knowledge_handlers.py +536 -0
- package/core/mcp_handlers/mining_handlers.py +586 -0
- package/core/mcp_handlers/resource_prompt_table.py +116 -0
- package/core/mcp_handlers/retrieval_handlers.py +239 -0
- package/core/mcp_handlers/rpc_server.py +465 -0
- package/core/mcp_handlers/supervisor_handlers.py +1435 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1015 -0
- package/core/mcp_runtime_support/README.md +21 -0
- package/core/mcp_runtime_support/__init__.py +1 -0
- package/core/mcp_runtime_support/common.py +363 -0
- package/core/mcp_runtime_support/environment.py +605 -0
- package/core/mcp_runtime_support/verifier.py +810 -0
- package/core/metadata.txt +5 -0
- package/core/planning/README.md +157 -0
- package/core/planning/__init__.py +242 -0
- package/core/planning/capability_plan.py +187 -0
- package/core/planning/capability_planner.py +195 -0
- package/core/planning/domain_archetype.py +542 -0
- package/core/planning/domain_router.py +267 -0
- package/core/planning/dynamic_flow_analyzer.py +328 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1163 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1702 -0
- package/core/planning/source_inspector.py +267 -0
- package/core/planning/spec_harvester.py +449 -0
- package/core/planning/target_sandbox_manager.py +573 -0
- package/core/planning/test_capability_verifier.py +1364 -0
- package/core/planning/tools-kb.md +38 -0
- package/core/planning/unit_kind.py +122 -0
- package/core/probes/INTERFACE.md +73 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +26 -0
- package/core/probes/__init__.py +70 -0
- package/core/probes/android_probe.py +384 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +590 -0
- package/core/probes/desktop_probe.py +238 -0
- package/core/probes/differential_probe.py +356 -0
- package/core/probes/efficiency_probe.py +168 -0
- package/core/probes/ios_binary_probe.py +368 -0
- package/core/probes/memory_probe.py +326 -0
- package/core/probes/miniprogram_probe.py +323 -0
- package/core/probes/mobile_probe.py +281 -0
- package/core/probes/native_probe.py +214 -0
- package/core/probes/openwiki_probe.py +193 -0
- package/core/probes/pattern_probe.py +347 -0
- package/core/probes/platform_probe.py +343 -0
- package/core/probes/probe_registry.py +1669 -0
- package/core/probes/sast_probe.py +1009 -0
- package/core/probes/sast_rules.py +841 -0
- package/core/probes/sca_scanner.py +731 -0
- package/core/probes/web_probe.py +359 -0
- package/core/project_profiler/INTERFACE.md +62 -0
- package/core/project_profiler/README.md +53 -0
- package/core/project_profiler/SPEC.md +28 -0
- package/core/project_profiler/__init__.py +201 -0
- package/core/project_profiler/arbitrator.py +311 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +392 -0
- package/core/project_profiler/extractors.py +836 -0
- package/core/project_profiler/fingerprint.py +116 -0
- package/core/project_profiler/storage.py +258 -0
- package/core/project_profiler/strategy.py +265 -0
- package/core/prompts/README.md +35 -0
- package/core/prompts/codex_dialog_dispatch.md +9 -0
- package/core/prompts/command_routing_en.md +42 -0
- package/core/prompts/command_routing_zh.md +42 -0
- package/core/prompts/l0_router.md +47 -0
- package/core/prompts/rules/anti_patterns.md +16 -0
- package/core/prompts/rules/concurrency_rules.md +14 -0
- package/core/prompts/rules/memory_leak_rules.md +13 -0
- package/core/prompts/rules/prompt_injection_defense.md +13 -0
- package/core/prompts/stages/stage_explore.md +31 -0
- package/core/prompts/stages/stage_gate.md +43 -0
- package/core/prompts/stages/stage_mutate.md +42 -0
- package/core/prompts/stages/stage_repair.md +85 -0
- package/core/repair/README.md +74 -0
- package/core/repair/__init__.py +169 -0
- package/core/repair/fix_watchlist.py +391 -0
- package/core/repair/l7_dynamic.py +418 -0
- package/core/repair/l7_repair_loop.py +465 -0
- package/core/repair/l7_selfcheck.py +862 -0
- package/core/repair/minimize_repro.py +466 -0
- package/core/repair/patch_synthesizer.py +617 -0
- package/core/repair/regression_pack.py +379 -0
- package/core/repair/rsi_fixer.py +910 -0
- package/core/repair/rsi_loop.py +313 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +262 -0
- package/core/repair/self_heal.py +604 -0
- package/core/repair/test_generator.py +1108 -0
- package/core/repair/test_quality_auditor.py +410 -0
- package/core/repair/test_strategy.py +511 -0
- package/core/report_engine/INTERFACE.md +59 -0
- package/core/report_engine/README.md +69 -0
- package/core/report_engine/SPEC.md +28 -0
- package/core/report_engine/__init__.py +47 -0
- package/core/report_engine/attestation.py +224 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +417 -0
- package/core/report_engine/formal_report_builder.py +924 -0
- package/core/report_engine/html_renderers.py +696 -0
- package/core/report_engine/models.py +761 -0
- package/core/report_engine/pdf_exporter.py +231 -0
- package/core/report_engine/projects_assets.py +730 -0
- package/core/report_engine/report_client.py +743 -0
- package/core/report_engine/report_data_builder.py +388 -0
- package/core/report_engine/report_share.py +459 -0
- package/core/report_engine/sast_bridge.py +116 -0
- package/core/report_engine/server.py +822 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +63 -0
- package/core/report_engine/web_conformance.py +459 -0
- package/core/report_engine/workbench_assets.py +484 -0
- package/core/retrieval/INTERFACE.md +20 -0
- package/core/retrieval/README.md +161 -0
- package/core/retrieval/SPEC.md +25 -0
- package/core/retrieval/__init__.py +3 -0
- package/core/retrieval/code_analyzer.py +1684 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +234 -0
- package/core/retrieval/corpus_fetch.py +369 -0
- package/core/retrieval/graph_ego.py +597 -0
- package/core/retrieval/knowledge_auto.py +662 -0
- package/core/retrieval/knowledge_sources.py +168 -0
- package/core/retrieval/knowledge_sync.py +909 -0
- package/core/retrieval/memory_store.py +480 -0
- package/core/retrieval/query_planner.py +1020 -0
- package/core/retrieval/rrf_engine.py +137 -0
- package/core/retrieval/slice_extractor.py +1209 -0
- package/core/retrieval/slice_normalizer.py +373 -0
- package/core/retrieval/slice_spec.py +357 -0
- package/core/retrieval/symbol_index.py +1132 -0
- package/core/retrieval/universal_code_matcher.py +437 -0
- package/core/retrieval/xerj_bridge.py +476 -0
- package/core/retrieval/xerj_supervisor.py +362 -0
- package/core/rules/README.md +33 -0
- package/core/rules/ios/PROVENANCE.json +30 -0
- package/core/rules/ios/crypto.yaml +36 -0
- package/core/rules/ios/network.yaml +20 -0
- package/core/rules/ios/resilience.yaml +47 -0
- package/core/rules/ios/storage.yaml +48 -0
- package/core/rules/mastg/LICENSE +173 -0
- package/core/rules/mastg/PROVENANCE.json +270 -0
- package/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- package/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- package/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- package/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- package/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- package/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- package/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- package/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- package/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- package/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- package/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- package/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- package/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- package/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- package/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- package/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- package/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- package/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- package/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- package/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- package/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- package/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- package/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- package/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- package/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- package/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- package/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- package/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- package/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- package/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- package/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- package/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- package/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- package/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- package/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- package/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- package/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- package/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- package/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- package/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- package/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- package/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- package/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- package/core/rules/miniprogram/PROVENANCE.json +26 -0
- package/core/rules/miniprogram/network.yaml +37 -0
- package/core/rules/miniprogram/platform.yaml +36 -0
- package/core/rules/miniprogram/storage.yaml +48 -0
- package/core/rules/mobsfscan-swift/LICENSE +165 -0
- package/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- package/core/rules/mobsfscan-swift/auth.yaml +59 -0
- package/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- package/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- package/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- package/core/rules/mobsfscan-swift/logging.yaml +23 -0
- package/core/rules/mobsfscan-swift/network.yaml +55 -0
- package/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- package/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- package/core/rules/mobsfscan-swift/storage.yaml +29 -0
- package/core/rules/mobsfscan-swift/webview.yaml +32 -0
- package/core/runtime/README.md +198 -0
- package/core/runtime/__init__.py +3 -0
- package/core/runtime/bugx_logging.py +1393 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +449 -0
- package/core/runtime/global_telemetry.py +549 -0
- package/core/runtime/incident_eval.py +148 -0
- package/core/runtime/interaction.py +605 -0
- package/core/runtime/interaction_store.py +435 -0
- package/core/runtime/interactive_menu.py +95 -0
- package/core/runtime/log_analytics.py +922 -0
- package/core/runtime/mining_quality_framework.py +1387 -0
- package/core/runtime/model_runner.py +769 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +476 -0
- package/core/runtime/project_graph.py +827 -0
- package/core/runtime/project_init.py +481 -0
- package/core/runtime/project_profile.py +224 -0
- package/core/runtime/project_settings.py +963 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +814 -0
- package/core/runtime/seed_drill.py +549 -0
- package/core/runtime/self_audit.py +550 -0
- package/core/runtime/session_profile.py +205 -0
- package/core/runtime/setup_ui_env.py +229 -0
- package/core/runtime/startup_environment.py +859 -0
- package/core/runtime/sync_store.py +1421 -0
- package/core/runtime/tool_install_targets.py +18 -0
- package/core/schemas/README.md +35 -0
- package/core/schemas/agent-graph.schema.json +368 -0
- package/core/schemas/attack-graph.schema.json +88 -0
- package/core/schemas/evidence-bundle.schema.json +33 -0
- package/core/schemas/skill-pack.schema.json +230 -0
- package/core/schemas/worker-checkpoint.schema.json +119 -0
- package/core/secure_atomic.py +289 -0
- package/core/seed_corpus/README.md +55 -0
- package/core/seed_corpus/c.txt +29 -0
- package/core/seed_corpus/cpp.txt +32 -0
- package/core/seed_corpus/css.txt +70 -0
- package/core/seed_corpus/go.txt +46 -0
- package/core/seed_corpus/java.txt +30 -0
- package/core/seed_corpus/javascript.txt +55 -0
- package/core/seed_corpus/kotlin.txt +28 -0
- package/core/seed_corpus/python.txt +71 -0
- package/core/seed_corpus/rust.txt +53 -0
- package/core/seed_corpus/swift.txt +29 -0
- package/core/seed_corpus/typescript.txt +29 -0
- package/core/skills/README.md +53 -0
- package/core/skills/__init__.py +189 -0
- package/core/skills/bugx_docs_mcp_server.py +416 -0
- package/core/skills/bugx_mcp_server.py +1134 -0
- package/core/skills/mcp_runtime.py +968 -0
- package/core/skills/mcp_session_proof.py +605 -0
- package/core/skills/mobile_ui_inspector.py +405 -0
- package/core/skills/skill_pack.py +1214 -0
- package/core/skills/skill_synthesizer.py +1153 -0
- package/core/skills/tools_kb.py +313 -0
- package/core/supervisor/INTERFACE.md +121 -0
- package/core/supervisor/README.md +209 -0
- package/core/supervisor/SPEC.md +25 -0
- package/core/supervisor/__init__.py +175 -0
- package/core/supervisor/audit_supervisor.py +1015 -0
- package/core/supervisor/budget_governor.py +760 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1322 -0
- package/core/supervisor/checkpoint_sync.py +640 -0
- package/core/supervisor/claim_events.py +74 -0
- package/core/supervisor/claim_sync.py +590 -0
- package/core/supervisor/cli.py +812 -0
- package/core/supervisor/context_sync.py +55 -0
- package/core/supervisor/coverage_sync.py +115 -0
- package/core/supervisor/finding_commit.py +470 -0
- package/core/supervisor/finding_sync.py +688 -0
- package/core/supervisor/finding_workflow.py +659 -0
- package/core/supervisor/finish_policy.py +224 -0
- package/core/supervisor/finish_sync.py +185 -0
- package/core/supervisor/graph_sync.py +669 -0
- package/core/supervisor/lease_manager.py +788 -0
- package/core/supervisor/lifecycle_blocks.py +124 -0
- package/core/supervisor/next_round_sync.py +126 -0
- package/core/supervisor/observability.py +140 -0
- package/core/supervisor/recovery_sync.py +165 -0
- package/core/supervisor/rejection_remedies.py +308 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +500 -0
- package/core/supervisor/start_sync.py +87 -0
- package/core/supervisor/state_store.py +249 -0
- package/core/supervisor/supervisor_host.py +511 -0
- package/core/supervisor/supervisor_models.py +1143 -0
- package/core/supervisor/systemic_failure.py +104 -0
- package/core/supervisor/task_scheduler.py +1640 -0
- package/core/supervisor/worker_checkpoint.py +223 -0
- package/core/supervisor/worker_execution.py +265 -0
- package/core/supervisor/worker_handoff.py +192 -0
- package/core/supervisor/worker_lifecycle.py +396 -0
- package/core/supervisor/worker_runtime.py +999 -0
- package/core/supervisor/worker_sync.py +89 -0
- package/core/supervisor_types/README.md +36 -0
- package/core/supervisor_types/__init__.py +0 -0
- package/core/supervisor_types/exceptions.py +52 -0
- package/core/supervisor_types/graph_models.py +357 -0
- package/core/supervisor_types/path_containment.py +151 -0
- package/core/supervisor_types/target_fingerprint.py +310 -0
- package/core/supervisor_types/worker_claim.py +402 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +25 -0
- package/core/webui/__init__.py +11 -0
- package/core/webui/adapters/__init__.py +27 -0
- package/core/webui/adapters/base.py +87 -0
- package/core/webui/adapters/bugx.py +102 -0
- package/core/webui/adapters/claude.py +218 -0
- package/core/webui/adapters/cline.py +399 -0
- package/core/webui/adapters/codex.py +256 -0
- package/core/webui/adapters/dsh.py +173 -0
- package/core/webui/adapters/opencode.py +218 -0
- package/core/webui/adapters/pi.py +272 -0
- package/core/webui/adapters/registry.py +100 -0
- package/core/webui/adapters/zcode.py +312 -0
- package/core/webui/api_routes_post.py +668 -0
- package/core/webui/dispatcher.py +1376 -0
- package/core/webui/docs_session_service.py +473 -0
- package/core/webui/handler.py +674 -0
- package/core/webui/ide_cloud_service.py +526 -0
- package/core/webui/mcp_inspector.py +1743 -0
- package/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- package/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- package/core/webui/static/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +42 -0
- package/core/webui/static/manifest.webmanifest +19 -0
- package/core/webui/static/project-settings.css +6458 -0
- package/core/webui/static/project-settings.js +9602 -0
- package/core/webui/static/sw.js +8 -0
- package/core/webui/workspace_service.py +218 -0
- package/docs/07_distribution/01_README_NPM.md +281 -0
- package/docs/07_distribution/README.md +16 -0
- package/docs/README.md +121 -0
- package/ecosystem/README.md +129 -0
- package/ecosystem/integrations/README.md +38 -0
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/dsh/agents/bugx.md +27 -0
- package/ecosystem/integrations/dsh/dsh-patch.yml +18 -0
- package/ecosystem/integrations/dsh/mcp/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/mcp/index.js +219 -0
- package/ecosystem/integrations/dsh/mcp/package.json +28 -0
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +70 -0
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/integrations/dsh/ui/client.js +87 -0
- package/ecosystem/integrations/dsh/ui/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/ui/index.js +7 -0
- package/ecosystem/integrations/dsh/ui/package.json +27 -0
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +53 -0
- package/ecosystem/integrations/opencode/mcp-lock.json +3067 -0
- package/ecosystem/integrations/opencode/opencode.json +118 -0
- package/ecosystem/integrations/pi/extensions/bugx/README.md +12 -0
- package/ecosystem/integrations/pi/extensions/bugx/index.ts +299 -0
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +11 -0
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/qoder/CONNECTORS.md +54 -0
- package/ecosystem/integrations/qoder/connector-meta.json +21 -0
- package/ecosystem/integrations/workbuddy/connector-meta.json +19 -0
- package/ecosystem/integrations/workbuddy/icon.png +0 -0
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +70 -0
- package/ecosystem/plugins/README.md +37 -0
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +17 -0
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +16 -0
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +41 -0
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +19 -0
- package/ecosystem/plugins/bugx/agents/bugx-judge.md +71 -0
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +31 -0
- package/ecosystem/plugins/bugx/agents/bugx.md +74 -0
- package/ecosystem/plugins/bugx/assets/bugx-avatar-512.png +0 -0
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +118 -0
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- package/interfaces/README.md +143 -0
- package/interfaces/bin/README.md +35 -0
- package/interfaces/bin/bugx.js +80 -0
- package/interfaces/cli/README.md +90 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/cli.py +1678 -0
- package/interfaces/cli/bugx_cli/commands/__init__.py +1 -0
- package/interfaces/cli/bugx_cli/commands/advisory.py +94 -0
- package/interfaces/cli/bugx_cli/commands/agent.py +3944 -0
- package/interfaces/cli/bugx_cli/commands/audit.py +632 -0
- package/interfaces/cli/bugx_cli/commands/autonomous.py +260 -0
- package/interfaces/cli/bugx_cli/commands/cloud.py +1370 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1345 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +244 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +617 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +2763 -0
- package/interfaces/cli/bugx_cli/commands/patch.py +1014 -0
- package/interfaces/cli/bugx_cli/commands/plugin.py +2714 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +1446 -0
- package/interfaces/cli/bugx_cli/commands/plugin_cline.py +269 -0
- package/interfaces/cli/bugx_cli/commands/plugin_codex.py +74 -0
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +728 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +216 -0
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +710 -0
- package/interfaces/cli/bugx_cli/commands/project.py +670 -0
- package/interfaces/cli/bugx_cli/commands/report.py +260 -0
- package/interfaces/cli/bugx_cli/commands/skill.py +251 -0
- package/interfaces/cli/bugx_cli/commands/stats.py +133 -0
- package/interfaces/cli/bugx_cli/commands/system.py +2567 -0
- package/interfaces/cli/bugx_cli/common.py +898 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1917 -0
- package/interfaces/cli/bugx_cli/hosts/__init__.py +80 -0
- package/interfaces/cli/bugx_cli/hosts/base.py +99 -0
- package/interfaces/cli/bugx_cli/hosts/registry.py +571 -0
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +188 -0
- package/interfaces/cli/bugx_cli/infra/__init__.py +209 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +721 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1937 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +545 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +755 -0
- package/interfaces/cli/bugx_cli/infra/security.py +332 -0
- package/package.json +98 -4
- package/pyproject.toml +246 -0
- package/scripts/README.md +118 -0
- package/scripts/ensure-python.mjs +97 -0
- package/scripts/isolate-npm-readme.mjs +40 -0
- package/scripts/runtime.lock.json +31 -0
- package/scripts/sync-version.mjs +37 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""core/sast_rules.py — 跨语言声明式安全规则库与 Schema 定义 (DOC-061)。
|
|
3
|
+
|
|
4
|
+
支持统一的规则模型,同一漏洞规则(CWE/OWASP)可在多语言(Python, Go, Java,
|
|
5
|
+
JavaScript, TypeScript, C/C++, Rust, PHP)下定义特定的危险模式(Sinks)
|
|
6
|
+
与净化器(Sanitizers)。
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import ast
|
|
12
|
+
import re
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from core.retrieval.universal_code_matcher import CallNode, ParsedSource, UniversalCodeMatcher
|
|
18
|
+
|
|
19
|
+
from core.planning.dynamic_flow_analyzer import DynamicFlowAnalyzer, STRONG_SANITIZERS
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class LanguageRuleSpec:
|
|
24
|
+
"""针对特定语言的规则特征匹配契约"""
|
|
25
|
+
callee_patterns: list[str] = field(default_factory=list) # 危险函数调用正则列表
|
|
26
|
+
require_string_concat: bool = False # 是否必须伴随实参动态字符串拼接
|
|
27
|
+
arg_patterns: list[str] = field(default_factory=list) # 实参中必须命中的特征正则
|
|
28
|
+
sanitizer_patterns: list[str] = field(default_factory=list) # 净化器过滤正则(命中则抵消告警)
|
|
29
|
+
line_patterns: list[str] = field(default_factory=list) # 行级特征正则(如弱类型比较运算符)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class SASTRule:
|
|
34
|
+
id: str
|
|
35
|
+
name: str
|
|
36
|
+
category: str
|
|
37
|
+
severity: str # critical, high, medium, low
|
|
38
|
+
confidence: str # high, medium, low
|
|
39
|
+
cwe: str # e.g. CWE-78, CWE-89
|
|
40
|
+
owasp: str # e.g. A03:2021-Injection
|
|
41
|
+
message: str
|
|
42
|
+
remediation: str
|
|
43
|
+
languages: dict[str, LanguageRuleSpec] = field(default_factory=dict)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# 内置核心高危规则库 (OWASP Top 10 多语言全谱系)
|
|
47
|
+
BUILTIN_RULES: list[SASTRule] = [
|
|
48
|
+
# 1. 操作系统命令注入 (CWE-78)
|
|
49
|
+
SASTRule(
|
|
50
|
+
id="SEC-CMD-001",
|
|
51
|
+
name="OS Command Injection",
|
|
52
|
+
category="command-injection",
|
|
53
|
+
severity="critical",
|
|
54
|
+
confidence="high",
|
|
55
|
+
cwe="CWE-78",
|
|
56
|
+
owasp="A03:2021-Injection",
|
|
57
|
+
message="调用命令执行函数且可能伴随未转义参数或 shell 解析,存在命令注入风险",
|
|
58
|
+
remediation="避免将外部不可信数据拼接入命令;改用参数数组列表形式调用,禁用 shell 解析。",
|
|
59
|
+
languages={
|
|
60
|
+
"python": LanguageRuleSpec(
|
|
61
|
+
callee_patterns=[r"^os\.(system|popen)$", r"^subprocess\.(run|Popen|call|check_call|check_output)$"],
|
|
62
|
+
arg_patterns=[r"shell\s*=\s*True", r"^os\.(system|popen)"],
|
|
63
|
+
sanitizer_patterns=[r"shlex\.quote\("],
|
|
64
|
+
),
|
|
65
|
+
"go": LanguageRuleSpec(
|
|
66
|
+
callee_patterns=[r"^exec\.Command(Context)?$"],
|
|
67
|
+
arg_patterns=[r'("sh"|"bash"|"cmd\.exe")\s*,\s*("-c"|"/c")'],
|
|
68
|
+
require_string_concat=True,
|
|
69
|
+
),
|
|
70
|
+
"java": LanguageRuleSpec(
|
|
71
|
+
callee_patterns=[r"^(Runtime\.getRuntime\(\)\.exec|ProcessBuilder)$"],
|
|
72
|
+
require_string_concat=True,
|
|
73
|
+
),
|
|
74
|
+
"javascript": LanguageRuleSpec(
|
|
75
|
+
callee_patterns=[r"^(child_process\.)?(exec|execSync)$"],
|
|
76
|
+
sanitizer_patterns=[r"execFile"],
|
|
77
|
+
),
|
|
78
|
+
"typescript": LanguageRuleSpec(
|
|
79
|
+
callee_patterns=[r"^(child_process\.)?(exec|execSync)$"],
|
|
80
|
+
sanitizer_patterns=[r"execFile"],
|
|
81
|
+
),
|
|
82
|
+
"php": LanguageRuleSpec(
|
|
83
|
+
callee_patterns=[r"^(system|exec|passthru|shell_exec|popen)$"],
|
|
84
|
+
sanitizer_patterns=[r"escapeshellarg", r"escapeshellcmd"],
|
|
85
|
+
),
|
|
86
|
+
"c": LanguageRuleSpec(
|
|
87
|
+
callee_patterns=[r"^(system|popen)$"],
|
|
88
|
+
),
|
|
89
|
+
"cpp": LanguageRuleSpec(
|
|
90
|
+
callee_patterns=[r"^(system|popen)$"],
|
|
91
|
+
),
|
|
92
|
+
"csharp": LanguageRuleSpec(
|
|
93
|
+
callee_patterns=[r"^(System\.Diagnostics\.)?Process\.Start$"],
|
|
94
|
+
arg_patterns=[r"\b(cmd|powershell|bash|sh|/c|-Command)\b", r"\b(input|request|query|args|command)\b"],
|
|
95
|
+
sanitizer_patterns=[r"\bArgumentList\b", r"\bRegex\.Escape\("],
|
|
96
|
+
),
|
|
97
|
+
"kotlin": LanguageRuleSpec(
|
|
98
|
+
callee_patterns=[r"^(ProcessBuilder|Runtime\.getRuntime|exec)$"],
|
|
99
|
+
arg_patterns=[r"\b(sh|bash|cmd\.exe|-c|/c)\b", r"\b(input|request|query|params|command)\b"],
|
|
100
|
+
sanitizer_patterns=[r"\bProcessBuilder\s*\([^)]*\bcommandList\b", r"\bShellwords\b"],
|
|
101
|
+
),
|
|
102
|
+
"swift": LanguageRuleSpec(
|
|
103
|
+
callee_patterns=[r"^(Process|Foundation\.Process)\.run$"],
|
|
104
|
+
arg_patterns=[r"/bin/(sh|bash)\b", r"\b(input|request|query|command)\b"],
|
|
105
|
+
sanitizer_patterns=[r"\barguments\s*:\s*\[\s*\"[^\"]+\"\s*\]"],
|
|
106
|
+
),
|
|
107
|
+
"ruby": LanguageRuleSpec(
|
|
108
|
+
callee_patterns=[r"^(system|exec|spawn|IO\.popen|Open3\.(capture\d*|pipeline))$"],
|
|
109
|
+
arg_patterns=[r"\b(params|request|input|ENV|command)\b"],
|
|
110
|
+
sanitizer_patterns=[r"\bShellwords\.escape\("],
|
|
111
|
+
),
|
|
112
|
+
}
|
|
113
|
+
),
|
|
114
|
+
|
|
115
|
+
# 2. SQL 字符串动态拼接注入 (CWE-89)
|
|
116
|
+
SASTRule(
|
|
117
|
+
id="SEC-SQLI-001",
|
|
118
|
+
name="SQL Injection via String Concatenation",
|
|
119
|
+
category="sql-injection",
|
|
120
|
+
severity="critical",
|
|
121
|
+
confidence="high",
|
|
122
|
+
cwe="CWE-89",
|
|
123
|
+
owasp="A03:2021-Injection",
|
|
124
|
+
message="SQL 查询执行语句使用动态字符串格式化或拼接构造,存在直接 SQL 注入风险",
|
|
125
|
+
remediation="严格改用预编译参数化占位符(Parameterized Prepared Statements),禁止字符串拼接查询语句。",
|
|
126
|
+
languages={
|
|
127
|
+
"python": LanguageRuleSpec(
|
|
128
|
+
callee_patterns=[r"^(cursor|db|conn|session)\.(execute|raw|select|query)$"],
|
|
129
|
+
require_string_concat=True,
|
|
130
|
+
sanitizer_patterns=[r"parametrize", r"placeholder"],
|
|
131
|
+
),
|
|
132
|
+
"go": LanguageRuleSpec(
|
|
133
|
+
callee_patterns=[r"^(db|tx|stmt|conn)\.(Query|QueryRow|Exec|QueryContext|ExecContext)$"],
|
|
134
|
+
require_string_concat=True,
|
|
135
|
+
arg_patterns=[r'(\+\s*["\']|["\']\s*\+|\bfmt\.Sprintf\b)'],
|
|
136
|
+
),
|
|
137
|
+
"java": LanguageRuleSpec(
|
|
138
|
+
callee_patterns=[r"^(Statement|stmt|statement)\.(executeQuery|executeUpdate|execute)$"],
|
|
139
|
+
require_string_concat=True,
|
|
140
|
+
arg_patterns=[r'\+\s*[A-Za-z_]'],
|
|
141
|
+
),
|
|
142
|
+
"javascript": LanguageRuleSpec(
|
|
143
|
+
callee_patterns=[r"^(db|pool|client|connection)\.(query|execute)$"],
|
|
144
|
+
require_string_concat=True,
|
|
145
|
+
arg_patterns=[r'(`[^`]*\${|\+\s*[A-Za-z_])'],
|
|
146
|
+
),
|
|
147
|
+
"typescript": LanguageRuleSpec(
|
|
148
|
+
callee_patterns=[r"^(db|pool|client|connection)\.(query|execute)$"],
|
|
149
|
+
require_string_concat=True,
|
|
150
|
+
arg_patterns=[r'(`[^`]*\${|\+\s*[A-Za-z_])'],
|
|
151
|
+
),
|
|
152
|
+
"php": LanguageRuleSpec(
|
|
153
|
+
callee_patterns=[r"^(mysqli_query|mysql_query|\$db->query|\$pdo->query)$"],
|
|
154
|
+
require_string_concat=True,
|
|
155
|
+
),
|
|
156
|
+
"csharp": LanguageRuleSpec(
|
|
157
|
+
callee_patterns=[r"^(SqlCommand|System\.Data\.SqlClient\.SqlCommand|.*\.Execute(Reader|NonQuery|Scalar))$"],
|
|
158
|
+
require_string_concat=True,
|
|
159
|
+
arg_patterns=[r"\+\s*[A-Za-z_]", r"\b(SELECT|INSERT|UPDATE|DELETE)\b"],
|
|
160
|
+
sanitizer_patterns=[r"\bParameters\.Add\("],
|
|
161
|
+
),
|
|
162
|
+
"kotlin": LanguageRuleSpec(
|
|
163
|
+
callee_patterns=[r"^(Statement\.(executeQuery|executeUpdate|execute)|JdbcTemplate\.(query|update)|SQLiteDatabase\.(rawQuery|execSQL))$"],
|
|
164
|
+
require_string_concat=True,
|
|
165
|
+
arg_patterns=[r"\+\s*[A-Za-z_]", r"\b(SELECT|INSERT|UPDATE|DELETE)\b"],
|
|
166
|
+
sanitizer_patterns=[r"\b(selectionArgs|arrayOf)\b", r"\?"],
|
|
167
|
+
),
|
|
168
|
+
"swift": LanguageRuleSpec(
|
|
169
|
+
callee_patterns=[r"^(SQLiteConnection|Database|statement|connection)\.execute$"],
|
|
170
|
+
require_string_concat=True,
|
|
171
|
+
arg_patterns=[r"\+\s*[A-Za-z_]", r"\b(SELECT|INSERT|UPDATE|DELETE)\b"],
|
|
172
|
+
sanitizer_patterns=[r"\b(bind|bindValue|parameters)\b", r"\?"],
|
|
173
|
+
),
|
|
174
|
+
"ruby": LanguageRuleSpec(
|
|
175
|
+
callee_patterns=[r"^(db\.execute|find_by_sql)$"],
|
|
176
|
+
require_string_concat=True,
|
|
177
|
+
arg_patterns=[r"\+\s*[A-Za-z_]", r"\b(SELECT|INSERT|UPDATE|DELETE)\b"],
|
|
178
|
+
sanitizer_patterns=[r"\bsanitize_sql(?:_array|_for_conditions)?\b"],
|
|
179
|
+
),
|
|
180
|
+
}
|
|
181
|
+
),
|
|
182
|
+
|
|
183
|
+
# 3. 动态代码执行 / Eval 注入 (CWE-95)
|
|
184
|
+
SASTRule(
|
|
185
|
+
id="SEC-EVAL-001",
|
|
186
|
+
name="Dangerous Dynamic Code Execution",
|
|
187
|
+
category="code-injection",
|
|
188
|
+
severity="critical",
|
|
189
|
+
confidence="medium",
|
|
190
|
+
cwe="CWE-95",
|
|
191
|
+
owasp="A03:2021-Injection",
|
|
192
|
+
message="直接使用 eval / exec 动态执行代码字符串,攻击者可利用输入实现任意代码执行",
|
|
193
|
+
remediation="彻底移除 eval/exec 调用;解析结构化数据请改用 JSON 或安全字面量解析工具。",
|
|
194
|
+
languages={
|
|
195
|
+
"python": LanguageRuleSpec(
|
|
196
|
+
callee_patterns=[r"^(eval|exec)$"],
|
|
197
|
+
sanitizer_patterns=[r"ast\.literal_eval"],
|
|
198
|
+
),
|
|
199
|
+
"javascript": LanguageRuleSpec(
|
|
200
|
+
callee_patterns=[r"^(eval|Function)$"],
|
|
201
|
+
),
|
|
202
|
+
"typescript": LanguageRuleSpec(
|
|
203
|
+
callee_patterns=[r"^(eval|Function)$"],
|
|
204
|
+
),
|
|
205
|
+
"php": LanguageRuleSpec(
|
|
206
|
+
callee_patterns=[r"^(eval|assert)$"],
|
|
207
|
+
),
|
|
208
|
+
"csharp": LanguageRuleSpec(
|
|
209
|
+
callee_patterns=[r"^(CSharpScript\.Evaluate(?:Async)?|Microsoft\.CodeAnalysis\.CSharp\.Scripting\.CSharpScript\.EvaluateAsync)$"],
|
|
210
|
+
arg_patterns=[r"\b(input|request|body|query|expression)\b"],
|
|
211
|
+
sanitizer_patterns=[r"\b(ALLOWED|allowlist|SyntaxTree)\b"],
|
|
212
|
+
),
|
|
213
|
+
"kotlin": LanguageRuleSpec(
|
|
214
|
+
callee_patterns=[r"^(ScriptEngine|engine)\.eval$", r"^eval$"],
|
|
215
|
+
arg_patterns=[r"\b(input|request|body|query|params|expression)\b"],
|
|
216
|
+
sanitizer_patterns=[r"\b(ALLOWED|allowlist|SAFE_EXPRESSIONS)\b"],
|
|
217
|
+
),
|
|
218
|
+
"swift": LanguageRuleSpec(
|
|
219
|
+
callee_patterns=[r"^(?:[A-Za-z_][A-Za-z0-9_]*\.)?evaluateScript$"],
|
|
220
|
+
arg_patterns=[r"\b(input|request|body|query|expression)\b"],
|
|
221
|
+
sanitizer_patterns=[r"\b(ALLOWED|allowlist|safeExpression)\b"],
|
|
222
|
+
),
|
|
223
|
+
"ruby": LanguageRuleSpec(
|
|
224
|
+
callee_patterns=[r"^(eval|instance_eval|class_eval|module_eval|ERB\.new)$"],
|
|
225
|
+
arg_patterns=[r"\b(params|request|input|ENV|expression)\b"],
|
|
226
|
+
sanitizer_patterns=[r"\b(ALLOWED|allowlist|ERB::Util)\b"],
|
|
227
|
+
),
|
|
228
|
+
}
|
|
229
|
+
),
|
|
230
|
+
|
|
231
|
+
# 4. 不安全的反序列化 (CWE-502)
|
|
232
|
+
SASTRule(
|
|
233
|
+
id="SEC-DESER-001",
|
|
234
|
+
name="Insecure Deserialization",
|
|
235
|
+
category="deserialization",
|
|
236
|
+
severity="critical",
|
|
237
|
+
confidence="high",
|
|
238
|
+
cwe="CWE-502",
|
|
239
|
+
owasp="A08:2021-Software-and-Data-Integrity-Failures",
|
|
240
|
+
message="对未受信任的数据流执行对象反序列化,可导致任意对象实例化与远程代码执行",
|
|
241
|
+
remediation="禁止反序列化外部不可信数据;采用结构化数据传输协议(如 JSON、Protocol Buffers)并加签防篡改。",
|
|
242
|
+
languages={
|
|
243
|
+
"python": LanguageRuleSpec(
|
|
244
|
+
callee_patterns=[r"^(pickle|_pickle|cPickle|marshal)\.(load|loads)$"],
|
|
245
|
+
),
|
|
246
|
+
"java": LanguageRuleSpec(
|
|
247
|
+
callee_patterns=[r"^(ObjectInputStream\.readObject|XMLDecoder\.readObject)$"],
|
|
248
|
+
),
|
|
249
|
+
"javascript": LanguageRuleSpec(
|
|
250
|
+
callee_patterns=[r"^(node-serialize|serialize-to-js)\.(unserialize)$"],
|
|
251
|
+
),
|
|
252
|
+
"php": LanguageRuleSpec(
|
|
253
|
+
callee_patterns=[r"^(unserialize)$"],
|
|
254
|
+
),
|
|
255
|
+
"csharp": LanguageRuleSpec(
|
|
256
|
+
callee_patterns=[r"^(BinaryFormatter\.Deserialize|JsonConvert\.DeserializeObject|JavaScriptSerializer\.DeserializeObject)$"],
|
|
257
|
+
arg_patterns=[r"\b(input|request|body|stream|payload)\b"],
|
|
258
|
+
sanitizer_patterns=[r"\b(TypeNameHandling\.None|SafeMode|Binder)\b"],
|
|
259
|
+
),
|
|
260
|
+
"kotlin": LanguageRuleSpec(
|
|
261
|
+
callee_patterns=[r"^(ObjectInputStream\.readObject|Kryo\.readClassAndObject|Yaml\.load)$"],
|
|
262
|
+
arg_patterns=[r"\b(input|request|body|stream|payload)\b"],
|
|
263
|
+
sanitizer_patterns=[r"\b(SafeLoader|ClassWhitelist|allowList)\b"],
|
|
264
|
+
),
|
|
265
|
+
"swift": LanguageRuleSpec(
|
|
266
|
+
callee_patterns=[r"^NSKeyedUnarchiver\.(unarchiveObject|unarchiveTopLevelObjectWithData)$", r"^JSONSerialization\.jsonObject$"],
|
|
267
|
+
arg_patterns=[r"\b(data|payload|input|request)\b"],
|
|
268
|
+
sanitizer_patterns=[r"\b(requiresSecureCoding|allowedClasses|decodeIfPresent)\b"],
|
|
269
|
+
),
|
|
270
|
+
"ruby": LanguageRuleSpec(
|
|
271
|
+
callee_patterns=[r"^(Marshal\.load|YAML\.load|Psych\.load)$"],
|
|
272
|
+
arg_patterns=[r"\b(params|request|payload|input|ENV)\b"],
|
|
273
|
+
sanitizer_patterns=[r"\b(safe_load|permitted_classes|aliases\s*:\s*false)\b"],
|
|
274
|
+
),
|
|
275
|
+
}
|
|
276
|
+
),
|
|
277
|
+
|
|
278
|
+
# 5. 路径穿越与任意文件读写 (CWE-22)
|
|
279
|
+
SASTRule(
|
|
280
|
+
id="SEC-PATH-001",
|
|
281
|
+
name="Path Traversal / Arbitrary File Access",
|
|
282
|
+
category="path-traversal",
|
|
283
|
+
severity="high",
|
|
284
|
+
confidence="medium",
|
|
285
|
+
cwe="CWE-22",
|
|
286
|
+
owasp="A01:2021-Broken-Access-Control",
|
|
287
|
+
message="直接将未经过滤的外部路径参数拼接入文件系统 I/O 函数,存在路径穿越风险",
|
|
288
|
+
remediation="使用路径规范化函数处理路径,校验目标绝对路径必须落在预期白名单安全目录内。",
|
|
289
|
+
languages={
|
|
290
|
+
"python": LanguageRuleSpec(
|
|
291
|
+
callee_patterns=[r"^(open|os\.open|os\.remove|os\.unlink)$"],
|
|
292
|
+
require_string_concat=True,
|
|
293
|
+
sanitizer_patterns=[r"os\.path\.abspath", r"Path\.resolve"],
|
|
294
|
+
),
|
|
295
|
+
"go": LanguageRuleSpec(
|
|
296
|
+
callee_patterns=[r"^(os\.Open|os\.ReadFile|os\.Create|ioutil\.ReadFile)$"],
|
|
297
|
+
require_string_concat=True,
|
|
298
|
+
sanitizer_patterns=[r"filepath\.Clean"],
|
|
299
|
+
),
|
|
300
|
+
"java": LanguageRuleSpec(
|
|
301
|
+
callee_patterns=[r"^(new FileInputStream|new FileOutputStream|Files\.readAllBytes|Files\.write)$"],
|
|
302
|
+
require_string_concat=True,
|
|
303
|
+
sanitizer_patterns=[r"getCanonicalPath", r"normalize\(\)"],
|
|
304
|
+
),
|
|
305
|
+
"javascript": LanguageRuleSpec(
|
|
306
|
+
callee_patterns=[r"^(fs\.)?(readFile|readFileSync|createReadStream|unlink|unlinkSync)$"],
|
|
307
|
+
require_string_concat=True,
|
|
308
|
+
sanitizer_patterns=[r"path\.resolve", r"path\.normalize"],
|
|
309
|
+
),
|
|
310
|
+
"typescript": LanguageRuleSpec(
|
|
311
|
+
callee_patterns=[r"^(fs\.)?(readFile|readFileSync|createReadStream|unlink|unlinkSync)$"],
|
|
312
|
+
require_string_concat=True,
|
|
313
|
+
sanitizer_patterns=[r"path\.resolve", r"path\.normalize"],
|
|
314
|
+
),
|
|
315
|
+
"csharp": LanguageRuleSpec(
|
|
316
|
+
callee_patterns=[r"^(File\.(ReadAllText|OpenRead|WriteAllText|Delete)|System\.IO\.File\.(ReadAllText|OpenRead|WriteAllText|Delete))$"],
|
|
317
|
+
require_string_concat=True,
|
|
318
|
+
sanitizer_patterns=[r"\bPath\.Get(?:FullPath|FileName|RelativePath)\("],
|
|
319
|
+
),
|
|
320
|
+
"kotlin": LanguageRuleSpec(
|
|
321
|
+
callee_patterns=[r"^(File|java\.io\.File|Files\.(readString|readAllBytes|write|deleteIfExists)|Paths\.get)$"],
|
|
322
|
+
require_string_concat=True,
|
|
323
|
+
sanitizer_patterns=[r"\b(canonical(File|Path)|normalize|toRealPath)\b"],
|
|
324
|
+
),
|
|
325
|
+
"swift": LanguageRuleSpec(
|
|
326
|
+
callee_patterns=[r"^(String|FileManager\.default\.(contents|removeItem|copyItem|moveItem))$"],
|
|
327
|
+
require_string_concat=True,
|
|
328
|
+
sanitizer_patterns=[r"\b(standardizedFileURL|resolvingSymlinksInPath|lastPathComponent)\b"],
|
|
329
|
+
),
|
|
330
|
+
"ruby": LanguageRuleSpec(
|
|
331
|
+
callee_patterns=[r"^(File\.(read|open|delete)|Pathname\.new)$"],
|
|
332
|
+
require_string_concat=True,
|
|
333
|
+
sanitizer_patterns=[r"\b(File\.expand_path|File\.basename|cleanpath)\b"],
|
|
334
|
+
),
|
|
335
|
+
}
|
|
336
|
+
),
|
|
337
|
+
|
|
338
|
+
# 6. 服务端请求伪造 SSRF (CWE-918)
|
|
339
|
+
SASTRule(
|
|
340
|
+
id="SEC-SSRF-001",
|
|
341
|
+
name="Server-Side Request Forgery",
|
|
342
|
+
category="ssrf",
|
|
343
|
+
severity="high",
|
|
344
|
+
confidence="medium",
|
|
345
|
+
cwe="CWE-918",
|
|
346
|
+
owasp="A10:2021-Server-Side-Request-Forgery",
|
|
347
|
+
message="向外部动态提供的 URL 发起 HTTP/网络请求,可能导致内网端口探测与元数据服务暴露",
|
|
348
|
+
remediation="对目标 URL 实施严格白名单域名与协议校验,阻断向 127.0.0.1/169.254.169.254 等私有内网段的请求。",
|
|
349
|
+
languages={
|
|
350
|
+
"python": LanguageRuleSpec(
|
|
351
|
+
callee_patterns=[r"^(requests\.(get|post|put|delete)|urllib\.request\.urlopen|httpx\.(get|post))$"],
|
|
352
|
+
require_string_concat=True,
|
|
353
|
+
),
|
|
354
|
+
"go": LanguageRuleSpec(
|
|
355
|
+
callee_patterns=[r"^(http\.(Get|Post|Head)|http\.NewRequest)$"],
|
|
356
|
+
require_string_concat=True,
|
|
357
|
+
),
|
|
358
|
+
"java": LanguageRuleSpec(
|
|
359
|
+
callee_patterns=[r"^(new URL|HttpClient\.send|HttpClients\.createDefault)$"],
|
|
360
|
+
require_string_concat=True,
|
|
361
|
+
),
|
|
362
|
+
"javascript": LanguageRuleSpec(
|
|
363
|
+
callee_patterns=[r"^(axios\.(get|post)|fetch|http\.(get|request)|https\.(get|request))$"],
|
|
364
|
+
require_string_concat=True,
|
|
365
|
+
),
|
|
366
|
+
"typescript": LanguageRuleSpec(
|
|
367
|
+
callee_patterns=[r"^(axios\.(get|post)|fetch|http\.(get|request)|https\.(get|request))$"],
|
|
368
|
+
require_string_concat=True,
|
|
369
|
+
),
|
|
370
|
+
}
|
|
371
|
+
),
|
|
372
|
+
|
|
373
|
+
# 7. 弱加密算法与散列碰撞 (CWE-327)
|
|
374
|
+
SASTRule(
|
|
375
|
+
id="SEC-CRYPTO-001",
|
|
376
|
+
name="Use of Broken or Weak Cryptographic Hash",
|
|
377
|
+
category="weak-crypto",
|
|
378
|
+
severity="medium",
|
|
379
|
+
confidence="high",
|
|
380
|
+
cwe="CWE-327",
|
|
381
|
+
owasp="A02:2021-Cryptographic-Failures",
|
|
382
|
+
message="使用了已证实存在碰撞或破损的弱哈希算法(如 MD5 / SHA1),不可用于安全散列或签名",
|
|
383
|
+
remediation="改用 SHA-256、SHA-3 或安全密码散列算法(如 Argon2id、bcrypt、PBKDF2)。",
|
|
384
|
+
languages={
|
|
385
|
+
"python": LanguageRuleSpec(
|
|
386
|
+
callee_patterns=[r"^hashlib\.(md5|sha1)$"],
|
|
387
|
+
),
|
|
388
|
+
"go": LanguageRuleSpec(
|
|
389
|
+
callee_patterns=[r"^(md5\.New|sha1\.New|md5\.Sum|sha1\.Sum)$"],
|
|
390
|
+
),
|
|
391
|
+
"java": LanguageRuleSpec(
|
|
392
|
+
callee_patterns=[r"^MessageDigest\.getInstance$"],
|
|
393
|
+
arg_patterns=[r'["\'](MD5|SHA-1|SHA1)["\']'],
|
|
394
|
+
),
|
|
395
|
+
"javascript": LanguageRuleSpec(
|
|
396
|
+
callee_patterns=[r"^crypto\.createHash$"],
|
|
397
|
+
arg_patterns=[r'["\'](md5|sha1)["\']'],
|
|
398
|
+
),
|
|
399
|
+
"typescript": LanguageRuleSpec(
|
|
400
|
+
callee_patterns=[r"^crypto\.createHash$"],
|
|
401
|
+
arg_patterns=[r'["\'](md5|sha1)["\']'],
|
|
402
|
+
),
|
|
403
|
+
}
|
|
404
|
+
),
|
|
405
|
+
|
|
406
|
+
# 8. 不安全的临时文件创建竞态 (CWE-377)
|
|
407
|
+
SASTRule(
|
|
408
|
+
id="SEC-TEMP-001",
|
|
409
|
+
name="Insecure Temporary File (TOCTOU Race Condition)",
|
|
410
|
+
category="race-condition",
|
|
411
|
+
severity="medium",
|
|
412
|
+
confidence="high",
|
|
413
|
+
cwe="CWE-377",
|
|
414
|
+
owasp="A01:2021-Broken-Access-Control",
|
|
415
|
+
message="使用不安全的临时文件创建函数,在文件名生成与打开之间存在 TOCTOU 竞争漏洞",
|
|
416
|
+
remediation="改用原子创建临时文件的安全 API(如 tempfile.NamedTemporaryFile 或 mkstemp)。",
|
|
417
|
+
languages={
|
|
418
|
+
"python": LanguageRuleSpec(
|
|
419
|
+
callee_patterns=[r"^tempfile\.mktemp$"],
|
|
420
|
+
),
|
|
421
|
+
"c": LanguageRuleSpec(
|
|
422
|
+
callee_patterns=[r"^(mktemp|tmpnam|tempnam)$"],
|
|
423
|
+
),
|
|
424
|
+
"cpp": LanguageRuleSpec(
|
|
425
|
+
callee_patterns=[r"^(mktemp|tmpnam|tempnam)$"],
|
|
426
|
+
),
|
|
427
|
+
}
|
|
428
|
+
),
|
|
429
|
+
|
|
430
|
+
# 9. Node.js 原型链污染 (CWE-1321)
|
|
431
|
+
SASTRule(
|
|
432
|
+
id="SEC-PROTO-001",
|
|
433
|
+
name="Prototype Pollution",
|
|
434
|
+
category="prototype-pollution",
|
|
435
|
+
severity="high",
|
|
436
|
+
confidence="high",
|
|
437
|
+
cwe="CWE-1321",
|
|
438
|
+
owasp="A03:2021-Injection",
|
|
439
|
+
message="对象深拷贝、合并或属性动态赋值时未过滤 __proto__ / constructor,存在原型链污染风险",
|
|
440
|
+
remediation="在合并对象属性前严格过滤 __proto__、constructor 等危险属性,或使用 Object.create(null)。",
|
|
441
|
+
languages={
|
|
442
|
+
"javascript": LanguageRuleSpec(
|
|
443
|
+
callee_patterns=[r"^(lodash\.)?(merge|defaultsDeep|extend)$", r"^Object\.assign$", r"^deepMerge$"],
|
|
444
|
+
arg_patterns=[r"(__proto__|constructor|prototype|req\.|request\.)"],
|
|
445
|
+
sanitizer_patterns=[r"hasOwnProperty", r"Object\.create\(null\)"],
|
|
446
|
+
),
|
|
447
|
+
"typescript": LanguageRuleSpec(
|
|
448
|
+
callee_patterns=[r"^(lodash\.)?(merge|defaultsDeep|extend)$", r"^Object\.assign$", r"^deepMerge$"],
|
|
449
|
+
arg_patterns=[r"(__proto__|constructor|prototype|req\.|request\.)"],
|
|
450
|
+
sanitizer_patterns=[r"hasOwnProperty", r"Object\.create\(null\)"],
|
|
451
|
+
),
|
|
452
|
+
}
|
|
453
|
+
),
|
|
454
|
+
|
|
455
|
+
# 10. 服务端模版注入 SSTI (CWE-1336)
|
|
456
|
+
SASTRule(
|
|
457
|
+
id="SEC-SSTI-001",
|
|
458
|
+
name="Server-Side Template Injection (SSTI)",
|
|
459
|
+
category="template-injection",
|
|
460
|
+
severity="critical",
|
|
461
|
+
confidence="high",
|
|
462
|
+
cwe="CWE-1336",
|
|
463
|
+
owasp="A03:2021-Injection",
|
|
464
|
+
message="直接动态编译或渲染外部可控的模版字符串,可能导致服务端模版注入 (SSTI) 与任意代码执行",
|
|
465
|
+
remediation="改用静态模版文件并传递参数上下文变量(如 render_template),严禁拼接外部输入动态渲染模版。",
|
|
466
|
+
languages={
|
|
467
|
+
"python": LanguageRuleSpec(
|
|
468
|
+
callee_patterns=[r"^(render_template_string|jinja2\.Template|Template|Environment\(\)\.from_string)$"],
|
|
469
|
+
arg_patterns=[r'(\+|\%|\.format\(|f["\']|request\.|args\.)'],
|
|
470
|
+
),
|
|
471
|
+
"javascript": LanguageRuleSpec(
|
|
472
|
+
callee_patterns=[r"^(ejs|nunjucks|handlebars|pug)\.(render|compile)$"],
|
|
473
|
+
arg_patterns=[r'(\+|req\.|request\.|`[^`]*\${)'],
|
|
474
|
+
),
|
|
475
|
+
"typescript": LanguageRuleSpec(
|
|
476
|
+
callee_patterns=[r"^(ejs|nunjucks|handlebars|pug)\.(render|compile)$"],
|
|
477
|
+
arg_patterns=[r'(\+|req\.|request\.|`[^`]*\${)'],
|
|
478
|
+
),
|
|
479
|
+
}
|
|
480
|
+
),
|
|
481
|
+
|
|
482
|
+
# 11. PHP 弱类型哈希比较与魔法哈希 (CWE-208 / CWE-697)
|
|
483
|
+
SASTRule(
|
|
484
|
+
id="SEC-PHPHASH-001",
|
|
485
|
+
name="PHP Loose Comparison Magic Hash Vulnerability",
|
|
486
|
+
category="type-juggling",
|
|
487
|
+
severity="high",
|
|
488
|
+
confidence="high",
|
|
489
|
+
cwe="CWE-208",
|
|
490
|
+
owasp="A07:2021-Identification-and-Authentication-Failures",
|
|
491
|
+
message="使用弱类型相等比较 (== 或 !=) 比对散列值,存在 PHP 魔法哈希 (0e...) 类型混淆与身份绕过风险",
|
|
492
|
+
remediation="改用严格相等运算符 (=== 或 !==),或使用 hash_equals() / password_verify() 进行常数时间安全比对。",
|
|
493
|
+
languages={
|
|
494
|
+
"php": LanguageRuleSpec(
|
|
495
|
+
callee_patterns=[r"^(md5|sha1|hash|crypt)$"],
|
|
496
|
+
line_patterns=[r'(==|!=)\s*(["\']0e\d+["\']|\$[A-Za-z0-9_]+)'],
|
|
497
|
+
sanitizer_patterns=[r"hash_equals", r"password_verify"],
|
|
498
|
+
),
|
|
499
|
+
}
|
|
500
|
+
),
|
|
501
|
+
|
|
502
|
+
# 12. Ruby 动态方法反射调用 (CWE-470)
|
|
503
|
+
SASTRule(
|
|
504
|
+
id="SEC-DYNCALL-001",
|
|
505
|
+
name="Ruby Unsafe Dynamic Method Dispatch",
|
|
506
|
+
category="code-injection",
|
|
507
|
+
severity="high",
|
|
508
|
+
confidence="high",
|
|
509
|
+
cwe="CWE-470",
|
|
510
|
+
owasp="A03:2021-Injection",
|
|
511
|
+
message="将外部未校验的参数直接传入动态方法分发调用 (send / public_send),可导致调用任意私有方法或执行恶意代码",
|
|
512
|
+
remediation="在调用 send / public_send 前,使用方法名白名单数组校验入参(例如 ALLOWED_ACTIONS.include?(action))。",
|
|
513
|
+
languages={
|
|
514
|
+
"ruby": LanguageRuleSpec(
|
|
515
|
+
callee_patterns=[r"^(send|public_send|__send__)$", r"\.(send|public_send|__send__)$"],
|
|
516
|
+
arg_patterns=[r"(params|request|\bto_sym\b)"],
|
|
517
|
+
sanitizer_patterns=[r"include\?"],
|
|
518
|
+
),
|
|
519
|
+
}
|
|
520
|
+
),
|
|
521
|
+
|
|
522
|
+
# 13. PHP 动态文件包含与伪协议流注入 (CWE-98)
|
|
523
|
+
SASTRule(
|
|
524
|
+
id="SEC-PHP-FILE-001",
|
|
525
|
+
name="PHP Dynamic File Inclusion / Stream Injection",
|
|
526
|
+
category="file-inclusion",
|
|
527
|
+
severity="critical",
|
|
528
|
+
confidence="high",
|
|
529
|
+
cwe="CWE-98",
|
|
530
|
+
owasp="A03:2021-Injection",
|
|
531
|
+
message="动态包含外部可控的文件路径或 PHP 伪协议流 (phar://, php://filter),存在本地/远程文件包含 (LFI/RFI) 与任意代码执行风险",
|
|
532
|
+
remediation="禁止使用外部输入拼接 include / require 语句;使用严格白名单映射文件,并禁用 allow_url_include。",
|
|
533
|
+
languages={
|
|
534
|
+
"php": LanguageRuleSpec(
|
|
535
|
+
callee_patterns=[r"^(include|include_once|require|require_once)$"],
|
|
536
|
+
require_string_concat=True,
|
|
537
|
+
arg_patterns=[r'(\$|phar:\/\/|php:\/\/|\.\.)'],
|
|
538
|
+
sanitizer_patterns=[r"basename\(", r"in_array\("],
|
|
539
|
+
),
|
|
540
|
+
}
|
|
541
|
+
),
|
|
542
|
+
]
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
class SASTRuleMatcher:
|
|
546
|
+
"""基于声明式规则库对 ParsedSource 执行多语言模式匹配"""
|
|
547
|
+
|
|
548
|
+
def __init__(self, rules: list[SASTRule] | None = None) -> None:
|
|
549
|
+
self.rules = rules or BUILTIN_RULES
|
|
550
|
+
|
|
551
|
+
def match_file(self, parsed: ParsedSource) -> list[dict[str, Any]]:
|
|
552
|
+
findings: list[dict[str, Any]] = []
|
|
553
|
+
lang = parsed.language
|
|
554
|
+
|
|
555
|
+
# 动态语言流分析器(主要用于强弱净化器消歧与框架 Source 判别)
|
|
556
|
+
analyzer = DynamicFlowAnalyzer(language=lang)
|
|
557
|
+
|
|
558
|
+
# 1. 结构化调用链与规则匹配 (直接复用 UniversalCodeMatcher 下沉内嵌的 CallNode 符号还原)
|
|
559
|
+
for call in parsed.calls:
|
|
560
|
+
resolved_callee = call.resolved_callee or call.callee
|
|
561
|
+
resolved_args = call.resolved_args or call.args_raw
|
|
562
|
+
is_tainted = call.is_tainted
|
|
563
|
+
for rule in self.rules:
|
|
564
|
+
spec = rule.languages.get(lang)
|
|
565
|
+
if not spec:
|
|
566
|
+
# 尝试 generic 回退
|
|
567
|
+
spec = rule.languages.get("generic")
|
|
568
|
+
if not spec:
|
|
569
|
+
continue
|
|
570
|
+
|
|
571
|
+
# 检查 callee_patterns 命中 (支持原始与解析展开的 callee)
|
|
572
|
+
callee_matched = False
|
|
573
|
+
for pat in spec.callee_patterns:
|
|
574
|
+
if (
|
|
575
|
+
re.search(pat, call.callee)
|
|
576
|
+
or re.search(pat, resolved_callee)
|
|
577
|
+
or re.search(pat, f"{call.callee}({call.args_raw})")
|
|
578
|
+
or re.search(pat, f"{resolved_callee}({resolved_args})")
|
|
579
|
+
):
|
|
580
|
+
callee_matched = True
|
|
581
|
+
break
|
|
582
|
+
if not callee_matched:
|
|
583
|
+
continue
|
|
584
|
+
|
|
585
|
+
# 检查行级特征匹配 (如弱类型比较运算符)
|
|
586
|
+
if spec.line_patterns:
|
|
587
|
+
line_matched = any(re.search(pat, call.span.snippet) for pat in spec.line_patterns)
|
|
588
|
+
if not line_matched:
|
|
589
|
+
continue
|
|
590
|
+
|
|
591
|
+
# 检查动态字符串拼接或受污染变量要求
|
|
592
|
+
has_concat_or_taint = (
|
|
593
|
+
call.has_string_concat
|
|
594
|
+
or is_tainted
|
|
595
|
+
or analyzer.has_framework_source(resolved_args)
|
|
596
|
+
or analyzer.has_framework_source(call.args_raw)
|
|
597
|
+
)
|
|
598
|
+
if spec.require_string_concat and not has_concat_or_taint:
|
|
599
|
+
continue
|
|
600
|
+
|
|
601
|
+
# 检查实参特征 (支持原始实参、解析展开后的实参与被调用者特征)
|
|
602
|
+
if spec.arg_patterns:
|
|
603
|
+
arg_matched = any(
|
|
604
|
+
re.search(pat, call.args_raw)
|
|
605
|
+
or re.search(pat, resolved_args)
|
|
606
|
+
or re.search(pat, call.callee)
|
|
607
|
+
or re.search(pat, resolved_callee)
|
|
608
|
+
for pat in spec.arg_patterns
|
|
609
|
+
)
|
|
610
|
+
if not arg_matched and is_tainted:
|
|
611
|
+
arg_matched = True
|
|
612
|
+
if not arg_matched:
|
|
613
|
+
continue
|
|
614
|
+
|
|
615
|
+
# 检查规则自带的净化器阻断
|
|
616
|
+
if spec.sanitizer_patterns:
|
|
617
|
+
is_sanitized = any(
|
|
618
|
+
re.search(pat, call.args_raw)
|
|
619
|
+
or re.search(pat, resolved_args)
|
|
620
|
+
or re.search(pat, call.span.snippet)
|
|
621
|
+
for pat in spec.sanitizer_patterns
|
|
622
|
+
)
|
|
623
|
+
if is_sanitized:
|
|
624
|
+
continue
|
|
625
|
+
|
|
626
|
+
# 检查分类强类型安全防御净化器消歧
|
|
627
|
+
if rule.category in STRONG_SANITIZERS:
|
|
628
|
+
if (
|
|
629
|
+
analyzer.is_strong_sanitized(call.args_raw, rule.category, lang)
|
|
630
|
+
or analyzer.is_strong_sanitized(resolved_args, rule.category, lang)
|
|
631
|
+
or analyzer.is_strong_sanitized(call.span.snippet, rule.category, lang)
|
|
632
|
+
):
|
|
633
|
+
continue
|
|
634
|
+
|
|
635
|
+
# 检查行级抑制注释
|
|
636
|
+
if UniversalCodeMatcher.is_line_suppressed(parsed, call.span.line, rule.id):
|
|
637
|
+
continue
|
|
638
|
+
|
|
639
|
+
findings.append({
|
|
640
|
+
"rule_id": rule.id,
|
|
641
|
+
"name": rule.name,
|
|
642
|
+
"category": rule.category,
|
|
643
|
+
"severity": rule.severity,
|
|
644
|
+
"confidence": rule.confidence,
|
|
645
|
+
"cwe": rule.cwe,
|
|
646
|
+
"owasp": rule.owasp,
|
|
647
|
+
"message": rule.message,
|
|
648
|
+
"file": parsed.rel_path,
|
|
649
|
+
"line": call.span.line,
|
|
650
|
+
"col": call.span.col,
|
|
651
|
+
"evidence": call.span.snippet or call.span.text,
|
|
652
|
+
"remediation": rule.remediation,
|
|
653
|
+
"language": lang,
|
|
654
|
+
})
|
|
655
|
+
|
|
656
|
+
# 2. 补充行级静态字面量扫描(如硬编码敏感凭据)
|
|
657
|
+
secret_findings = self._scan_hardcoded_secrets(parsed)
|
|
658
|
+
findings.extend(secret_findings)
|
|
659
|
+
|
|
660
|
+
# 3. 针对动态语言专有语法结构补充扫描
|
|
661
|
+
if lang in {"javascript", "typescript"}:
|
|
662
|
+
findings.extend(self._scan_js_specifics(parsed))
|
|
663
|
+
elif lang == "php":
|
|
664
|
+
findings.extend(self._scan_php_specifics(parsed))
|
|
665
|
+
elif lang == "ruby":
|
|
666
|
+
findings.extend(self._scan_ruby_specifics(parsed))
|
|
667
|
+
elif lang == "python":
|
|
668
|
+
findings.extend(self._scan_python_specifics(parsed))
|
|
669
|
+
|
|
670
|
+
# 去重并返回
|
|
671
|
+
seen = set()
|
|
672
|
+
deduped = []
|
|
673
|
+
for f in findings:
|
|
674
|
+
key = (f["rule_id"], f["file"], f["line"])
|
|
675
|
+
if key not in seen:
|
|
676
|
+
seen.add(key)
|
|
677
|
+
deduped.append(f)
|
|
678
|
+
return deduped
|
|
679
|
+
|
|
680
|
+
def _scan_hardcoded_secrets(self, parsed: ParsedSource) -> list[dict[str, Any]]:
|
|
681
|
+
findings = []
|
|
682
|
+
secret_kw = re.compile(r'\b(api[_-]?key|secret|password|passwd|private_key|token|access_token)\b\s*[:=]\s*["\']([^"\']{12,})["\']', re.IGNORECASE)
|
|
683
|
+
|
|
684
|
+
for line_no, line in enumerate(parsed.lines, 1):
|
|
685
|
+
if UniversalCodeMatcher.is_line_suppressed(parsed, line_no, "SEC-SECRET-001"):
|
|
686
|
+
continue
|
|
687
|
+
m = secret_kw.search(line)
|
|
688
|
+
if m:
|
|
689
|
+
val = m.group(2)
|
|
690
|
+
# 排除占位符
|
|
691
|
+
if val.lower() in {"your_token_here", "placeholder", "changeme", "your_password", "env_variable"}:
|
|
692
|
+
continue
|
|
693
|
+
findings.append({
|
|
694
|
+
"rule_id": "SEC-SECRET-001",
|
|
695
|
+
"name": "Hardcoded Secret or Access Token",
|
|
696
|
+
"category": "secrets",
|
|
697
|
+
"severity": "high",
|
|
698
|
+
"confidence": "medium",
|
|
699
|
+
"cwe": "CWE-798",
|
|
700
|
+
"owasp": "A07:2021-Identification-and-Authentication-Failures",
|
|
701
|
+
"message": f"在源码中疑似硬编码静态机密凭证 ({m.group(1)})",
|
|
702
|
+
"file": parsed.rel_path,
|
|
703
|
+
"line": line_no,
|
|
704
|
+
"col": m.start(),
|
|
705
|
+
"evidence": line.strip(),
|
|
706
|
+
"remediation": "将静态凭据移出代码,改用操作系统环境变量或受信任的 Secrets Manager 动态加载。",
|
|
707
|
+
"language": parsed.language,
|
|
708
|
+
})
|
|
709
|
+
return findings
|
|
710
|
+
|
|
711
|
+
def _scan_python_specifics(self, parsed: ParsedSource) -> list[dict[str, Any]]:
|
|
712
|
+
findings = []
|
|
713
|
+
try:
|
|
714
|
+
tree = ast.parse(parsed.raw_text, filename=str(parsed.filepath))
|
|
715
|
+
except Exception:
|
|
716
|
+
return []
|
|
717
|
+
|
|
718
|
+
for node in ast.walk(tree):
|
|
719
|
+
if isinstance(node, ast.ExceptHandler):
|
|
720
|
+
if len(node.body) == 1 and isinstance(node.body[0], ast.Pass):
|
|
721
|
+
is_broad = node.type is None
|
|
722
|
+
if isinstance(node.type, ast.Name) and node.type.id in {"Exception", "BaseException"}:
|
|
723
|
+
is_broad = True
|
|
724
|
+
if is_broad:
|
|
725
|
+
if not UniversalCodeMatcher.is_line_suppressed(parsed, node.lineno, "SEC-ERR-001"):
|
|
726
|
+
findings.append({
|
|
727
|
+
"rule_id": "SEC-ERR-001",
|
|
728
|
+
"name": "Silent Generic Exception Swallowing",
|
|
729
|
+
"category": "error-handling",
|
|
730
|
+
"severity": "low",
|
|
731
|
+
"confidence": "high",
|
|
732
|
+
"cwe": "CWE-391",
|
|
733
|
+
"owasp": "A09:2021-Security-Logging-and-Monitoring-Failures",
|
|
734
|
+
"message": "静默捕获并吞没通用异常(except: pass),掩盖运行时系统故障",
|
|
735
|
+
"file": parsed.rel_path,
|
|
736
|
+
"line": node.lineno,
|
|
737
|
+
"col": node.col_offset,
|
|
738
|
+
"evidence": parsed.lines[node.lineno - 1].strip() if 1 <= node.lineno <= len(parsed.lines) else "",
|
|
739
|
+
"remediation": "指定具体的异常捕获类型,并在 except 块中输出诊断日志或妥善恢复。",
|
|
740
|
+
"language": "python",
|
|
741
|
+
})
|
|
742
|
+
return findings
|
|
743
|
+
|
|
744
|
+
def _scan_js_specifics(self, parsed: ParsedSource) -> list[dict[str, Any]]:
|
|
745
|
+
findings = []
|
|
746
|
+
proto_re = re.compile(r'(\[[\s*"\'](__proto__|constructor|prototype)[\s*"\']\]|__proto__)\s*=', re.IGNORECASE)
|
|
747
|
+
for line_no, line in enumerate(parsed.lines, 1):
|
|
748
|
+
if proto_re.search(line) and not UniversalCodeMatcher.is_line_suppressed(parsed, line_no, "SEC-PROTO-001"):
|
|
749
|
+
findings.append({
|
|
750
|
+
"rule_id": "SEC-PROTO-001",
|
|
751
|
+
"name": "Prototype Pollution",
|
|
752
|
+
"category": "prototype-pollution",
|
|
753
|
+
"severity": "high",
|
|
754
|
+
"confidence": "high",
|
|
755
|
+
"cwe": "CWE-1321",
|
|
756
|
+
"owasp": "A03:2021-Injection",
|
|
757
|
+
"message": "代码中存在直接修改 __proto__ 或 constructor 原型对象的赋值操作",
|
|
758
|
+
"file": parsed.rel_path,
|
|
759
|
+
"line": line_no,
|
|
760
|
+
"col": 0,
|
|
761
|
+
"evidence": line.strip(),
|
|
762
|
+
"remediation": "在对象深拷贝或合并前过滤 __proto__、constructor 等危险属性,或使用 Object.create(null) 创建空原型字典。",
|
|
763
|
+
"language": parsed.language,
|
|
764
|
+
})
|
|
765
|
+
return findings
|
|
766
|
+
|
|
767
|
+
def _scan_php_specifics(self, parsed: ParsedSource) -> list[dict[str, Any]]:
|
|
768
|
+
findings = []
|
|
769
|
+
include_re = re.compile(r'^\s*(include|include_once|require|require_once)\s+([^;]+);')
|
|
770
|
+
hash_cmp_re = re.compile(r'\b(md5|sha1|hash)\s*\(.+?\)\s*(==|!=)\s*(["\']0e\d+["\']|\$[A-Za-z0-9_]+)', re.IGNORECASE)
|
|
771
|
+
|
|
772
|
+
for line_no, line in enumerate(parsed.lines, 1):
|
|
773
|
+
clean_line = parsed.clean_lines[line_no - 1] if line_no <= len(parsed.clean_lines) else line
|
|
774
|
+
# 1. 动态文件包含语句(无括号形式)
|
|
775
|
+
m_inc = include_re.search(clean_line)
|
|
776
|
+
if m_inc:
|
|
777
|
+
target_expr = m_inc.group(2).strip()
|
|
778
|
+
if ("$" in target_expr or "." in target_expr or "phar://" in target_expr) and not UniversalCodeMatcher.is_line_suppressed(parsed, line_no, "SEC-PHP-FILE-001"):
|
|
779
|
+
if not any(san in target_expr for san in ["basename(", "in_array("]):
|
|
780
|
+
findings.append({
|
|
781
|
+
"rule_id": "SEC-PHP-FILE-001",
|
|
782
|
+
"name": "PHP Dynamic File Inclusion / Stream Injection",
|
|
783
|
+
"category": "file-inclusion",
|
|
784
|
+
"severity": "critical",
|
|
785
|
+
"confidence": "high",
|
|
786
|
+
"cwe": "CWE-98",
|
|
787
|
+
"owasp": "A03:2021-Injection",
|
|
788
|
+
"message": f"PHP 动态文件包含使用未严格校验的表达式 ({m_inc.group(1)} {target_expr})",
|
|
789
|
+
"file": parsed.rel_path,
|
|
790
|
+
"line": line_no,
|
|
791
|
+
"col": m_inc.start(),
|
|
792
|
+
"evidence": line.strip(),
|
|
793
|
+
"remediation": "禁止使用外部输入拼接 include / require 语句;使用严格白名单映射文件,并禁用 allow_url_include。",
|
|
794
|
+
"language": "php",
|
|
795
|
+
})
|
|
796
|
+
|
|
797
|
+
# 2. 魔法哈希弱类型比较
|
|
798
|
+
m_hash = hash_cmp_re.search(clean_line)
|
|
799
|
+
if m_hash and not UniversalCodeMatcher.is_line_suppressed(parsed, line_no, "SEC-PHPHASH-001"):
|
|
800
|
+
if "hash_equals" not in clean_line and "password_verify" not in clean_line:
|
|
801
|
+
findings.append({
|
|
802
|
+
"rule_id": "SEC-PHPHASH-001",
|
|
803
|
+
"name": "PHP Loose Comparison Magic Hash Vulnerability",
|
|
804
|
+
"category": "type-juggling",
|
|
805
|
+
"severity": "high",
|
|
806
|
+
"confidence": "high",
|
|
807
|
+
"cwe": "CWE-208",
|
|
808
|
+
"owasp": "A07:2021-Identification-and-Authentication-Failures",
|
|
809
|
+
"message": f"使用弱类型相等比较 ({m_hash.group(2)}) 比对哈希值,存在 PHP 魔法哈希类型混淆绕过风险",
|
|
810
|
+
"file": parsed.rel_path,
|
|
811
|
+
"line": line_no,
|
|
812
|
+
"col": m_hash.start(),
|
|
813
|
+
"evidence": line.strip(),
|
|
814
|
+
"remediation": "改用严格相等运算符 (=== 或 !==),或使用 hash_equals() / password_verify() 进行常数时间安全比对。",
|
|
815
|
+
"language": "php",
|
|
816
|
+
})
|
|
817
|
+
return findings
|
|
818
|
+
|
|
819
|
+
def _scan_ruby_specifics(self, parsed: ParsedSource) -> list[dict[str, Any]]:
|
|
820
|
+
findings = []
|
|
821
|
+
dyncall_re = re.compile(r'\b(send|public_send|__send__)\s*\(?\s*(?:params|request|params\[:[A-Za-z0-9_]+\])', re.IGNORECASE)
|
|
822
|
+
for line_no, line in enumerate(parsed.lines, 1):
|
|
823
|
+
if dyncall_re.search(line) and not UniversalCodeMatcher.is_line_suppressed(parsed, line_no, "SEC-DYNCALL-001"):
|
|
824
|
+
if "include?" not in line:
|
|
825
|
+
findings.append({
|
|
826
|
+
"rule_id": "SEC-DYNCALL-001",
|
|
827
|
+
"name": "Ruby Unsafe Dynamic Method Dispatch",
|
|
828
|
+
"category": "code-injection",
|
|
829
|
+
"severity": "high",
|
|
830
|
+
"confidence": "high",
|
|
831
|
+
"cwe": "CWE-470",
|
|
832
|
+
"owasp": "A03:2021-Injection",
|
|
833
|
+
"message": "将外部未校验的参数直接传入动态方法分发调用 (send / public_send)",
|
|
834
|
+
"file": parsed.rel_path,
|
|
835
|
+
"line": line_no,
|
|
836
|
+
"col": 0,
|
|
837
|
+
"evidence": line.strip(),
|
|
838
|
+
"remediation": "在调用 send / public_send 前,使用方法名白名单数组校验入参(例如 ALLOWED_ACTIONS.include?(action))。",
|
|
839
|
+
"language": "ruby",
|
|
840
|
+
})
|
|
841
|
+
return findings
|