bamaer commented on code in PR #9419:
URL: https://github.com/apache/hop/pull/9419#discussion_r4547341183


##########
core/src/main/java/org/apache/hop/core/config/ConfigFileSerializer.java:
##########
@@ -80,9 +81,13 @@ private void writeAtomically(Path file, byte[] content) 
throws Exception {
       Files.createDirectories(folder);
     }
     // In the same folder as the file itself: a move is only atomic within one 
file store.
-    Path temporary = Files.createTempFile(folder, 
file.getFileName().toString() + ".", ".tmp");
+    // Not Files.createTempFile: that always creates the file as rw-------, 
and the move would
+    // hand those permissions to the configuration, locking out every other 
user sharing it.
+    Path temporary =
+        Files.createFile(folder.resolve(file.getFileName() + "." + 
UUID.randomUUID() + ".tmp"));
     try {
       Files.write(temporary, content);
+      keepPermissions(file, temporary);

Review Comment:
   **Should fix:** the content goes into the temp file before its permissions 
are set. A `600` config (every hop-config.json that 2.20 saved, and environment 
files holding passwords) is briefly readable under the umask (`644`). If the 
save dies before the move, it stays that way. Setting the permissions first 
avoids this, and the tests still pass with that order:
   ```suggestion
         keepPermissions(file, temporary);
         Files.write(temporary, content);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to