Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<script` before the upload. Those strings were confirmed blocked on one host's WAF, but some hosts
exempt the upload routes, so CVE text in a findings file was dropped though the WAF would accept it. With the flag
the file is sent; if the WAF does refuse it (a 403 with no request id), the upload still drops only that file. The
plan notes that the check is off. `--plan` takes the flag too.
- **`wiz_inventory`**, the Wiz cloud resource inventory, as a pipeline fetcher (`kind: inventory`, `id_scheme:
wiz-resource-id`). One record per resource from `cloudResourcesV2` under `payload.data`, keyed by the Wiz resource
id, with its cloud ID (`external_id`), account, region, type, IPs, OS, image, environment and owner, and internet
Expand Down
1 change: 1 addition & 0 deletions docs/cli_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ batches.
| `--owner USERNAME` | Where a stack has one channel per owner, uses this owner's channel. It replaces the owner the run recorded. |
| `--with-validators` | Syncs validators for the evidence sets of the run before the batches go out. If the sync fails, the upload sends no batch. With `--dry-run`, it only names the sync it would do. |
| `--no-tags` | Skips the default custom tags for this upload. |
| `--no-waf-check` | Sends files that hold a string the production WAF has blocked (`../`, `/bin/sh`, `<script`) instead of dropping them before the upload. If the WAF does block one, the upload drops that file and sends the rest. The plan notes that the check is off. |
| `--config`, `-f`, `-o` | Choose the uploader config, the manifest, and the output directory. |
| `--json` | Prints the summary: the legacy counts, plus `dropped`, `plan`, `entries`, `outcomes`, `batches` and, with `--with-validators`, `validators`. |

Expand Down
2 changes: 1 addition & 1 deletion docs/uploader_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ results, see [verify validators](suggest_validator_guide.md#5-verify-in-paramify
| `batches are off for this workspace (…); every entry is sent direct, as before batches` | This is a note, not an error. The workspace has no batches, so the upload sends every entry direct. |
| An entry shows `held` | A temporary failure stopped the batch. Run the same upload again. |
| `… was rejected in Paramify; collect again to send new evidence` | A person rejected this run's batch in the app. The upload does not send the same evidence again. Collect again: the new run makes a new batch. |
| A file shows `blocked by the production WAF` | The evidence holds a string the WAF rejects (`../`, `/bin/sh`, `<script`). The upload sent the rest. Remove the string and collect again. |
| A file shows `blocked by the production WAF: '…'` | The upload's own check found a string the WAF has rejected (`../`, `/bin/sh`, `<script`), so it did not send the file. The upload sent the rest. Your workspace's WAF may not block it (upload routes on some hosts are exempt): run `paramify upload --no-waf-check` to send the file. If the WAF does reject it, the upload drops it and shows `blocked by the production WAF` with no string. |
| Validators attach to `EVD-…`, not your remapped set | Validator sync uses the registry's reference IDs. Attach them on the set's **Validators** tab → **Manage Selection**. |
| `No fetchers in the manifest …` from `scripts sync` | It found none in `manifest.yaml` at the repo root. Name your manifest, or pass `--all`. |
| The run also collected scan reports | `paramify upload` sends evidence only. Send reports with the [issues uploader](../uploaders/paramify_issues/README.md). |
Expand Down
12 changes: 9 additions & 3 deletions framework/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,7 @@ def plan_upload(
with_validators: bool = False,
manifest_path: Optional[Path] = None,
owner: Optional[str] = None,
waf_check: bool = True,
) -> Plan:
"""The upload plan for one run directory; nothing is written.

Expand All @@ -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,
)


Expand All @@ -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.

Expand All @@ -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,
)


Expand Down
7 changes: 5 additions & 2 deletions framework/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"


Expand Down Expand Up @@ -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', '<script'); a real WAF 403 still drops only that file"),
plan: bool = typer.Option(False, "--plan", help="Read the workspace and print the plan; apply nothing"),
stack: Optional[str] = typer.Option(None, "--stack", help="Paramify stack (id or name) for every entry in this upload, over the one the manifest recorded"),
owner: Optional[str] = typer.Option(None, "--owner", help="Paramify username whose channel to use when a stack has one channel per owner, over the one the manifest recorded"),
Expand All @@ -1490,7 +1492,8 @@ def upload_cmd(
upload_fn=api.upload_run,
noun="file",
log_name="upload_log.json",
upload_kwargs={"custom_tags": not no_tags, "stack": stack, "owner": owner, "with_validators": with_validators},
upload_kwargs={"custom_tags": not no_tags, "stack": stack, "owner": owner, "with_validators": with_validators,
"waf_check": not no_waf_check},
kind="evidence",
manifest=file,
plan_fn=api.plan_upload,
Expand Down
10 changes: 9 additions & 1 deletion framework/sync/providers/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
warning: a direct upload built nothing. A pipeline entry on a set with
validators is refused, unless this run's batch is already submitted or
approved (then it is a no-op);
4. WAF: a file the production WAF would block is dropped at plan time.
4. WAF: a file the production WAF would block is dropped at plan time,
unless the pre-check is off (`paramify upload --no-waf-check`).

An entry is sent direct (the route before batches: no batch, no submit) when
the workspace has no batches or the entry says `delivery: direct`; then it
Expand Down Expand Up @@ -93,6 +94,8 @@
PIPELINE_DIRECT_SENT = "sent direct: this workspace has no batches; the pipeline runs the pre-batch way"
BATCHES_OFF = "batches are off for this workspace"
DELIVERY_DIRECT = "delivery: direct"
WAF_CHECK_OFF = ("WAF pre-check off (--no-waf-check): files that hold '../', '/bin/sh' or '<script' are "
"sent as they are; if the WAF does block one, the upload drops that file and sends the rest")
DIRECT = "DIRECT" # the payload target of an entry sent direct
_BATCH_TARGETS = ("ARTIFACT_REQUEST", "EVIDENCE")
_FAILING = ("FAIL", "ERROR")
Expand Down Expand Up @@ -337,8 +340,11 @@ def __init__(
today: Callable[[], date] = date.today,
on_event: Optional[Callable[[dict], None]] = None,
capability: Optional[Capability] = None,
waf_check: bool = True,
) -> 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
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 17 additions & 6 deletions framework/sync/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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}")
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.

Expand All @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions tests/test_api_upload_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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; <script> in PoC"}
build(run, {"a.json": env(fetcher="x"), "b.json": bad}, [inv("x", ["a.json", "b.json"])])
events: List[Dict[str, Any]] = []
out = api.upload_run(run, root, on_event=events.append, waf_check=False)
assert (out["uploaded"], out["dropped"], out["errors"]) == (2, 0, 0)
assert sorted(file_events(events)) == [("a.json", "uploaded"), ("b.json", "uploaded")]
assert out["plan"]["notes"] == [WAF_CHECK_OFF]


def test_no_waf_check_reaches_the_offline_plan(no_env, root, tmp_path):
run = tmp_path / "run-1"
run.mkdir()
bad = env(fetcher="x")
bad["payload"] = {"cmd": "/bin/sh -c x"}
build(run, {"a.json": env(fetcher="x"), "b.json": bad}, [inv("x", ["a.json", "b.json"])])
plan = api.plan_upload(run, root, online=False, waf_check=False)
assert plan.notes == [WAF_CHECK_OFF]
[d] = [a for a in plan.actions if a.provider == "delivery"]
assert d.payload["dropped"] == [] and len(d.payload["files"]) == 2


def test_preflight_stays_offline_and_keeps_its_shape(no_env, root, tmp_path, monkeypatch):
monkeypatch.setattr(client_mod.requests, "Session", lambda: pytest.fail("preflight built a session"))
pf = api.upload_preflight(two_files(tmp_path), root, dry_run=True)
Expand Down
18 changes: 17 additions & 1 deletion tests/test_cli_upload_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from framework.cli import app
from framework.paramify.client import ApiError, ErrorKind
from framework.sync import upload as upload_mod
from framework.sync.model import Plan
from tests.test_api_upload_engine import fake, no_env, root, submits, two_files # noqa: F401 (fixtures)

runner = CliRunner()
Expand Down Expand Up @@ -188,12 +189,27 @@ def fake_upload(run_dir, root, config_path, **kw):
monkeypatch.setattr(api, "upload_run", fake_upload)
monkeypatch.setattr(api, "sync_validators", lambda *a, **k: pytest.fail("synced after the upload"))
res = cli("upload", str(two_files(tmp_path)), "--dry-run", "--stack", "Prod", "--owner", "alice",
"--with-validators", "--no-tags")
"--with-validators", "--no-tags", "--no-waf-check")
assert res.exit_code == 0, res.output
assert seen["stack"] == "Prod" and seen["with_validators"] is True and seen["custom_tags"] is False
assert seen["waf_check"] is False
assert seen["owner"] == "alice"


def test_no_waf_check_reaches_the_plan(no_env, tmp_path, monkeypatch): # noqa: F811
seen: Dict[str, Any] = {}

def fake_plan(run_dir, _root, config_path, **kw):
seen.update(kw)
return Plan()

monkeypatch.setenv(paramify_auth.UPLOAD_TOKEN_ENV, "tok")
monkeypatch.setattr(api, "plan_upload", fake_plan)
res = cli("upload", str(two_files(tmp_path)), "--plan", "--no-waf-check")
assert res.exit_code == 0, res.output
assert seen["waf_check"] is False


def test_stack_override_is_applied(fake, tmp_path): # noqa: F811
st1, st2 = fake.add_stack("Prod"), fake.add_stack("Gov")
ev = fake.add_evidence("EVD-X", channels=[st1.id, st2.id])
Expand Down
8 changes: 8 additions & 0 deletions tests/test_provider_delivery_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,14 @@ def test_files_waf_match_dropped(tmp_path):
assert drop["reason"].startswith("blocked by the production WAF") and "'../'" in drop["reason"]


def test_waf_check_off_sends_a_matching_file(tmp_path):
bad = write_file(tmp_path, "bad.json", payload={"cmd": "cd ../etc; /bin/bash", "html": "<script>"})
[a] = DeliveryProvider(today=lambda: TODAY, waf_check=False).diff(
[entry(tmp_path, files=("a.json", bad))], {"aws_x": observed(evidence())})
assert a.verb == "deliver" and a.payload["dropped"] == []
assert [f["original_file_name"] for f in a.payload["files"]] == ["a.json", "bad.json"]


def test_all_files_dropped_creates_no_batch(tmp_path):
bad = write_file(tmp_path, "bad.json", payload={"html": "<script>x</script>"})
a = plan_one(entry(tmp_path, files=(bad,)), observed(evidence(CH_P)))
Expand Down
Loading