Files
SenMeshNet/docs/research/sftp-local-publish-safety.md
zhaolei 2f9f8da48e
Some checks failed
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
Initial commit: NetMesh smart ops platform with 3D topology, inspection reports, RCA and AI ops assistant
2026-10-15 13:53:04 +08:00

2.4 KiB

Local transfer publication safety audit

Confirmed defect

The completed download moves an existing destination to a backup, checks that its pathname is unoccupied, then renames the prepared download into place. Another program can save to that pathname between the check and rename. The rename overwrites those bytes and successful cleanup deletes the original backup. Backup restoration and post-publication rollback have equivalent races.

Real filesystem regressions inject concurrent creation at the actual final publication and restoration boundary. Both lose concurrent contents on the baseline. An explicitly absent destination can also appear after validation and be incorrectly moved aside. These tests fail before the change.

Contract and design

  • Prepared data and an original backup remain private sibling files.
  • Publication and backup restoration use the same no-overwrite primitive.
  • On hardlink-capable filesystems, linking publishes complete bytes atomically.
  • On filesystems without that operation, exclusive open plus writes through the owned handle preserves compatibility without overwriting another destination. This fallback exposes partial contents during copying; it does not promise atomic visibility. It never deletes the destination pathname on failure.
  • Failed fallback copies retain complete prepared data and original backup, with their locations in the error. A concurrent replacement is never removed.
  • Successful publication is the commit boundary. Cancellation checked before it restores the original where possible. Cancellation arriving after publication does not attempt unsafe pathname-based rollback.
  • A validated absent target is distinct from an omitted validation callback.
  • This change does not claim to prevent another program writing through an already-open handle or provide durable power-loss transactions.

Validation

The focused tests cover publication and restoration boundary races, absent validation, normal mode-preserving replacement, early/late cancellation, unsupported-hardlink fallback and write failure with concurrent replacement. Real unsupported-filesystem hardware has not been exercised; the fallback uses real files with hardlink capability failure injected.

Related audit themes: #3186 replacement attributes and #3213 interrupted recovery. These reports do not establish the cause of this separately reproduced defect.