pwn 0.5.795 → 0.5.796
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/bin/pwn_autoinc_version +4 -5
- data/bin/pwn_web_cache_deception +40 -29
- data/documentation/AWS.md +15 -5
- data/documentation/Diagrams.md +1 -1
- data/documentation/Home.md +2 -2
- data/documentation/How-PWN-Works.md +1 -1
- data/documentation/What-is-PWN.md +1 -1
- data/documentation/diagrams/aws-cloud-security.svg +1 -1
- data/documentation/diagrams/dot/aws-cloud-security.dot +1 -1
- data/documentation/diagrams/dot/network-infra-testing.dot +1 -1
- data/documentation/diagrams/network-infra-testing.svg +1 -1
- data/etc/default_cron/session_cleanup.rb +84 -51
- data/lib/pwn/ai/agent/assembly.rb +0 -2
- data/lib/pwn/ai/agent/btc.rb +0 -2
- data/lib/pwn/ai/agent/burp_suite.rb +0 -2
- data/lib/pwn/ai/agent/curriculum.rb +2 -2
- data/lib/pwn/ai/agent/dispatch.rb +3 -0
- data/lib/pwn/ai/agent/engagement.rb +96 -41
- data/lib/pwn/ai/agent/extrospection/osint/bridges.rb +2 -0
- data/lib/pwn/ai/agent/extrospection.rb +50 -13
- data/lib/pwn/ai/agent/gqrx.rb +0 -2
- data/lib/pwn/ai/agent/hacker_one.rb +0 -2
- data/lib/pwn/ai/agent/learning.rb +45 -13
- data/lib/pwn/ai/agent/loop.rb +12 -11
- data/lib/pwn/ai/agent/metrics.rb +1 -1
- data/lib/pwn/ai/agent/mission.rb +6 -3
- data/lib/pwn/ai/agent/policy.rb +1 -1
- data/lib/pwn/ai/agent/policy_evaluation.rb +2 -2
- data/lib/pwn/ai/agent/reflect.rb +1 -0
- data/lib/pwn/ai/agent/request_runtime.rb +1 -1
- data/lib/pwn/ai/agent/reward.rb +155 -53
- data/lib/pwn/ai/agent/sast.rb +0 -2
- data/lib/pwn/ai/agent/task_dag.rb +5 -3
- data/lib/pwn/ai/agent/task_summarizer.rb +21 -11
- data/lib/pwn/ai/agent/tool_guard.rb +19 -0
- data/lib/pwn/ai/agent/tools/ruby_eval.rb +1 -1
- data/lib/pwn/ai/agent/tools/verify.rb +7 -3
- data/lib/pwn/ai/agent/transparent_browser.rb +0 -2
- data/lib/pwn/ai/agent/turn_finalizer.rb +3 -0
- data/lib/pwn/ai/anthropic.rb +3 -3
- data/lib/pwn/ai/context.rb +2 -1
- data/lib/pwn/ai/gemini.rb +7 -5
- data/lib/pwn/ai/grok.rb +37 -18
- data/lib/pwn/ai/mcp.rb +17 -5
- data/lib/pwn/ai/ollama.rb +76 -35
- data/lib/pwn/ai/open_ai.rb +7 -19
- data/lib/pwn/ai/open_web_ui.rb +76 -40
- data/lib/pwn/aws/cloud_search_domain.rb +6 -0
- data/lib/pwn/aws/iam.rb +2 -2
- data/lib/pwn/aws/workspaces.rb +2 -2
- data/lib/pwn/aws.rb +0 -5
- data/lib/pwn/bounty/lifecycle_authz_replay.rb +1 -1
- data/lib/pwn/config.rb +17 -10
- data/lib/pwn/corpus.rb +33 -5
- data/lib/pwn/cron.rb +60 -17
- data/lib/pwn/driver.rb +2 -3
- data/lib/pwn/engagement.rb +28 -10
- data/lib/pwn/ffi/capstone.rb +3 -2
- data/lib/pwn/ffi/fftw.rb +8 -6
- data/lib/pwn/ffi/keystone.rb +3 -2
- data/lib/pwn/ffi/soapy_sdr.rb +10 -6
- data/lib/pwn/json_text.rb +25 -13
- data/lib/pwn/memory_index.rb +6 -4
- data/lib/pwn/module_skills.rb +3 -1
- data/lib/pwn/plugins/aflplusplus.rb +1 -0
- data/lib/pwn/plugins/ai_sandbox.rb +42 -10
- data/lib/pwn/plugins/android.rb +429 -466
- data/lib/pwn/plugins/artifact_registry.rb +12 -2
- data/lib/pwn/plugins/assembly.rb +9 -42
- data/lib/pwn/plugins/authentication_helper.rb +4 -3
- data/lib/pwn/plugins/baresip.rb +70 -28
- data/lib/pwn/plugins/binary_analysis.rb +14 -5
- data/lib/pwn/plugins/binary_parser.rb +42 -7
- data/lib/pwn/plugins/black_duck_binary_analysis.rb +3 -3
- data/lib/pwn/plugins/burp_suite.rb +15 -12
- data/lib/pwn/plugins/bus_pirate.rb +3 -7
- data/lib/pwn/plugins/char.rb +9 -3
- data/lib/pwn/plugins/credit_card.rb +7 -0
- data/lib/pwn/plugins/dao_ldap.rb +2 -2
- data/lib/pwn/plugins/dao_mongo.rb +1 -1
- data/lib/pwn/plugins/debugger.rb +1 -1
- data/lib/pwn/plugins/defect_dojo.rb +7 -3
- data/lib/pwn/plugins/detect_os.rb +1 -1
- data/lib/pwn/plugins/detonate.rb +9 -19
- data/lib/pwn/plugins/exploit_db.rb +1 -1
- data/lib/pwn/plugins/file_fu.rb +4 -1
- data/lib/pwn/plugins/findings.rb +76 -2
- data/lib/pwn/plugins/fuzz.rb +12 -3
- data/lib/pwn/plugins/gdb.rb +7 -2
- data/lib/pwn/plugins/gdbmi.rb +10 -6
- data/lib/pwn/plugins/git.rb +18 -13
- data/lib/pwn/plugins/github.rb +11 -6
- data/lib/pwn/plugins/google_workspace.rb +11 -3
- data/lib/pwn/plugins/hacker_one.rb +5 -1
- data/lib/pwn/plugins/httpx.rb +24 -8
- data/lib/pwn/plugins/ip_info.rb +11 -8
- data/lib/pwn/plugins/irc.rb +73 -45
- data/lib/pwn/plugins/jenkins.rb +2 -2
- data/lib/pwn/plugins/jira_data_center.rb +13 -6
- data/lib/pwn/plugins/jobs.rb +62 -4
- data/lib/pwn/plugins/log.rb +1 -1
- data/lib/pwn/plugins/monkey_patch.rb +1 -1
- data/lib/pwn/plugins/msr206.rb +157 -182
- data/lib/pwn/plugins/nessus_cloud.rb +2 -2
- data/lib/pwn/plugins/nexpose_vuln_scan.rb +44 -33
- data/lib/pwn/plugins/nuclei.rb +24 -8
- data/lib/pwn/plugins/ocr.rb +3 -1
- data/lib/pwn/plugins/open_api.rb +0 -4
- data/lib/pwn/plugins/openvas.rb +31 -43
- data/lib/pwn/plugins/packet.rb +40 -25
- data/lib/pwn/plugins/pony.rb +2 -2
- data/lib/pwn/plugins/preflight_checker.rb +1 -1
- data/lib/pwn/plugins/process_tube.rb +17 -2
- data/lib/pwn/plugins/ps.rb +6 -1
- data/lib/pwn/plugins/repl/ai.rb +1 -0
- data/lib/pwn/plugins/repl/ai_console.rb +12 -5
- data/lib/pwn/plugins/repl/mesh.rb +10 -2
- data/lib/pwn/plugins/sbom.rb +59 -27
- data/lib/pwn/plugins/scannable_codes.rb +3 -1
- data/lib/pwn/plugins/serial.rb +102 -44
- data/lib/pwn/plugins/shodan.rb +4 -10
- data/lib/pwn/plugins/sock.rb +16 -11
- data/lib/pwn/plugins/ssn.rb +3 -1
- data/lib/pwn/plugins/transparent_browser.rb +43 -3
- data/lib/pwn/plugins/vault.rb +92 -30
- data/lib/pwn/plugins/vin.rb +2 -1
- data/lib/pwn/plugins/vsphere.rb +2 -1
- data/lib/pwn/plugins/xxd.rb +3 -5
- data/lib/pwn/plugins/yubikey/security_domain/scp.rb +4 -0
- data/lib/pwn/plugins/yubikey/transport.rb +42 -11
- data/lib/pwn/plugins/yubikey.rb +21 -6
- data/lib/pwn/plugins/zaproxy.rb +3 -4
- data/lib/pwn/reports/ai_red_team.rb +4 -4
- data/lib/pwn/reports/pdf.rb +9 -5
- data/lib/pwn/reports/sast.rb +4 -4
- data/lib/pwn/sast/keystore.rb +2 -2
- data/lib/pwn/sast/logger.rb +1 -1
- data/lib/pwn/sast/php_type_juggling.rb +3 -6
- data/lib/pwn/sast/pom_version.rb +12 -6
- data/lib/pwn/sast/port.rb +1 -1
- data/lib/pwn/sast/sql.rb +3 -7
- data/lib/pwn/sast/test_case_engine.rb +62 -16
- data/lib/pwn/sast/type_script_type_juggling.rb +3 -6
- data/lib/pwn/sdr/decoder/base.rb +8 -0
- data/lib/pwn/sdr/decoder/lora.rb +1 -1
- data/lib/pwn/sdr/flipper_zero.rb +4 -7
- data/lib/pwn/sdr/gqrx.rb +35 -16
- data/lib/pwn/sdr/son_micro_rfid.rb +44 -26
- data/lib/pwn/sdr.rb +1 -1
- data/lib/pwn/session_trace.rb +7 -2
- data/lib/pwn/sessions.rb +307 -39
- data/lib/pwn/setup.rb +4 -3
- data/lib/pwn/version.rb +1 -1
- data/lib/pwn/www/app_cobalt_io.rb +14 -2
- data/lib/pwn/www/bing.rb +13 -1
- data/lib/pwn/www/bug_crowd.rb +14 -2
- data/lib/pwn/www/checkip.rb +13 -1
- data/lib/pwn/www/coinbase_pro.rb +14 -2
- data/lib/pwn/www/duckduckgo.rb +13 -1
- data/lib/pwn/www/facebook.rb +14 -2
- data/lib/pwn/www/github.rb +14 -2
- data/lib/pwn/www/google.rb +13 -1
- data/lib/pwn/www/hacker_one.rb +117 -33
- data/lib/pwn/www/linkedin.rb +14 -2
- data/lib/pwn/www/pandora.rb +14 -2
- data/lib/pwn/www/pastebin.rb +13 -1
- data/lib/pwn/www/paypal.rb +16 -4
- data/lib/pwn/www/synack.rb +14 -2
- data/lib/pwn/www/torch.rb +17 -3
- data/lib/pwn/www/trading_view.rb +14 -2
- data/lib/pwn/www/twitter.rb +14 -2
- data/lib/pwn/www/uber.rb +14 -2
- data/lib/pwn/www/upwork.rb +14 -2
- data/lib/pwn/www/wayback_machine.rb +16 -2
- data/lib/pwn/www/youtube.rb +13 -1
- data/pwn.gemspec +4 -0
- data/spec/integration/authentication_helper_oath_spec.rb +1 -1
- data/spec/integration/autoinc_lifecycle_supplement_spec.rb +47 -0
- data/spec/integration/gemspec_deleted_files_spec.rb +43 -0
- data/spec/integration/spec_curriculum_isolation_spec.rb +41 -0
- data/spec/integration/verify_acceptance_eui_regression_spec.rb +162 -0
- data/spec/integration/web_cache_lifecycle_closure_spec.rb +89 -0
- data/spec/integration/web_cache_lifecycle_supplement_spec.rb +70 -0
- data/spec/lib/pwn/ai/agent/analysis_errors_regression_spec.rb +33 -0
- data/spec/lib/pwn/ai/agent/curriculum_cooldown_regression_spec.rb +19 -0
- data/spec/lib/pwn/ai/agent/curriculum_spec.rb +2 -0
- data/spec/lib/pwn/ai/agent/engagement_boundary_regression_spec.rb +42 -0
- data/spec/lib/pwn/ai/agent/engagement_dispatch_review_spec.rb +82 -0
- data/spec/lib/pwn/ai/agent/engagement_roe_regression_spec.rb +25 -0
- data/spec/lib/pwn/ai/agent/engagement_scope_regression_spec.rb +37 -0
- data/spec/lib/pwn/ai/agent/extrospection/osint/bridges_spec.rb +4 -0
- data/spec/lib/pwn/ai/agent/extrospection_input_regression_spec.rb +31 -0
- data/spec/lib/pwn/ai/agent/extrospection_review_spec.rb +61 -0
- data/spec/lib/pwn/ai/agent/extrospection_serial_review_spec.rb +42 -0
- data/spec/lib/pwn/ai/agent/extrospection_spec.rb +9 -0
- data/spec/lib/pwn/ai/agent/extrospection_verification_regression_spec.rb +39 -0
- data/spec/lib/pwn/ai/agent/learning_last_answer_regression_spec.rb +32 -0
- data/spec/lib/pwn/ai/agent/learning_lifecycle_closure_spec.rb +84 -0
- data/spec/lib/pwn/ai/agent/learning_prune_regression_spec.rb +17 -0
- data/spec/lib/pwn/ai/agent/learning_spec.rb +2 -1
- data/spec/lib/pwn/ai/agent/loop_execution_audit_spec.rb +30 -0
- data/spec/lib/pwn/ai/agent/metrics_usage_regression_spec.rb +20 -0
- data/spec/lib/pwn/ai/agent/mission_execution_audit_spec.rb +27 -0
- data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +210 -18
- data/spec/lib/pwn/ai/agent/policy_confidence_regression_spec.rb +16 -0
- data/spec/lib/pwn/ai/agent/policy_evaluation_spec.rb +1 -1
- data/spec/lib/pwn/ai/agent/policy_evaluation_tmp_regression_spec.rb +36 -0
- data/spec/lib/pwn/ai/agent/reflect_model_regression_spec.rb +15 -0
- data/spec/lib/pwn/ai/agent/request_runtime_execution_audit_spec.rb +43 -0
- data/spec/lib/pwn/ai/agent/reward_binding_review_spec.rb +129 -0
- data/spec/lib/pwn/ai/agent/reward_dispatch_review_spec.rb +154 -0
- data/spec/lib/pwn/ai/agent/reward_envelope_regression_spec.rb +45 -0
- data/spec/lib/pwn/ai/agent/reward_turn_regression_spec.rb +40 -0
- data/spec/lib/pwn/ai/agent/swarm_spec.rb +2 -2
- data/spec/lib/pwn/ai/agent/task_dag_execution_audit_spec.rb +45 -0
- data/spec/lib/pwn/ai/agent/task_summarizer_failure_regression_spec.rb +26 -0
- data/spec/lib/pwn/ai/agent/tools/verify_execution_audit_spec.rb +33 -0
- data/spec/lib/pwn/ai/context_range_audit_spec.rb +24 -0
- data/spec/lib/pwn/ai/gemini_roundtrip_audit_spec.rb +33 -0
- data/spec/lib/pwn/ai/grok_reasoning_effort_spec.rb +43 -0
- data/spec/lib/pwn/ai/mcp_session_audit_spec.rb +36 -0
- data/spec/lib/pwn/ai/ollama_spec.rb +6 -11
- data/spec/lib/pwn/ai/open_web_ui_spec.rb +6 -11
- data/spec/lib/pwn/ai/provider_history_audit_spec.rb +44 -0
- data/spec/lib/pwn/ai/provider_operations_audit_spec.rb +53 -0
- data/spec/lib/pwn/ai/provider_review_history_stream_regression_spec.rb +143 -0
- data/spec/lib/pwn/ai/provider_review_tls_regression_spec.rb +62 -0
- data/spec/lib/pwn/ai/provider_stream_audit_spec.rb +49 -0
- data/spec/lib/pwn/aws/iam_decoding_regression_spec.rb +23 -0
- data/spec/lib/pwn/aws/services_runtime_regression_spec.rb +51 -0
- data/spec/lib/pwn/aws_spec.rb +6 -0
- data/spec/lib/pwn/banner_operational_audit_spec.rb +105 -0
- data/spec/lib/pwn/bounty/lifecycle_authz_replay_spec.rb +17 -0
- data/spec/lib/pwn/config_redaction_regression_spec.rb +24 -0
- data/spec/lib/pwn/config_skills_regression_spec.rb +38 -0
- data/spec/lib/pwn/corpus_core_review_regression_spec.rb +96 -0
- data/spec/lib/pwn/corpus_spec.rb +13 -0
- data/spec/lib/pwn/cron_core_review_regression_spec.rb +95 -0
- data/spec/lib/pwn/cron_execution_spec.rb +75 -0
- data/spec/lib/pwn/driver_core_review_regression_spec.rb +38 -0
- data/spec/lib/pwn/driver_spec.rb +13 -0
- data/spec/lib/pwn/engagement_core_review_regression_spec.rb +88 -0
- data/spec/lib/pwn/engagement_storage_regression_spec.rb +44 -0
- data/spec/lib/pwn/ffi/capstone_spec.rb +19 -0
- data/spec/lib/pwn/ffi/fftw_spec.rb +19 -0
- data/spec/lib/pwn/ffi/keystone_spec.rb +13 -0
- data/spec/lib/pwn/ffi/soapy_sdr_spec.rb +13 -0
- data/spec/lib/pwn/json_text_spec.rb +25 -0
- data/spec/lib/pwn/memory_index_spec.rb +23 -0
- data/spec/lib/pwn/module_skills_parsing_regression_spec.rb +34 -0
- data/spec/lib/pwn/plugins/ai_sandbox_boundary_review_spec.rb +57 -0
- data/spec/lib/pwn/plugins/ai_sandbox_spec.rb +10 -18
- data/spec/lib/pwn/plugins/android_review_fixes_spec.rb +121 -0
- data/spec/lib/pwn/plugins/android_transport_audit_spec.rb +64 -0
- data/spec/lib/pwn/plugins/api_import_namespace_audit_spec.rb +49 -0
- data/spec/lib/pwn/plugins/artifact_registry_namespace_audit_spec.rb +20 -0
- data/spec/lib/pwn/plugins/artifact_registry_review_fixes_spec.rb +63 -0
- data/spec/lib/pwn/plugins/assembly_namespace_audit_spec.rb +16 -0
- data/spec/lib/pwn/plugins/assembly_review_fixes_spec.rb +33 -0
- data/spec/lib/pwn/plugins/authentication_helper_spec.rb +14 -0
- data/spec/lib/pwn/plugins/baresip_review_fixes_spec.rb +127 -0
- data/spec/lib/pwn/plugins/baresip_transport_audit_spec.rb +59 -0
- data/spec/lib/pwn/plugins/binary_analysis_process_review_spec.rb +57 -0
- data/spec/lib/pwn/plugins/black_duck_namespace_audit_spec.rb +25 -0
- data/spec/lib/pwn/plugins/burp_suite_har_review_fixes_spec.rb +60 -0
- data/spec/lib/pwn/plugins/burp_suite_import_review_fixes_spec.rb +62 -0
- data/spec/lib/pwn/plugins/burp_suite_namespace_audit_spec.rb +37 -0
- data/spec/lib/pwn/plugins/bus_pirate_transport_audit_spec.rb +19 -0
- data/spec/lib/pwn/plugins/file_fu_namespace_audit_spec.rb +17 -0
- data/spec/lib/pwn/plugins/findings_structured_spec.rb +1 -1
- data/spec/lib/pwn/plugins/gdbmi_namespace_audit_spec.rb +28 -0
- data/spec/lib/pwn/plugins/gdbmi_review_fixes_spec.rb +73 -0
- data/spec/lib/pwn/plugins/github_argv_review_spec.rb +49 -0
- data/spec/lib/pwn/plugins/google_workspace_provider_review_oauth_spec.rb +80 -0
- data/spec/lib/pwn/plugins/irc_review_fixes_spec.rb +92 -0
- data/spec/lib/pwn/plugins/irc_transport_audit_spec.rb +37 -0
- data/spec/lib/pwn/plugins/jenkins_namespace_audit_spec.rb +12 -0
- data/spec/lib/pwn/plugins/jira_data_center_namespace_audit_spec.rb +44 -0
- data/spec/lib/pwn/plugins/jira_data_center_review_fixes_spec.rb +81 -0
- data/spec/lib/pwn/plugins/jsonl_elf_review_fixes_spec.rb +59 -0
- data/spec/lib/pwn/plugins/log_spec.rb +36 -20
- data/spec/lib/pwn/plugins/monkey_patch_spec.rb +16 -0
- data/spec/lib/pwn/plugins/msr206_readback_review_fixes_spec.rb +119 -0
- data/spec/lib/pwn/plugins/msr206_review_fixes_spec.rb +50 -0
- data/spec/lib/pwn/plugins/msr206_transport_audit_spec.rb +64 -0
- data/spec/lib/pwn/plugins/nessus_cloud_namespace_audit_spec.rb +14 -0
- data/spec/lib/pwn/plugins/nexpose_review_fixes_spec.rb +55 -0
- data/spec/lib/pwn/plugins/open_api_namespace_audit_spec.rb +22 -0
- data/spec/lib/pwn/plugins/packet_transport_audit_spec.rb +47 -0
- data/spec/lib/pwn/plugins/plugins_b_operational_regression_spec.rb +600 -0
- data/spec/lib/pwn/plugins/pony_namespace_audit_spec.rb +17 -0
- data/spec/lib/pwn/plugins/pony_review_fixes_spec.rb +33 -0
- data/spec/lib/pwn/plugins/process_tube_namespace_audit_spec.rb +19 -0
- data/spec/lib/pwn/plugins/ps_namespace_audit_spec.rb +12 -0
- data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +111 -0
- data/spec/lib/pwn/plugins/repl/ai_spec.rb +38 -0
- data/spec/lib/pwn/plugins/repl/mesh_spec.rb +52 -0
- data/spec/lib/pwn/plugins/sandbox_spec.rb +9 -7
- data/spec/lib/pwn/plugins/sbom_review_fixes_spec.rb +43 -0
- data/spec/lib/pwn/plugins/scannable_codes_namespace_audit_spec.rb +15 -0
- data/spec/lib/pwn/plugins/serial_review_fixes_spec.rb +76 -0
- data/spec/lib/pwn/plugins/serial_transport_audit_spec.rb +102 -0
- data/spec/lib/pwn/plugins/shodan_namespace_audit_spec.rb +10 -0
- data/spec/lib/pwn/plugins/sock_transport_audit_spec.rb +55 -0
- data/spec/lib/pwn/plugins/transparent_browser_navigation_review_spec.rb +21 -0
- data/spec/lib/pwn/plugins/vault_master_key_eui_regression_spec.rb +242 -0
- data/spec/lib/pwn/plugins/vault_spec.rb +58 -0
- data/spec/lib/pwn/plugins/vault_store_safety_spec.rb +1 -1
- data/spec/lib/pwn/plugins/xxd_namespace_audit_spec.rb +34 -0
- data/spec/lib/pwn/plugins/yubikey_hid_cleanup_review_fixes_spec.rb +52 -0
- data/spec/lib/pwn/plugins/yubikey_lifecycle_audit_spec.rb +65 -0
- data/spec/lib/pwn/plugins/yubikey_options_audit_spec.rb +30 -0
- data/spec/lib/pwn/plugins/yubikey_selector_audit_spec.rb +26 -0
- data/spec/lib/pwn/plugins/yubikey_spec.rb +1 -1
- data/spec/lib/pwn/plugins/zaproxy_namespace_audit_spec.rb +30 -0
- data/spec/lib/pwn/reports/empty_report_audit_spec.rb +18 -0
- data/spec/lib/pwn/reports/pdf_spec.rb +25 -0
- data/spec/lib/pwn/reports/provider_review_encoding_regression_spec.rb +45 -0
- data/spec/lib/pwn/sast/engine_runtime_regression_spec.rb +91 -0
- data/spec/lib/pwn/sast/filter_edge_regression_spec.rb +39 -0
- data/spec/lib/pwn/sast/formatter_review_fixes_spec.rb +178 -0
- data/spec/lib/pwn/sast/path_review_fixes_spec.rb +60 -0
- data/spec/lib/pwn/sast/pom_runtime_regression_spec.rb +37 -0
- data/spec/lib/pwn/sast/rules_runtime_regression_spec.rb +78 -0
- data/spec/lib/pwn/sast/sql_review_fixes_spec.rb +38 -0
- data/spec/lib/pwn/sdr/decoder/base_iq_spec.rb +21 -18
- data/spec/lib/pwn/sdr/decoder/base_review_fixes_spec.rb +49 -0
- data/spec/lib/pwn/sdr/decoder/base_validation_spec.rb +78 -0
- data/spec/lib/pwn/sdr/decoder/lora_spec.rb +9 -0
- data/spec/lib/pwn/sdr/flipper_zero_review_fixes_spec.rb +34 -0
- data/spec/lib/pwn/sdr/gqrx_operational_spec.rb +83 -0
- data/spec/lib/pwn/sdr/gqrx_review_fixes_spec.rb +22 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_review_fixes_spec.rb +113 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_serial_review_fixes_spec.rb +76 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_spec.rb +39 -0
- data/spec/lib/pwn/sdr_spec.rb +5 -0
- data/spec/lib/pwn/session_cleanup_default_spec.rb +1 -1
- data/spec/lib/pwn/session_cleanup_lifecycle_supplement_spec.rb +39 -0
- data/spec/lib/pwn/session_cleanup_payload_spec.rb +3 -2
- data/spec/lib/pwn/session_trace_lifecycle_supplement_spec.rb +39 -0
- data/spec/lib/pwn/sessions_archive_closure_spec.rb +126 -0
- data/spec/lib/pwn/sessions_lifecycle_closure_spec.rb +373 -0
- data/spec/lib/pwn/sessions_lifecycle_supplement_spec.rb +204 -0
- data/spec/lib/pwn/setup_operational_regression_spec.rb +36 -0
- data/spec/lib/pwn/www/browser_review_fixes_spec.rb +70 -0
- data/spec/lib/pwn/www/browser_runtime_regression_spec.rb +100 -0
- data/spec/lib/pwn/www/hacker_one_runtime_regression_spec.rb +146 -0
- data/spec/lib/pwn/www/pagination_review_fixes_spec.rb +84 -0
- data/spec/support/namespace_controller_observability_fixture.rb +141 -0
- data/spec/support/sandbox.rb +8 -5
- data/third_party/pwn_rdoc.jsonl +73 -31
- metadata +137 -18
- data/etc/default_skills/pwn/aws/elastic_transcoder/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/lambda_preview/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/ops_works/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/ops_works_cm/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/sms/SKILL.md +0 -48
- data/lib/pwn/aws/elastic_transcoder.rb +0 -95
- data/lib/pwn/aws/lambda_preview.rb +0 -95
- data/lib/pwn/aws/ops_works.rb +0 -95
- data/lib/pwn/aws/ops_works_cm.rb +0 -95
- data/lib/pwn/aws/sms.rb +0 -95
- data/spec/lib/pwn/aws/elastic_transcoder_spec.rb +0 -15
- data/spec/lib/pwn/aws/lambda_preview_spec.rb +0 -15
- data/spec/lib/pwn/aws/ops_works_cm_spec.rb +0 -15
- data/spec/lib/pwn/aws/ops_works_spec.rb +0 -15
- data/spec/lib/pwn/aws/sms_spec.rb +0 -15
data/lib/pwn/sessions.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'fileutils'
|
|
5
|
+
require 'tmpdir'
|
|
5
6
|
require 'time'
|
|
6
7
|
require 'securerandom'
|
|
7
8
|
require 'digest'
|
|
@@ -29,6 +30,16 @@ module PWN
|
|
|
29
30
|
TITLE_WORD_MAX = 7
|
|
30
31
|
METADATA_MUTEX = Mutex.new
|
|
31
32
|
|
|
33
|
+
# A checked unlink can fail after earlier files have already disappeared.
|
|
34
|
+
class PartialDeletion < IOError
|
|
35
|
+
attr_reader :result
|
|
36
|
+
|
|
37
|
+
def initialize(result)
|
|
38
|
+
@result = result
|
|
39
|
+
super('Session deletion interrupted; inspect the recovery ledger before retrying')
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
32
43
|
SESSION_ID = /\A\d{8}_\d{6}_[0-9a-f]{8}\z/
|
|
33
44
|
# Selectors follow writer-owned schemas only; never recurse through payloads.
|
|
34
45
|
# :values is a documented map, :items an array, :path a session file path.
|
|
@@ -68,8 +79,8 @@ module PWN
|
|
|
68
79
|
|
|
69
80
|
# Supported Method Parameters::
|
|
70
81
|
# dir = PWN::Sessions.sessions_dir
|
|
71
|
-
public_class_method def self.sessions_dir
|
|
72
|
-
FileUtils.mkdir_p(SESSIONS_DIR)
|
|
82
|
+
public_class_method def self.sessions_dir(opts = {})
|
|
83
|
+
FileUtils.mkdir_p(SESSIONS_DIR) unless opts[:read_only]
|
|
73
84
|
SESSIONS_DIR
|
|
74
85
|
end
|
|
75
86
|
|
|
@@ -88,7 +99,7 @@ module PWN
|
|
|
88
99
|
when :trace then ['traces', File.join(id, 'trace.jsonl')]
|
|
89
100
|
else raise ArgumentError, 'Invalid session support kind'
|
|
90
101
|
end
|
|
91
|
-
directory = opts[:read_only]
|
|
102
|
+
directory = sessions_dir(read_only: opts[:read_only] == true)
|
|
92
103
|
legacy = File.join(directory, name)
|
|
93
104
|
return legacy if File.exist?(legacy) || File.symlink?(legacy)
|
|
94
105
|
|
|
@@ -105,7 +116,7 @@ module PWN
|
|
|
105
116
|
# Supported Method Parameters::
|
|
106
117
|
# sessions = PWN::Sessions.list
|
|
107
118
|
public_class_method def self.list(opts = {})
|
|
108
|
-
dir = sessions_dir
|
|
119
|
+
dir = sessions_dir(read_only: true)
|
|
109
120
|
references = opts[:references] || dependency_index
|
|
110
121
|
Dir.glob(File.join(dir, '*.jsonl')).reverse.filter_map do |f|
|
|
111
122
|
naming = retention_status(session_id: File.basename(f, '.jsonl'), references: references)
|
|
@@ -641,13 +652,13 @@ module PWN
|
|
|
641
652
|
# this effective title. Explicit titles follow the same seven-word limit.
|
|
642
653
|
public_class_method def self.metadata(opts = {})
|
|
643
654
|
sid = opts[:session_id].to_s
|
|
644
|
-
path = support_path(kind: :metadata, session_id: sid)
|
|
655
|
+
path = support_path(kind: :metadata, session_id: sid, read_only: true)
|
|
645
656
|
if File.file?(path)
|
|
646
657
|
stored = JSON.parse(File.read(path), symbolize_names: true)
|
|
647
658
|
return stored.merge(id: sid, title: bounded_title(title: stored[:title])) if stored.is_a?(Hash) && !bounded_title(title: stored[:title]).empty?
|
|
648
659
|
end
|
|
649
660
|
|
|
650
|
-
first = File.open(File.join(
|
|
661
|
+
first = File.open(File.join(SESSIONS_DIR, "#{sid}.jsonl"), &:gets)
|
|
651
662
|
row = JSON.parse(first.to_s, symbolize_names: true)
|
|
652
663
|
title = row[:content].to_s.delete_prefix('Session started: ') if row[:role] == 'system' && row[:content].to_s.start_with?('Session started: ')
|
|
653
664
|
{ id: sid, title: bounded_title(title: title.to_s.empty? ? "pwn-ai session #{sid}" : title) }
|
|
@@ -663,10 +674,10 @@ module PWN
|
|
|
663
674
|
status = { title_source: nil, is_summarized: false, classification: :unknown, title_reason: 'invalid_session' }
|
|
664
675
|
return status unless sid.match?(SESSION_ID)
|
|
665
676
|
|
|
666
|
-
path = File.join(
|
|
677
|
+
path = File.join(SESSIONS_DIR, "#{sid}.jsonl")
|
|
667
678
|
return status.merge(title_reason: 'invalid_transcript') unless cleanup_transcript_valid?(path: path)
|
|
668
679
|
|
|
669
|
-
meta_path = support_path(kind: :metadata, session_id: sid)
|
|
680
|
+
meta_path = support_path(kind: :metadata, session_id: sid, read_only: true)
|
|
670
681
|
return status.merge(classification: :unnamed, title_reason: 'missing_summary_provenance') unless File.exist?(meta_path) || File.symlink?(meta_path)
|
|
671
682
|
return status.merge(title_reason: 'unsafe_metadata') unless File.file?(meta_path) && !File.symlink?(meta_path)
|
|
672
683
|
|
|
@@ -887,11 +898,14 @@ module PWN
|
|
|
887
898
|
# Supported Method Parameters::
|
|
888
899
|
# transcript = PWN::Sessions.load(session_id: 'required')
|
|
889
900
|
public_class_method def self.load(opts = {})
|
|
890
|
-
sid = opts[:session_id]
|
|
901
|
+
sid = opts[:session_id].to_s
|
|
902
|
+
raise ArgumentError, 'Invalid session ID' if sid.empty? || File.basename(sid) != sid || sid.include?("\0") || %w[. ..].include?(sid)
|
|
903
|
+
|
|
891
904
|
path = File.join(sessions_dir, "#{sid}.jsonl")
|
|
905
|
+
raise IOError, 'Unsafe session transcript' if File.symlink?(path) || (File.exist?(path) && File.realpath(path) != File.expand_path(path))
|
|
892
906
|
return PWN::AI::Agent::Learning.session_evidence(session_id: sid) || [] unless File.exist?(path)
|
|
893
907
|
|
|
894
|
-
File.
|
|
908
|
+
File.open(path, File::RDONLY | File::NOFOLLOW) { |file| file.each_line.map { |line| JSON.parse(line, symbolize_names: true) } }
|
|
895
909
|
end
|
|
896
910
|
|
|
897
911
|
# Newest session that is not exclude_session_id (the prior pwn-ai run).
|
|
@@ -1064,6 +1078,53 @@ module PWN
|
|
|
1064
1078
|
[]
|
|
1065
1079
|
end
|
|
1066
1080
|
|
|
1081
|
+
# Store locks precede transcript leases and transcript writer locks. All
|
|
1082
|
+
# maintenance acquisitions are nonblocking, including initially absent stores.
|
|
1083
|
+
# Learning precedes Backups (the coordinator already owns both). Producers
|
|
1084
|
+
# take their store lock then a nonblocking shared source lease before reading
|
|
1085
|
+
# or publishing references; a publisher losing deletion must reject the source.
|
|
1086
|
+
public_class_method def self.with_dependency_locks(opts = {})
|
|
1087
|
+
return yield if opts[:dry_run] || dependency_locks_owned?
|
|
1088
|
+
|
|
1089
|
+
locks = []
|
|
1090
|
+
previous = Thread.current[:pwn_session_dependency_locks]
|
|
1091
|
+
learning = PWN::AI::Agent::Learning.send(:learning_lock, nonblocking: true)
|
|
1092
|
+
raise IOError, 'Dependency writer active: Learning' if learning == :busy
|
|
1093
|
+
|
|
1094
|
+
return PWN::Backups.transaction { with_dependency_locks(opts.merge(backup: false)) { yield } } if opts[:backup] && !PWN::Backups.active? # rubocop:disable Style/ExplicitBlockArgument -- public module contract accepts only the options hash
|
|
1095
|
+
|
|
1096
|
+
root = File.join(Dir.home, '.pwn')
|
|
1097
|
+
paths = [File.join(File.dirname(PWN::Plugins::Findings::FILE), '.findings-write.lock'),
|
|
1098
|
+
File.join(root, '.swarm-continuations.lock'), "#{PWN::Memory::MEMORY_FILE}.write.lock",
|
|
1099
|
+
"#{PWN::AI::Agent::Mistakes::MISTAKES_FILE}.write.lock"]
|
|
1100
|
+
# The index scans HOME; explicit writer paths may be overridden by callers.
|
|
1101
|
+
paths.concat(%w[.findings-write.lock memory.json.write.lock mistakes.json.write.lock].map { |name| File.join(root, name) })
|
|
1102
|
+
paths << File.join(root, '.learning-write.lock') unless File.dirname(PWN::AI::Agent::Learning::LEARNING_FILE) == root
|
|
1103
|
+
paths = paths.uniq.sort
|
|
1104
|
+
paths.each do |path|
|
|
1105
|
+
FileUtils.mkdir_p(File.dirname(path), mode: 0o700)
|
|
1106
|
+
raise IOError, 'Unsafe dependency lock directory' unless File.realpath(File.dirname(path)) == File.expand_path(File.dirname(path))
|
|
1107
|
+
|
|
1108
|
+
lock = File.open(path, File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) # rubocop:disable Style/FileOpen -- transaction owns all handles
|
|
1109
|
+
locks << lock
|
|
1110
|
+
raise IOError, 'Dependency writer active' unless lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
1111
|
+
end
|
|
1112
|
+
Thread.current[:pwn_session_dependency_locks] = { pid: Process.pid, thread: Thread.current, root: root, locks: locks }
|
|
1113
|
+
yield
|
|
1114
|
+
ensure
|
|
1115
|
+
if locks
|
|
1116
|
+
Thread.current[:pwn_session_dependency_locks] = previous
|
|
1117
|
+
locks.reverse_each(&:close)
|
|
1118
|
+
PWN::AI::Agent::Learning.send(:learning_unlock, lock: learning) if learning && learning != :busy
|
|
1119
|
+
end
|
|
1120
|
+
end
|
|
1121
|
+
|
|
1122
|
+
private_class_method def self.dependency_locks_owned?
|
|
1123
|
+
owner = Thread.current[:pwn_session_dependency_locks]
|
|
1124
|
+
owner && owner[:pid] == Process.pid && owner[:thread] == Thread.current &&
|
|
1125
|
+
owner[:root] == File.join(Dir.home, '.pwn') && owner[:locks].none?(&:closed?)
|
|
1126
|
+
end
|
|
1127
|
+
|
|
1067
1128
|
# Supported Method Parameters::
|
|
1068
1129
|
# PWN::Sessions.delete(
|
|
1069
1130
|
# session_id: 'required',
|
|
@@ -1071,6 +1132,8 @@ module PWN
|
|
|
1071
1132
|
# )
|
|
1072
1133
|
# Refuses deletion of pinned sessions (hot/gold/mistake/current) unless force:true.
|
|
1073
1134
|
public_class_method def self.delete(opts = {})
|
|
1135
|
+
return with_dependency_locks(backup: true) { delete(opts) } unless dependency_locks_owned?
|
|
1136
|
+
|
|
1074
1137
|
sid = opts[:session_id].to_s
|
|
1075
1138
|
raise 'ERROR: session_id required' if sid.to_s.empty?
|
|
1076
1139
|
raise ArgumentError, 'Invalid session ID' if File.basename(sid) != sid || sid.include?("\0") || sid == '.' || sid == '..'
|
|
@@ -1082,17 +1145,86 @@ module PWN
|
|
|
1082
1145
|
raise IOError, "Session #{sid} is active" unless File.identical?(lock, lock_path) && lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
1083
1146
|
|
|
1084
1147
|
unless force
|
|
1085
|
-
pins = protected_session_ids(current_session_id: opts[:current_session_id])
|
|
1148
|
+
pins = protected_session_ids(current_session_id: opts[:current_session_id], hot_days: opts[:hot_days], include_activity: false)
|
|
1086
1149
|
raise "ERROR: refusing to delete protected session #{sid.inspect} (pinned by HOT_DAYS/gold/mistakes/current; pass force:true)" if pins.include?(sid.to_s)
|
|
1087
1150
|
end
|
|
1088
1151
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1152
|
+
paths = [path, support_path(kind: :metadata, session_id: sid, read_only: true)].select { |file| File.exist?(file) || File.symlink?(file) }
|
|
1153
|
+
return true if paths.empty?
|
|
1154
|
+
|
|
1155
|
+
progress = { session_id: sid, state: 'prepared', deleted_paths: [], remaining_paths: paths.dup }
|
|
1156
|
+
journal = opts[:deletion_progress] || deletion_journal(session_id: sid, paths: paths)
|
|
1157
|
+
journal.call(progress)
|
|
1158
|
+
paths.each do |file|
|
|
1159
|
+
File.unlink(file)
|
|
1160
|
+
progress[:deleted_paths] << file
|
|
1161
|
+
progress[:remaining_paths].delete(file)
|
|
1162
|
+
journal.call(progress)
|
|
1163
|
+
end
|
|
1164
|
+
progress[:state] = 'committed'
|
|
1165
|
+
journal.call(progress)
|
|
1091
1166
|
true
|
|
1167
|
+
rescue StandardError, Interrupt, SystemExit => e
|
|
1168
|
+
if progress && journal
|
|
1169
|
+
progress[:state] = 'interrupted'
|
|
1170
|
+
progress[:error] = e.class.name
|
|
1171
|
+
begin
|
|
1172
|
+
journal.call(progress)
|
|
1173
|
+
rescue StandardError => journal_error
|
|
1174
|
+
progress[:journal_error] = journal_error.class.name
|
|
1175
|
+
end
|
|
1176
|
+
raise PartialDeletion, progress if e.is_a?(StandardError) && progress[:deleted_paths].any?
|
|
1177
|
+
end
|
|
1178
|
+
raise
|
|
1092
1179
|
ensure
|
|
1093
1180
|
lock&.close unless opts[:cleanup_lock]
|
|
1094
1181
|
end
|
|
1095
1182
|
|
|
1183
|
+
# The callback form lets the coordinator use its already verified backup
|
|
1184
|
+
# without duplicating payload I/O or overwriting its multi-session ledger.
|
|
1185
|
+
private_class_method def self.deletion_journal(opts = {})
|
|
1186
|
+
id = opts[:session_id]
|
|
1187
|
+
directory = PWN::Backups.directory(label: 'session-delete')
|
|
1188
|
+
record = { id: id, files: {} }
|
|
1189
|
+
opts[:paths].each do |path|
|
|
1190
|
+
raise IOError, 'Unsafe deletion source' unless File.file?(path) && File.realpath(path) == File.expand_path(path)
|
|
1191
|
+
|
|
1192
|
+
bytes = File.binread(path)
|
|
1193
|
+
digest = Digest::SHA256.hexdigest(bytes)
|
|
1194
|
+
target = File.join(directory, File.basename(path))
|
|
1195
|
+
atomic_publish(path: target, bytes: bytes)
|
|
1196
|
+
raise IOError, 'Deletion backup mismatch' unless Digest::SHA256.file(target).hexdigest == digest && File.binread(path) == bytes
|
|
1197
|
+
|
|
1198
|
+
record[:files][File.basename(path)] = { sha256: digest, size: bytes.bytesize }
|
|
1199
|
+
end
|
|
1200
|
+
ledger = File.join(directory, 'ledger.json')
|
|
1201
|
+
lambda do |progress|
|
|
1202
|
+
progress[:ledger] = ledger
|
|
1203
|
+
record[:deletion] = progress
|
|
1204
|
+
record[:deleted] = progress[:state] == 'committed'
|
|
1205
|
+
deleted = progress[:deleted_paths].any? { |path| path.end_with?("/#{id}.jsonl") }
|
|
1206
|
+
atomic_publish(path: ledger, bytes: JSON.generate(state: progress[:state], dry_run: false, records: [record], deleted_ids: deleted ? [id] : []))
|
|
1207
|
+
end
|
|
1208
|
+
end
|
|
1209
|
+
|
|
1210
|
+
private_class_method def self.atomic_publish(opts = {})
|
|
1211
|
+
path = opts[:path]
|
|
1212
|
+
temporary = "#{path}.#{SecureRandom.hex(12)}.tmp"
|
|
1213
|
+
identity = nil
|
|
1214
|
+
File.open(temporary, File::WRONLY | File::CREAT | File::EXCL | File::NOFOLLOW, 0o600) do |file|
|
|
1215
|
+
identity = [file.stat.dev, file.stat.ino]
|
|
1216
|
+
file.write(opts[:bytes])
|
|
1217
|
+
file.flush
|
|
1218
|
+
file.fsync
|
|
1219
|
+
raise IOError, 'Atomic temporary changed' unless File.identical?(file, temporary)
|
|
1220
|
+
|
|
1221
|
+
File.rename(temporary, path)
|
|
1222
|
+
File.open(File.dirname(path), File::RDONLY, &:fsync)
|
|
1223
|
+
end
|
|
1224
|
+
ensure
|
|
1225
|
+
remove_owned_temporary(path: temporary, identity: identity) if identity
|
|
1226
|
+
end
|
|
1227
|
+
|
|
1096
1228
|
# Supported Method Parameters::
|
|
1097
1229
|
# stats = PWN::Sessions.stats
|
|
1098
1230
|
public_class_method def self.stats
|
|
@@ -1127,7 +1259,7 @@ module PWN
|
|
|
1127
1259
|
current = opts[:current_session_id].to_s
|
|
1128
1260
|
current = PWN::Env.dig(:ai, :session_id).to_s if current.empty? && defined?(PWN::Env)
|
|
1129
1261
|
|
|
1130
|
-
dir =
|
|
1262
|
+
dir = SESSIONS_DIR
|
|
1131
1263
|
files = Dir.glob(File.join(dir, '*.jsonl'))
|
|
1132
1264
|
before_bytes = files.sum { |f| File.size(f) }
|
|
1133
1265
|
now = Time.now.utc
|
|
@@ -1142,6 +1274,17 @@ module PWN
|
|
|
1142
1274
|
deleted = []
|
|
1143
1275
|
compacted = []
|
|
1144
1276
|
protected_n = 0
|
|
1277
|
+
skipped = {}
|
|
1278
|
+
partial_deletions = []
|
|
1279
|
+
remove = lambda do |entry|
|
|
1280
|
+
delete(session_id: entry[:id], current_session_id: current, hot_days: hot_days) unless dry
|
|
1281
|
+
deleted << entry[:id]
|
|
1282
|
+
rescue PartialDeletion => e
|
|
1283
|
+
partial_deletions << e.result
|
|
1284
|
+
deleted << entry[:id] if e.result[:deleted_paths].include?(entry[:path])
|
|
1285
|
+
rescue IOError, RuntimeError, SystemCallError => e
|
|
1286
|
+
skipped[entry[:id]] = e.class.name
|
|
1287
|
+
end
|
|
1145
1288
|
|
|
1146
1289
|
# Classify
|
|
1147
1290
|
entries = files.map do |path|
|
|
@@ -1162,8 +1305,7 @@ module PWN
|
|
|
1162
1305
|
aged = e[:age] > retain_days
|
|
1163
1306
|
next unless stub || aged
|
|
1164
1307
|
|
|
1165
|
-
|
|
1166
|
-
FileUtils.rm_f([e[:path], support_path(kind: :metadata, session_id: e[:id])]) unless dry
|
|
1308
|
+
remove.call(e)
|
|
1167
1309
|
end
|
|
1168
1310
|
|
|
1169
1311
|
# Refresh remaining after deletes
|
|
@@ -1174,9 +1316,8 @@ module PWN
|
|
|
1174
1316
|
unpinned = remaining.reject { |e| e[:pinned] }.sort_by { |e| e[:mtime] }
|
|
1175
1317
|
over = remaining.size - max_files
|
|
1176
1318
|
unpinned.first(over).each do |e|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
remaining.delete(e)
|
|
1319
|
+
remove.call(e)
|
|
1320
|
+
remaining.delete(e) if deleted.include?(e[:id])
|
|
1180
1321
|
end
|
|
1181
1322
|
end
|
|
1182
1323
|
|
|
@@ -1199,10 +1340,17 @@ module PWN
|
|
|
1199
1340
|
after_bytes = after_files.sum { |f| File.size(f) }
|
|
1200
1341
|
|
|
1201
1342
|
{
|
|
1343
|
+
state: if partial_deletions.empty?
|
|
1344
|
+
dry ? 'planned' : 'committed'
|
|
1345
|
+
else
|
|
1346
|
+
'interrupted'
|
|
1347
|
+
end,
|
|
1348
|
+
partial_deletions: partial_deletions,
|
|
1202
1349
|
deleted: deleted.length,
|
|
1203
1350
|
deleted_ids: deleted.first(30),
|
|
1204
1351
|
compacted: compacted.length,
|
|
1205
1352
|
compacted_ids: compacted.first(30),
|
|
1353
|
+
skipped: skipped,
|
|
1206
1354
|
protected: protected_n,
|
|
1207
1355
|
remaining: after_files.size,
|
|
1208
1356
|
bytes_before: before_bytes,
|
|
@@ -1222,10 +1370,12 @@ module PWN
|
|
|
1222
1370
|
Dir.glob(File.join(SESSIONS_DIR, '*.jsonl')).each { |path| pins[File.basename(path, '.jsonl')] = true } if references[:errors].any?
|
|
1223
1371
|
pins[opts[:current_session_id].to_s] = true unless opts[:current_session_id].to_s.empty?
|
|
1224
1372
|
|
|
1225
|
-
#
|
|
1226
|
-
|
|
1373
|
+
# Activity is a pin, but callers already holding the exclusive cleanup
|
|
1374
|
+
# lease omit their own lock from this probe and still recheck dependencies.
|
|
1375
|
+
Dir.glob(File.join(SESSIONS_DIR, '*.jsonl')).each do |path|
|
|
1376
|
+
id = File.basename(path, '.jsonl')
|
|
1227
1377
|
age = (now - File.mtime(path).utc) / 86_400.0
|
|
1228
|
-
pins[
|
|
1378
|
+
pins[id] = true if age <= hot_days || (opts[:include_activity] != false && active?(session_id: id))
|
|
1229
1379
|
end
|
|
1230
1380
|
|
|
1231
1381
|
# Learning gold
|
|
@@ -1271,15 +1421,26 @@ module PWN
|
|
|
1271
1421
|
end
|
|
1272
1422
|
|
|
1273
1423
|
private_class_method def self.compact_transcript!(opts = {})
|
|
1424
|
+
return with_dependency_locks { compact_transcript!(opts) } unless opts[:dry_run] || dependency_locks_owned?
|
|
1425
|
+
|
|
1274
1426
|
path = opts[:path]
|
|
1275
1427
|
tool_max = opts[:tool_max] || TOOL_CONTENT_MAX
|
|
1276
1428
|
asst_max = opts[:assistant_content_max] || opts[:asst_max] || ASSISTANT_CONTENT_MAX
|
|
1277
1429
|
dry = opts[:dry_run] ? true : false
|
|
1278
1430
|
return false unless File.exist?(path)
|
|
1279
1431
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1432
|
+
id = File.basename(path, '.jsonl')
|
|
1433
|
+
return false if dry && active?(session_id: id)
|
|
1434
|
+
|
|
1435
|
+
unless dry
|
|
1436
|
+
lease = File.open(support_path(kind: :lease, session_id: id), File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) # rubocop:disable Style/FileOpen -- exclusive maintenance lease closed in ensure
|
|
1437
|
+
return false unless lease.flock(File::LOCK_EX | File::LOCK_NB)
|
|
1438
|
+
|
|
1439
|
+
writer = File.open("#{path}.write.lock", File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) # rubocop:disable Style/FileOpen -- held through atomic replace; ensure closes it
|
|
1440
|
+
writer.flock(File::LOCK_EX)
|
|
1441
|
+
end
|
|
1442
|
+
return false if protected_session_ids(hot_days: 0, include_activity: dry).include?(id)
|
|
1443
|
+
|
|
1283
1444
|
lines = File.readlines(path)
|
|
1284
1445
|
rows = lines.map { |line| JSON.parse(line, symbolize_names: true) }
|
|
1285
1446
|
return false if rows.empty?
|
|
@@ -1307,7 +1468,9 @@ module PWN
|
|
|
1307
1468
|
return changed if dry || !changed
|
|
1308
1469
|
|
|
1309
1470
|
tmp = "#{path}.#{SecureRandom.hex(12)}.tmp"
|
|
1471
|
+
identity = nil
|
|
1310
1472
|
File.open(tmp, File::WRONLY | File::CREAT | File::EXCL | File::NOFOLLOW, 0o600) do |f|
|
|
1473
|
+
identity = [f.stat.dev, f.stat.ino]
|
|
1311
1474
|
f.flock(File::LOCK_EX)
|
|
1312
1475
|
rows.each { |e| f.puts(JSON.generate(e)) }
|
|
1313
1476
|
f.flush
|
|
@@ -1317,7 +1480,7 @@ module PWN
|
|
|
1317
1480
|
File.open(File.dirname(path), File::RDONLY, &:fsync)
|
|
1318
1481
|
true
|
|
1319
1482
|
ensure
|
|
1320
|
-
|
|
1483
|
+
remove_owned_temporary(path: tmp, identity: identity) if identity
|
|
1321
1484
|
writer&.close
|
|
1322
1485
|
deactivate(lease: lease)
|
|
1323
1486
|
end
|
|
@@ -1334,7 +1497,13 @@ module PWN
|
|
|
1334
1497
|
|
|
1335
1498
|
dir = File.join(Dir.home, '.pwn', 'exports')
|
|
1336
1499
|
FileUtils.mkdir_p(dir)
|
|
1500
|
+
raise IOError, 'Unsafe session export directory' unless File.realpath(dir) == File.expand_path(dir)
|
|
1501
|
+
|
|
1337
1502
|
dest = File.join(dir, "#{sid}.tar.gz")
|
|
1503
|
+
archive = File.join(dir, ".#{sid}.#{SecureRandom.hex(12)}.tmp")
|
|
1504
|
+
archive_file = File.open(archive, File::RDWR | File::CREAT | File::EXCL | File::NOFOLLOW, 0o600) # rubocop:disable Style/FileOpen -- reserved through tar and atomic publication
|
|
1505
|
+
archive_identity = [archive_file.stat.dev, archive_file.stat.ino]
|
|
1506
|
+
archive_file.flock(File::LOCK_EX)
|
|
1338
1507
|
manifest = {}
|
|
1339
1508
|
Dir.mktmpdir do |tmp|
|
|
1340
1509
|
lines = transcript.map { |row| JSON.generate(PWN::Redaction.redact(value: row)) }
|
|
@@ -1351,35 +1520,128 @@ module PWN
|
|
|
1351
1520
|
end
|
|
1352
1521
|
end
|
|
1353
1522
|
File.write(File.join(tmp, 'manifest.json'), JSON.generate(manifest))
|
|
1354
|
-
system('tar', '-czf',
|
|
1523
|
+
raise IOError, 'Session export tar failed' unless system('tar', '-czf', '-', '-C', tmp, '.', out: archive_file)
|
|
1524
|
+
raise IOError, 'Session export temporary changed' unless File.identical?(archive_file, archive)
|
|
1525
|
+
|
|
1526
|
+
archive_file.flush
|
|
1527
|
+
archive_file.fsync
|
|
1528
|
+
File.rename(archive, dest)
|
|
1355
1529
|
end
|
|
1356
1530
|
{ path: dest, session_id: sid, manifest: manifest }
|
|
1531
|
+
ensure
|
|
1532
|
+
archive_file&.close
|
|
1533
|
+
remove_owned_temporary(path: archive, identity: archive_identity) if archive_identity
|
|
1357
1534
|
end
|
|
1358
1535
|
|
|
1359
1536
|
public_class_method def self.retain(opts = {})
|
|
1537
|
+
return with_dependency_locks { retain(opts) } unless dependency_locks_owned?
|
|
1538
|
+
|
|
1360
1539
|
days = (opts[:days] || 90).to_i
|
|
1361
1540
|
cutoff = Time.now - (days * 86_400)
|
|
1362
|
-
|
|
1541
|
+
records = []
|
|
1363
1542
|
pins = protected_session_ids(hot_days: 0)
|
|
1364
1543
|
Dir[File.join(sessions_dir, '*.jsonl')].each do |path|
|
|
1365
|
-
next if pins.include?(File.basename(path, '.jsonl'))
|
|
1366
|
-
next if File.mtime(path) > cutoff
|
|
1367
|
-
|
|
1368
1544
|
id = File.basename(path, '.jsonl')
|
|
1545
|
+
next if pins.include?(id) || File.mtime(path) > cutoff
|
|
1546
|
+
|
|
1369
1547
|
File.open(support_path(kind: :lease, session_id: id), File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) do |lock|
|
|
1370
1548
|
next unless lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
1371
1549
|
next unless File.file?(path) && File.mtime(path) <= cutoff
|
|
1550
|
+
next if protected_session_ids(hot_days: 0, include_activity: false).include?(id)
|
|
1551
|
+
|
|
1552
|
+
records << retain_transcript(path: path, session_id: id)
|
|
1553
|
+
end
|
|
1554
|
+
end
|
|
1555
|
+
{ deleted: 0, gzipped: records.count { |row| row[:state] == 'committed' }, days: days, records: records }
|
|
1556
|
+
end
|
|
1372
1557
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1558
|
+
private_class_method def self.retain_transcript(opts = {})
|
|
1559
|
+
path = opts[:path]
|
|
1560
|
+
id = opts[:session_id]
|
|
1561
|
+
archive = "#{path}.gz"
|
|
1562
|
+
directory = File.join(Dir.home, '.pwn', 'maintenance', 'retention')
|
|
1563
|
+
ancestor = directory
|
|
1564
|
+
ancestor = File.dirname(ancestor) until File.exist?(ancestor) || File.symlink?(ancestor)
|
|
1565
|
+
raise IOError, 'Unsafe retention journal directory' unless File.realpath(ancestor) == File.expand_path(ancestor)
|
|
1566
|
+
|
|
1567
|
+
FileUtils.mkdir_p(directory, mode: 0o700)
|
|
1568
|
+
ledger = File.join(directory, "#{Digest::SHA256.hexdigest(path)}.json")
|
|
1569
|
+
source_hash = Digest::SHA256.file(path).hexdigest
|
|
1570
|
+
report = { id: id, state: 'prepared', ledger: ledger }
|
|
1571
|
+
if File.exist?(archive) || File.symlink?(archive)
|
|
1572
|
+
raise IOError, 'Unowned retention archive' unless File.file?(ledger) && !File.symlink?(ledger)
|
|
1573
|
+
|
|
1574
|
+
record = JSON.parse(File.binread(ledger), symbolize_names: true)
|
|
1575
|
+
raise IOError, 'Unverified retention archive' unless record[:version] == 1 && record[:path] == path && record[:source_sha256] == source_hash &&
|
|
1576
|
+
record[:archive] == archive && !File.symlink?(archive) && File.file?(archive) &&
|
|
1577
|
+
[File.stat(archive).dev, File.stat(archive).ino] == record[:identity] && Digest::SHA256.file(archive).hexdigest == record[:sha256]
|
|
1578
|
+
|
|
1579
|
+
owned_record = true
|
|
1580
|
+
else
|
|
1581
|
+
lines = File.readlines(path)
|
|
1582
|
+
keep = lines.length <= 40 ? lines : lines.first(20) + lines.last(20)
|
|
1583
|
+
temporary = "#{path}.#{SecureRandom.hex(12)}.tmp"
|
|
1584
|
+
identity = nil
|
|
1585
|
+
File.open(temporary, File::WRONLY | File::CREAT | File::EXCL | File::NOFOLLOW, 0o600) do |file|
|
|
1586
|
+
identity = [file.stat.dev, file.stat.ino]
|
|
1587
|
+
file.flock(File::LOCK_EX)
|
|
1588
|
+
gz = Zlib::GzipWriter.new(file)
|
|
1589
|
+
begin
|
|
1376
1590
|
keep.each { |line| gz.write("#{JSON.generate(PWN::Redaction.redact(value: JSON.parse(line)))}\n") }
|
|
1591
|
+
gz.finish
|
|
1592
|
+
file.flush
|
|
1593
|
+
file.fsync
|
|
1594
|
+
ensure
|
|
1595
|
+
gz.close unless gz.closed?
|
|
1377
1596
|
end
|
|
1378
|
-
|
|
1379
|
-
|
|
1597
|
+
end
|
|
1598
|
+
record = { version: 1, state: 'prepared', path: path, source_sha256: source_hash, archive: archive,
|
|
1599
|
+
temporary: temporary, identity: identity, sha256: Digest::SHA256.file(temporary).hexdigest }
|
|
1600
|
+
atomic_publish(path: ledger, bytes: JSON.generate(record))
|
|
1601
|
+
owned_record = true
|
|
1602
|
+
File.link(temporary, archive) # No-clobber publication, even for unrelated valid gzip files.
|
|
1603
|
+
File.open(File.dirname(archive), File::RDONLY, &:fsync)
|
|
1604
|
+
end
|
|
1605
|
+
record[:state] = 'published'
|
|
1606
|
+
atomic_publish(path: ledger, bytes: JSON.generate(record))
|
|
1607
|
+
raise IOError, 'Retention source changed' unless Digest::SHA256.file(path).hexdigest == source_hash
|
|
1608
|
+
|
|
1609
|
+
File.delete(path)
|
|
1610
|
+
File.open(File.dirname(path), File::RDONLY, &:fsync)
|
|
1611
|
+
record[:state] = 'committed'
|
|
1612
|
+
atomic_publish(path: ledger, bytes: JSON.generate(record))
|
|
1613
|
+
report.merge(state: 'committed')
|
|
1614
|
+
rescue StandardError => e
|
|
1615
|
+
# A published verified archive is recoverable; unknown/preexisting archives
|
|
1616
|
+
# are explicit conflicts. Neither outcome may starve later candidates.
|
|
1617
|
+
state = owned_record ? 'interrupted' : 'conflict'
|
|
1618
|
+
if owned_record
|
|
1619
|
+
record[:state] = 'interrupted'
|
|
1620
|
+
record[:error] = e.class.name
|
|
1621
|
+
begin
|
|
1622
|
+
atomic_publish(path: ledger, bytes: JSON.generate(record))
|
|
1623
|
+
rescue StandardError => journal_error
|
|
1624
|
+
report[:journal_error] = journal_error.class.name
|
|
1380
1625
|
end
|
|
1381
1626
|
end
|
|
1382
|
-
{
|
|
1627
|
+
(report || { id: id, ledger: ledger }).merge(state: state, error: e.class.name)
|
|
1628
|
+
ensure
|
|
1629
|
+
remove_owned_temporary(path: temporary, identity: identity) if identity
|
|
1630
|
+
remove_owned_temporary(path: record[:temporary], identity: record[:identity]) if owned_record && record[:state] == 'committed' && record[:temporary].to_s.match?(/\A#{Regexp.escape(path)}\.[0-9a-f]{24}\.tmp\z/)
|
|
1631
|
+
end
|
|
1632
|
+
|
|
1633
|
+
private_class_method def self.remove_owned_temporary(opts = {})
|
|
1634
|
+
path = opts[:path]
|
|
1635
|
+
identity = opts[:identity]
|
|
1636
|
+
return unless path && identity && File.exist?(path) && !File.symlink?(path)
|
|
1637
|
+
|
|
1638
|
+
File.open(path, File::RDONLY | File::NOFOLLOW) do |file|
|
|
1639
|
+
next unless file.flock(File::LOCK_EX | File::LOCK_NB) && File.identical?(file, path) && [file.stat.dev, file.stat.ino] == identity
|
|
1640
|
+
|
|
1641
|
+
File.unlink(path)
|
|
1642
|
+
end
|
|
1643
|
+
rescue IOError, SystemCallError
|
|
1644
|
+
nil
|
|
1383
1645
|
end
|
|
1384
1646
|
|
|
1385
1647
|
public_class_method def self.redact(opts = {})
|
|
@@ -1394,7 +1656,7 @@ module PWN
|
|
|
1394
1656
|
public_class_method def self.help
|
|
1395
1657
|
puts "USAGE:
|
|
1396
1658
|
# Run sessions dir and return its result
|
|
1397
|
-
#{self}.sessions_dir
|
|
1659
|
+
#{self}.sessions_dir(read_only: 'optional - resolve the session directory without creating it')
|
|
1398
1660
|
|
|
1399
1661
|
# Run list and return its result
|
|
1400
1662
|
#{self}.list(include_hidden: 'optional - include unretained sessions for diagnostics and explicit resume', current_session_id: 'optional - include this active session regardless of naming classification', references: 'optional - precomputed structural dependency index')
|
|
@@ -1411,6 +1673,9 @@ module PWN
|
|
|
1411
1673
|
# Index exact dependency file paths and uncertain stores for cleanup and listing.
|
|
1412
1674
|
#{self}.dependency_index
|
|
1413
1675
|
|
|
1676
|
+
# Serialize reference checks and mutation with cooperating publishers.
|
|
1677
|
+
#{self}.with_dependency_locks(dry_run: 'optional - yield without creating or acquiring locks for read-only plans', backup: 'optional - acquire the backup transaction before other dependency locks') { ... }
|
|
1678
|
+
|
|
1414
1679
|
# Hold a shared per-session OS lease until deactivate or process exit.
|
|
1415
1680
|
#{self}.activate(
|
|
1416
1681
|
session_id: 'required - stable transcript identifier for activity ownership',
|
|
@@ -1494,7 +1759,9 @@ module PWN
|
|
|
1494
1759
|
session_id: 'required - session id value consumed by #delete',
|
|
1495
1760
|
force: 'optional - Boolean bypass pin policy (default false)',
|
|
1496
1761
|
current_session_id: 'optional - current session id value consumed by #delete',
|
|
1497
|
-
|
|
1762
|
+
hot_days: 'optional - hot-file protection window, defaults HOT_DAYS',
|
|
1763
|
+
cleanup_lock: 'optional - already-held per-session exclusive cleanup lock',
|
|
1764
|
+
deletion_progress: 'optional - coordinator callback persisting prepared and per-file deletion states with its verified recovery backup'
|
|
1498
1765
|
)
|
|
1499
1766
|
|
|
1500
1767
|
# Run stats and return its result
|
|
@@ -1516,6 +1783,7 @@ module PWN
|
|
|
1516
1783
|
now: 'optional - now value consumed by #protected_session_ids (defaults to Time.now.utc)',
|
|
1517
1784
|
hot_days: 'optional - hot days value consumed by #protected_session_ids',
|
|
1518
1785
|
retain_days: 'optional - retain days value consumed by #protected_session_ids',
|
|
1786
|
+
include_activity: 'optional - include held activity leases; default true, false only while the caller holds an exclusive cleanup lease',
|
|
1519
1787
|
current_session_id: 'optional - current session id value consumed by #protected_session_ids'
|
|
1520
1788
|
)
|
|
1521
1789
|
|
data/lib/pwn/setup.rb
CHANGED
|
@@ -804,7 +804,7 @@ module PWN
|
|
|
804
804
|
io.puts
|
|
805
805
|
io.puts 'Re-checking…'
|
|
806
806
|
io.puts
|
|
807
|
-
result = check(io: io)
|
|
807
|
+
result = check(io: io, profile: profile)
|
|
808
808
|
{ profile: profile, ran: ran, check: result }
|
|
809
809
|
rescue StandardError => e
|
|
810
810
|
raise e
|
|
@@ -898,7 +898,7 @@ module PWN
|
|
|
898
898
|
io.puts ' backup ~/.pwn/backup (shared seven-generation store)'
|
|
899
899
|
io.puts
|
|
900
900
|
|
|
901
|
-
unless yes
|
|
901
|
+
unless yes || dry_run
|
|
902
902
|
io.print 'Proceed? [y/N] '
|
|
903
903
|
io.flush
|
|
904
904
|
ans = $stdin.gets.to_s.strip.downcase
|
|
@@ -1015,7 +1015,8 @@ module PWN
|
|
|
1015
1015
|
engine = opts[:engine]
|
|
1016
1016
|
return false unless engine
|
|
1017
1017
|
|
|
1018
|
-
PWN::Env.dig(:ai, engine.to_sym, :key).to_s
|
|
1018
|
+
key = PWN::Env.dig(:ai, engine.to_sym, :key).to_s.strip
|
|
1019
|
+
!key.empty? && !key.match?(/\A(?:required|optional)\b|REDACTED/i)
|
|
1019
1020
|
rescue StandardError
|
|
1020
1021
|
false
|
|
1021
1022
|
end
|
data/lib/pwn/version.rb
CHANGED
|
@@ -15,13 +15,25 @@ module PWN
|
|
|
15
15
|
# )
|
|
16
16
|
|
|
17
17
|
public_class_method def self.open(opts = {})
|
|
18
|
-
browser_obj = PWN::Plugins::TransparentBrowser.open(opts)
|
|
18
|
+
browser_obj = PWN::Plugins::TransparentBrowser.open(opts.dup)
|
|
19
19
|
|
|
20
20
|
browser = browser_obj[:browser]
|
|
21
21
|
browser.goto('https://app.cobalt.io')
|
|
22
22
|
|
|
23
23
|
browser_obj
|
|
24
24
|
rescue StandardError => e
|
|
25
|
+
begin
|
|
26
|
+
if browser_obj
|
|
27
|
+
# Teardown independently: a driver failure must not strand Tor.
|
|
28
|
+
begin
|
|
29
|
+
PWN::Plugins::TransparentBrowser.close(browser_obj: browser_obj.reject { |key| key == :tor_obj })
|
|
30
|
+
ensure
|
|
31
|
+
PWN::Plugins::TransparentBrowser.close(browser_obj: { tor_obj: browser_obj[:tor_obj] }) if browser_obj[:tor_obj]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
rescue StandardError => cleanup_error
|
|
35
|
+
warn "Browser cleanup failed (#{cleanup_error.class}); preserving the navigation error"
|
|
36
|
+
end
|
|
25
37
|
raise e
|
|
26
38
|
end
|
|
27
39
|
|
|
@@ -46,7 +58,7 @@ module PWN
|
|
|
46
58
|
if password.nil?
|
|
47
59
|
password = PWN::Plugins::AuthenticationHelper.mask_password
|
|
48
60
|
else
|
|
49
|
-
password = opts[:password].to_s
|
|
61
|
+
password = opts[:password].to_s
|
|
50
62
|
end
|
|
51
63
|
mfa = opts[:mfa]
|
|
52
64
|
|
data/lib/pwn/www/bing.rb
CHANGED
|
@@ -11,13 +11,25 @@ module PWN
|
|
|
11
11
|
# )
|
|
12
12
|
|
|
13
13
|
public_class_method def self.open(opts = {})
|
|
14
|
-
browser_obj = PWN::Plugins::TransparentBrowser.open(opts)
|
|
14
|
+
browser_obj = PWN::Plugins::TransparentBrowser.open(opts.dup)
|
|
15
15
|
|
|
16
16
|
browser = browser_obj[:browser]
|
|
17
17
|
browser.goto('https://www.bing.com')
|
|
18
18
|
|
|
19
19
|
browser_obj
|
|
20
20
|
rescue StandardError => e
|
|
21
|
+
begin
|
|
22
|
+
if browser_obj
|
|
23
|
+
# Teardown independently: a driver failure must not strand Tor.
|
|
24
|
+
begin
|
|
25
|
+
PWN::Plugins::TransparentBrowser.close(browser_obj: browser_obj.reject { |key| key == :tor_obj })
|
|
26
|
+
ensure
|
|
27
|
+
PWN::Plugins::TransparentBrowser.close(browser_obj: { tor_obj: browser_obj[:tor_obj] }) if browser_obj[:tor_obj]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
rescue StandardError => cleanup_error
|
|
31
|
+
warn "Browser cleanup failed (#{cleanup_error.class}); preserving the navigation error"
|
|
32
|
+
end
|
|
21
33
|
raise e
|
|
22
34
|
end
|
|
23
35
|
|