fix: reject ingest URIs that name the data root - #374
Conversation
Signed-off-by: Antonio Carlos Borges Neto <84680581+fafnirkyu@users.noreply.github.com>
|
👋 Hi @fafnirkyu — thank you so much for your first contribution to HFlow! A maintainer will review your pull request as soon as possible. In the meantime:
💡 Tip: one open pull request per contributor at a time. Issues with an assignee are taken; everything else is fair game. We are excited to have you here and appreciate your help making the project better! 🙌 |
kstonekuan
left a comment
There was a problem hiding this comment.
LGTM, merging. Welcome.
One condition and three parametrize rows is exactly the right size for this, and both directions are held. Removing the condition:
the data-root condition removed -> 9 failed
test_ingest_rejects_invalid_uri_before_making_http_requests (SDK)
test_ingest_rejects_uris_outside_data_root (CLI)
test_ingest_rejects_absolute_and_escaping_uris_before_any_runtime (server)
All three boundaries, which is the property #314 built the shared parser for.
The other direction matters just as much here, because the obvious "simplification" of this check is to refuse anything whose normalized form differs from the candidate. That would be wrong, and it is caught:
over-refusal: any normalization difference rejected -> test_ingest_accepts_safe_uris_unchanged fails
So the non-goal from #314 about not rewriting a/../b.mcap into a different persisted identity is protected in both directions rather than just documented. Confirmed the behaviour directly:
refused: '.' './' 'a/..' 'a/b/../..' '..' '../x' '/abs/x'
accepted: 'a/../b.mcap' -> 'a/../b.mcap' (spelling kept, not rewritten to 'b.mcap')
' a/../b.mcap ' -> 'a/../b.mcap' (trimmed, per DoD 3 on #314)
'CC:/notadrive.mcap' -> unchanged (two letters is not a drive)
Gate clean with current main merged in: ruff check, ruff format --check, ty check, 1436 passed / 6 skipped.
One optional thing, not worth a push. normalized == "." or normalized == ".." reads a little easier as normalized in {".", ".."}. Ruff does not flag it and the meaning is identical, so take it or leave it.
Closes #369. If you want another, the starter list is here: https://github.com/Hebbian-Robotics/hflow/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22
Fixes #369
Summary
.,./,a/.., anda/b/../...a/../b.mcapunchanged.Validation
uv run ruff check .uv run ruff format --check .uv run ty checkuv run pytest -q— 1417 passed, 6 skipped