[PR #4207] [MERGED] Fix overly permissive file permissions (os.ModePerm / 0777) #5627

Closed
opened 2026-10-31 20:48:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4207
Author: @hobostay
Created: 5/10/2026
Status: ✅ Merged
Merged: 5/10/2026
Merged by: @MHSanaei

Base: main ← Head: fix/file-permissions


📝 Commits (1)

  • 492188d Fix overly permissive file permissions (os.ModePerm)

📊 Changes

3 files changed (+4 additions, -7 deletions)

View changed files

📝 database/db.go (+1 -2)
📝 web/service/server.go (+1 -2)
📝 xray/process.go (+2 -3)

📄 Description

Summary

  • Replace os.ModePerm / fs.ModePerm (0777) with appropriate restrictive permissions across four file operations
  • Remove unused "io/fs" imports from the affected files

Changes

File Operation Before After
database/db.go DB directory creation 0777 0755
xray/process.go Xray config write 0777 0644
xray/process.go Crash report write 0777 0644
web/service/server.go Binary extraction 0777 0755

Why

os.ModePerm (0777) makes files and directories world-writable, violating the principle of least privilege. An attacker with local access could modify the Xray configuration file or crash reports, or inject malicious binaries.

  • 0755 for directories: owner read/write/execute, group/others read/execute
  • 0644 for regular files: owner read/write, group/others read-only
  • 0755 for executable binaries: owner read/write/execute, group/others read/execute

Test plan

  • Verify the application starts normally
  • Verify Xray config file is created with 0644 permissions
  • Verify crash reports are created with 0644 permissions
  • Verify binary extraction produces files with 0755 permissions

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/4207 **Author:** [@hobostay](https://github.com/hobostay) **Created:** 5/10/2026 **Status:** ✅ Merged **Merged:** 5/10/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/file-permissions` --- ### 📝 Commits (1) - [`492188d`](https://github.com/MHSanaei/3x-ui/commit/492188db12d15632375f78cefcfcbc627963e246) Fix overly permissive file permissions (os.ModePerm) ### 📊 Changes **3 files changed** (+4 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `database/db.go` (+1 -2) 📝 `web/service/server.go` (+1 -2) 📝 `xray/process.go` (+2 -3) </details> ### 📄 Description ## Summary - Replace `os.ModePerm` / `fs.ModePerm` (0777) with appropriate restrictive permissions across four file operations - Remove unused `"io/fs"` imports from the affected files ## Changes | File | Operation | Before | After | |------|-----------|--------|-------| | `database/db.go` | DB directory creation | 0777 | 0755 | | `xray/process.go` | Xray config write | 0777 | 0644 | | `xray/process.go` | Crash report write | 0777 | 0644 | | `web/service/server.go` | Binary extraction | 0777 | 0755 | ## Why `os.ModePerm` (0777) makes files and directories **world-writable**, violating the principle of least privilege. An attacker with local access could modify the Xray configuration file or crash reports, or inject malicious binaries. - **0755** for directories: owner read/write/execute, group/others read/execute - **0644** for regular files: owner read/write, group/others read-only - **0755** for executable binaries: owner read/write/execute, group/others read/execute ## Test plan - [ ] Verify the application starts normally - [ ] Verify Xray config file is created with 0644 permissions - [ ] Verify crash reports are created with 0644 permissions - [ ] Verify binary extraction produces files with 0755 permissions 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:48:15 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5627
No description provided.