Skip to content

Audit findings: refuse non-finite STLs, bound uploads, localhost-only compose - #9

Merged
Rigare merged 2 commits into
mainfrom
fix/audit-findings
Oct 17, 2026
Merged

Rigare merged 2 commits into
mainfrom
fix/audit-findings

Conversation

@Rigare

@Rigare Rigare commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Hardening from the audit findings: untrusted input and the default deployment. There are two commits. The first is the hardening itself. The second makes each piece do what its commit message claims and adds tests, because a review found that two of the four changes did nothing or made things worse.

Input

  • STL files with a NaN or infinite coordinate are refused before trimesh touches them. trimesh's processing drops such a vertex and hangs its triangle on vertex 0. A file with one bad triangle loaded fine, holding a triangle it does not contain, so a check after loading could never fire. load_mesh now loads unprocessed, checks, then calls process(). These files get their own message, "contains invalid coordinates (NaN or infinite)", instead of "contains no triangles". That includes files made only of NaN, which used to get the old message.
  • _check_grid_size closes the NaN gap. A NaN count failed voxels > MAX_GRID_VOXELS and passed. It is the old one-line count plus math.isfinite. The first commit's integer early exit is reverted: the float rounding it guarded against cannot happen (whole numbers stay exact in a float up to 2**53, the limit is 1e9), and its error message reported a partial voxel count (1e10 for a grid of 1e15).

Web app

  • One run takes at most 10 uploads (app_helpers.MAX_UPLOAD_FILES). This bounds the work of a single click, not memory: Streamlit already holds every upload when the run starts.
  • A missing translation key is logged as a warning (inlayer.i18n) instead of failing silently.
  • The first commit's chmod 0600 on the temporary upload files is removed: NamedTemporaryFile already creates them with that mode.

Deployment

  • compose.yaml publishes the port on 127.0.0.1 only. The app has no authentication. README and the compose comment explain how to open it to a trusted network ("8501:8501") and that anything public needs a reverse proxy with authentication.

Worth a look before merging

  • Behaviour change for LAN setups: anyone running the bundled compose file on a NAS or home server loses access from other devices until they change the port mapping.
  • load_mesh now defers trimesh's processing. For finite files the result is the same mesh trimesh's default load builds (byte-identical vertices, faces and normals over boxes, spheres, cylinders, two bodies, degenerate and duplicate faces, binary and ASCII). A test pins this.

Tests (513 → 524 in the Docker test stage)

  • Grid bound at exactly the limit and one layer above it, a NaN extent, and the full voxel count in the message.
  • Non-finite STLs, entirely NaN/Inf or one bad triangle, in the pipeline and in the upload preview. Finite files load as with trimesh's default.
  • Upload limit: 11 files stop before the pipeline, 10 reach it. Missing translation key is logged. Compose port is localhost-only. The Docker test stage now copies compose.yaml for this test.
  • Mutation check: the first commit's inlayer.py and main's each fail the tests aimed at them. With processing back at load time, exactly the 5 NaN tests fail. Without the later process(), 20 tests fail.

Verified

  • docker build --target test .: 524 passed, 1 skipped. The runtime image builds and docker compose config is valid.

🤖 Generated with Claude Code

Marco Wittwer and others added 2 commits October 17, 2026 11:41
- inlayer: reject non-finite vertices in load_mesh, use integer
  early-exit in _check_grid_size to avoid float rounding bypass
- i18n: log warning on missing translation key
- app: chmod uploads 0600, limit to 10 files with error
- compose: bind port to 127.0.0.1 with auth hint
- load_mesh loads unprocessed, refuses a NaN or infinite coordinate with
  its own message, then processes. trimesh's processing dropped such a
  vertex and hung its triangle on vertex 0, so the check never fired and
  one bad triangle loaded as a different, real-looking one. A finite file
  still yields exactly the mesh of trimesh's default load.
- _check_grid_size: back to the one-line count, plus an isfinite check.
  NaN was the only gap - whole numbers stay exact in a float far beyond
  the 1e9 limit - and the early exit reported a partial voxel count.
- app: MAX_UPLOAD_FILES in app_helpers instead of a literal 10; its
  comment says it bounds the work of a run, not upload memory. The chmod
  is gone: NamedTemporaryFile creates the file with mode 0600 already.
- README and compose.yaml describe the localhost-only port and how to
  open it to the local network; README names the 10-file limit.
- Tests for every change on this branch. The Docker test stage copies
  compose.yaml for the port test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rigare
Rigare merged commit 03f2016 into main Oct 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant