Description
By not being atomic, std::fs::write()
may be a footgun for people trying to create correct/secure code.
As an example, nodejs has a function with same behavior that led to a security risk. In that case creation of the secret token file succeeded but writing to it failed leaving an empty token file which caused application to accept empty authentication token later.
The documentation currently kind of describes the behavior but the implications may not be obvious to people. Adding a note about the risk of empty/corrupted file being left in case of failure could help people avoid issues.
If atomic behavior is undesired due to compatibility reasons, then maybe add another atomic_write()
function and suggest it in write()
doc. This could be done in a crate obviously but maybe the security/robustness benefits are a good reason to put it into std
.
I'm willing to make a PR regardless of the conclusion.