Skip to content

Harden organizer transfers, undo, and compression publication - #2

Merged
JayacharanR merged 12 commits into
mainfrom
codex/audit-file-safety
Nov 14, 2026
Merged

JayacharanR merged 12 commits into
mainfrom
codex/audit-file-safety

Conversation

@JayacharanR

@JayacharanR JayacharanR commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Organizer moves can overwrite colliding targets, undo can remove newer edits, and compression can replace its own input. This first audit-repair phase adds verified private staging, exclusive publication, intent journals, and conflict-aware undo. Organization retains filename variants and names colliding outputs uniquely. Compression refuses existing outputs and overlapping roots. The scan and organize forms also preserve threshold zero. Legacy callers close their journals on return and failure; API Trash requests use independent sessions.

Validation: 65 Python tests pass in the working tree, including the existing API/workflow suite; all 49 added regressions pass from a clean export of the committed tree. Ruff and the frontend production build pass. GitHub Actions passed lint, Rust/Python tests, and the Docker build/smoke test on final head fb915ad: https://github.com/JayacharanR/Clean-Backup/actions/runs/43293216322. Regressions include separate-process collisions, failed/corrupt copies, changed sources, journal failures, interrupted undo, abrupt process exits at three transfer boundaries, and legacy session lifetimes.

Scope and limits: publication requires hard-link support and fails closed otherwise. Old path-only journals require manual review, and abrupt exits may leave private staging files. Classification, CLI duplicate handling, and Trash still need migration to the executor. Deletion plans, API access boundaries, cloud object identity, compression fidelity, and the remaining audit findings are open. See docs/AUDIT_REPAIRS.md for finding-level status. This draft is the first repair phase, not a release-readiness claim.

JayacharanR and others added 12 commits November 13, 2026 00:57
…cording

Commits the pre-existing working-tree changes unchanged so the audit that
follows starts from a recorded baseline: 65 passing Python tests, clean Ruff,
clippy and cargo test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The API has no login, yet it answered every origin with
Access-Control-Allow-Origin: * and listened on all interfaces, so any web page
the user visited could scan a directory, read files from it and delete them.

- Drop wildcard CORS; refuse state-changing requests from another Origin and
  requests addressed to an unexpected Host (DNS rebinding). Loopback names and
  IP literals are always accepted; other names via CLEAN_BACKUP_ALLOWED_HOSTS.
- Listen on 127.0.0.1 by default (CLEAN_BACKUP_HOST); the Docker image keeps
  0.0.0.0 inside the container and compose publishes on loopback unless
  CLEAN_BACKUP_BIND is set. Fix the compose image name (ghcr.io/jayacharanr).
- /api/image serves media types only and never renders undecodable content
  inline; previously it returned any file under a scanned directory.
- Demo mode can only read its sample media folder.
- Watcher PATCH interpolated JSON keys into SQL as column names; restrict to a
  fixed set (same for sync-run updates).
- Escape file names in Drive queries, send a single OAuth state, escape the
  OAuth error page, create credential files owner-only, validate face-crop ids.
- Trash uses the verified, journaled transfer (no silent replace, works across
  filesystems, undoable); malformed selections no longer raise.
- Failed apply/sync jobs are reported as failed; finished jobs are pruned.
- Keep .env and working data out of the Docker build context.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- EXIF DateTimeOriginal, ISO and exposure live in the Exif sub-IFD; only the
  top-level IFD was read, so camera photos were organized by file modification
  time and night detection never saw exposure data.
- Classification apply called the job progress callback with one argument and
  always ended in a TypeError after moving files; it also filed photos under
  the month they were catalogued. It now uses the capture date, the verified
  journaled transfer, and one safe folder name per category.
- Remove CLI prompts that imported src.gdrive_sync, which is not in the
  repository; report partial undo honestly; align the threshold cap with the
  web UI (25).
- Count scanned images in one pass with the scanner's extension rule.
- Demo reset named tables that do not exist, so it never cleared visitor data.
- Close the image handle in the Python hash fallback.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Duplicate scan
- The web scan hashed every image in batches, then handed the paths back to
  Rust, which hashed them all again and decoded each a third time to read its
  dimensions. Hash and pixel count now come from one decode
  (compute_hashes_with_resolution) and grouping works on those results
  (group_hashes) with no file access. Hashes and groups are bit-identical on
  the 320-image benchmark library; scan time fell from 6.03 s to 2.79 s.
- Hashing releases the GIL, so job-status polling is served during a scan.
- 64-bit hashes are compared as single words.
- Build only the image codecs the app scans: the extension shrinks from
  2.46 MB to 1.85 MB and its dependency tree from 195 to 98 entries.

Undo journal
- Every prepare/complete rewrote and fsynced the whole journal, so cost grew
  with the square of the session: organizing 2,000 small files took 61 s and
  undoing 1,000 took 50 s. The journal is now an append-only log with one
  fsynced record per state change (9.4 s and 1.7 s respectively). A record cut
  short by a crash is ignored; a corrupt record is reported; journals in the
  earlier array format remain readable and undoable.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Python (pip-audit against OSV: 84 advisory matches before, none after):
pillow 12.3.0 -> 13.0.0, cryptography 49.0.0 -> 50.0.2, oauthlib 3.3.1 ->
4.0.1, urllib3 2.7.0 -> 2.8.0, werkzeug 3.1.8 -> 3.1.9, pyasn1 0.6.4 -> 0.6.5,
certifi 2026.6.17 -> 2026.10.23. Only these pins changed. The full suite
passes on a clean environment built from the new pins.

Frontend build tooling (npm audit fix, semver-compatible): 8 advisories -> 2.
The remaining two (esbuild, vite dev server) need a Vite major upgrade and do
not affect the built assets; runtime dependencies have none.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- Pin SHA-256 for the three ONNX models (upstream files fetched today match
  the existing copies); a mismatch removes the file and fails the build. The
  script's documentation previously claimed verification it did not perform.
- The delete endpoint refuses non-image files under a scanned folder.
- README: document the network model and new settings; replace claims that
  did not match the code (process pools, parallel compression, working S3,
  name-based duplicate detection, MobileNetV3, an unmeasured 10x figure).
- Fix the phash_rs and web READMEs (non-existent parameters, machine paths).
- Add docs/AUDIT_REPORT.md with findings, measurements and open items.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
.dockerignore listed 'target', which matches only a top-level directory, so
phash_rs/target (1.4 GB locally) was sent to the daemon and copied into the
image. The final 'chown -R /app' then stored a second copy of every
application file, including the 275 MB of models, in a new layer.

Ignore **/target, create the user first and set ownership during COPY. An
image built from this tree shrinks from 6.04 GB to 1.72 GB; the container
passes the health, frontend, request-guard and scan/Trash/undo checks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@JayacharanR
JayacharanR merged commit a9ef246 into main Nov 14, 2026
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