diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ee79711..75eb0837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ schemas and the `paramify` CLI — not the internal code. ### Added +- `paramify upload --no-waf-check` turns off the check that drops a file holding `../`, `/etc/passwd`, `/bin/sh`, + `/bin/bash` or ` Plan: """The upload plan for one run directory; nothing is written. @@ -1913,11 +1914,14 @@ def plan_upload( delivery) that `manifest_path` now sets differently from the run. Without it, the run's own manifest is used; with neither, nothing is compared. The run's settings still apply. + + `waf_check=False` turns off the WAF pre-check: no file is dropped at plan + time for holding a string the production WAF blocks, and the plan says so. """ return _sync_upload.plan_upload( run_dir, root, _upload_config(root, config_path), online=online, stack=stack, only_file=only_file, custom_tags=custom_tags, with_validators=with_validators, - manifest_path=manifest_path, owner=owner, + manifest_path=manifest_path, owner=owner, waf_check=waf_check, ) @@ -1938,6 +1942,7 @@ def upload_run( deprecations: Sequence[str] = (), manifest_path: Optional[Path] = None, owner: Optional[str] = None, + waf_check: bool = True, ) -> dict: """Upload one run directory to Paramify, one batch per manifest entry. @@ -1952,13 +1957,14 @@ def upload_run( `token` and `base_url` (both ahead of the environment) are for callers that already hold them; `deprecations` are notes for `upload_log.json`. `manifest_path` is as for plan_upload: the plan notes the settings it now - sets differently from the run. `stack` and `owner` are as for plan_upload. + sets differently from the run. `stack`, `owner` and `waf_check` are as for + plan_upload. """ return _sync_upload.run_upload( run_dir, root, _upload_config(root, config_path), dry_run=dry_run, on_event=on_event, custom_tags=custom_tags, stack=stack, only_file=only_file, with_validators=with_validators, upload_cfg=upload_cfg, token=token, base_url=base_url, deprecations=deprecations, - manifest_path=manifest_path, owner=owner, + manifest_path=manifest_path, owner=owner, waf_check=waf_check, ) diff --git a/framework/cli.py b/framework/cli.py index 55eec5c0..e62c6bdc 100644 --- a/framework/cli.py +++ b/framework/cli.py @@ -653,7 +653,8 @@ def on_human_event(ev: dict) -> None: raise typer.Exit(0 if summary["ok"] else 1) -_PLAN_KWARGS = frozenset({"stack", "owner", "custom_tags", "with_validators", "only_file", "manifest_path"}) +_PLAN_KWARGS = frozenset({"stack", "owner", "custom_tags", "with_validators", "only_file", "manifest_path", + "waf_check"}) _TOKEN_REJECTED = "Paramify rejected the API token (HTTP 401); check {env}" @@ -1467,6 +1468,7 @@ def upload_cmd( dry_run: bool = typer.Option(False, "--dry-run", help="Resolve and report what would upload; no API calls"), with_validators: bool = typer.Option(False, "--with-validators", help="Before delivery, sync validators for the sets this run produced (create-or-skip)"), no_tags: bool = typer.Option(False, "--no-tags", help="Skip the default custom tags for this run (PARAMIFY_CUSTOM_TAGS=off does the same from the environment)"), + no_waf_check: bool = typer.Option(False, "--no-waf-check", help="Send files that hold strings the production WAF blocked ('../', '/bin/sh', ' None: self._run_state = run_state + # False: send every file and let a real WAF 403 drop it (see Client.classify). + self._waf_check = waf_check self._capability = capability # None: batches are assumed (offline) self._today = today self._on_event = on_event @@ -380,6 +386,8 @@ def _content(self, path: Path, mode: Optional[str] = None) -> bytes: def _scan(self, f: DeliveryFile) -> List[str]: """WAF signatures in what the upload of `f` would send: the bytes, the note and the title.""" + if not self._waf_check: + return [] mode = self._mode_for(f.pipeline) key = (str(f.path), mode) if key not in self._waf_hits: diff --git a/framework/sync/upload.py b/framework/sync/upload.py index 74232980..5bd8e516 100644 --- a/framework/sync/upload.py +++ b/framework/sync/upload.py @@ -42,6 +42,7 @@ from framework.sync.model import Action, Outcome, Plan, SyncContext, Unknown from framework.sync.providers.delivery import ( BATCHES_OFF, + WAF_CHECK_OFF, DeliveryProvider, delivery_mode, ) @@ -143,8 +144,9 @@ class _Setup: def __init__(self, run_dir: Any, config_path: Optional[Path], stack: Optional[str], only_file: Optional[str], *, upload_cfg: Optional[Dict[str, Any]] = None, token: Optional[str] = None, base_url: Optional[str] = None, - owner: Optional[str] = None) -> None: + owner: Optional[str] = None, waf_check: bool = True) -> None: load_dotenv() + self.waf_check = waf_check self.run_dir = Path(run_dir) if not self.run_dir.is_dir(): raise ValueError(f"No run directory to upload: {self.run_dir}") @@ -166,6 +168,12 @@ def __init__(self, run_dir: Any, config_path: Optional[Path], stack: Optional[st # Plan notes the caller adds (see manifest_notes). self.notes: List[str] = [] + def plan_notes(self, root: Path, manifest_path: Optional[Path], stack: Optional[str], + owner: Optional[str]) -> List[str]: + """The manifest notes, then a note when the WAF pre-check is off.""" + notes = manifest_notes(self.run_dir, root, manifest_path, stack, owner) + return notes if self.waf_check else [*notes, WAF_CHECK_OFF] + def client(self) -> Client: token = self.token or resolve_upload_token()[0] if not token: @@ -184,7 +192,8 @@ def providers( on_delivery_event: Optional[Event] = None, capability: Optional[Capability] = None, ) -> Tuple[List[Any], DeliveryProvider]: - delivery = DeliveryProvider(run_state, on_event=on_delivery_event, capability=capability) + delivery = DeliveryProvider(run_state, on_event=on_delivery_event, capability=capability, + waf_check=self.waf_check) providers: List[Any] = [EvidenceSetsProvider(custom_tags, category_display_names(root), self.config)] if with_validators: from framework.api import reference_ids_from_run # api imports this module @@ -232,14 +241,15 @@ def plan_upload( with_validators: bool = False, manifest_path: Optional[Path] = None, owner: Optional[str] = None, + waf_check: bool = True, ) -> Plan: """The plan for uploading `run_dir`. Online it reads the workspace (read-only); offline it needs no token. `manifest_path` is the manifest to compare the run's Paramify settings with (see manifest_notes); without it, the run's own manifest is used. """ - setup = _Setup(run_dir, config_path, stack, only_file, owner=owner) - notes = manifest_notes(setup.run_dir, root, manifest_path, stack, owner) + setup = _Setup(run_dir, config_path, stack, only_file, owner=owner, waf_check=waf_check) + notes = setup.plan_notes(root, manifest_path, stack, owner) reader = None capability: Optional[Capability] = None # offline: no check, no note if online: @@ -487,6 +497,7 @@ def run_upload( deprecations: Sequence[str] = (), manifest_path: Optional[Path] = None, owner: Optional[str] = None, + waf_check: bool = True, ) -> Dict[str, Any]: """Plan and apply the upload of one run; see the module docstring. @@ -502,8 +513,8 @@ def run_upload( """ emit: Event = on_event or (lambda _ev: None) setup = _Setup(run_dir, config_path, stack, only_file, - upload_cfg=upload_cfg, token=token, base_url=base_url, owner=owner) - setup.notes = manifest_notes(setup.run_dir, root, manifest_path, stack, owner) + upload_cfg=upload_cfg, token=token, base_url=base_url, owner=owner, waf_check=waf_check) + setup.notes = setup.plan_notes(root, manifest_path, stack, owner) policy = resolve_tag_policy(setup.config, override_off=None if custom_tags else NO_TAGS) report = _Report(emit, dry_run, Tagger(None, "", policy=policy, display_names=category_display_names(root))) base = {"run_dir": str(setup.run_dir), "base_url": setup.base_url, "dry_run": dry_run, diff --git a/tests/test_api_upload_engine.py b/tests/test_api_upload_engine.py index 5db54ec2..b7b9f274 100644 --- a/tests/test_api_upload_engine.py +++ b/tests/test_api_upload_engine.py @@ -23,6 +23,7 @@ from framework.sync import render from framework.sync import upload as upload_mod from framework.sync.model import Outcome +from framework.sync.providers.delivery import WAF_CHECK_OFF from framework.sync.state import RunState from tests.test_sync_desired import build, env, inv @@ -512,6 +513,31 @@ def test_skips_and_drops_are_counted_and_reported_per_file(fake, root, tmp_path) assert drop["reason"].startswith("blocked by the production WAF") +def test_no_waf_check_sends_the_file_and_notes_it(fake, root, tmp_path): + run = tmp_path / "run-1" + run.mkdir() + bad = env(fetcher="x") + bad["payload"] = {"cve": "fixed in ../lib; spawns /bin/bash; "}) a = plan_one(entry(tmp_path, files=(bad,)), observed(evidence(CH_P)))