Skip to content

Commit f0cfc3e

Browse files
committed
Harden permissions on tmp dir and socket
1 parent 23fb899 commit f0cfc3e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/file_manager.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const std = @import("std");
22
const fs = std.fs;
3+
const posix = std.posix;
34
const log = std.log.scoped(.file_manager);
45

56
pub const FileManager = struct {
@@ -21,6 +22,11 @@ pub const FileManager = struct {
2122
else => return err,
2223
};
2324

25+
// Harden permissions on the base directory so only the user can access it
26+
posix.fchmodat(posix.AT.FDCWD, base_path, 0o700, 0) catch |chmod_err| {
27+
log.warn("Failed to set permissions 0700 on {s}: {}", .{ base_path, chmod_err });
28+
};
29+
2430
// Transfer ownership if we allocated, otherwise dupe the provided slice
2531
const base_dir: []u8 = if (owned_path) |p| p else try allocator.dupe(u8, base_path);
2632

src/main.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ pub fn main() !void {
122122
.kernel_backlog = 128,
123123
});
124124

125+
std.posix.fchmodat(std.posix.AT.FDCWD, socket_path, 0o600, 0) catch |chmod_err| {
126+
log.warn("Failed to set permissions 0600 on socket {s}: {}", .{ socket_path, chmod_err });
127+
};
128+
125129
log.info("RMate Launcher {} listening on Unix socket: {s}", .{ build_options.version, socket_path });
126130
break :blk unix_listener;
127131
} else blk: {

0 commit comments

Comments
 (0)