azukaar / Cosmos-Server

☁️ The Most Secure and Easy Selfhosted Home Server. Take control of your data and privacy without sacrificing security and stability (Authentication, anti-DDOS, anti-bot)
https://cosmos-cloud.io
Other
3.44k stars 118 forks source link

Fix: Wrong file permission for database file store #240

Closed george-radu-cs closed 5 months ago

george-radu-cs commented 5 months ago

Bug description:

When establishing a database file store, incorrect permission modes are set due to the absence of octal representation.

Assigning the value 700 as the mode does not correspond to the intended (I think) permissions -rwx------ (700), but rather results in --w-r-xr-- (254). This occurs because in Go, the os.FileMode doesn’t require the value to be provided only in octal format.

Test made to see the difference:

package main

import (
        "os"
)

func main() {
        content := []byte("Hello world!\n")
        os.WriteFile("700", content, 700)
        os.WriteFile("0700", content, 0700)
}

and ls -lah output showcasing the difference:

drwxr-xr-x  5 georgeradu  staff   160B Apr  6 21:37 .
drwxr-xr-x  4 georgeradu  staff   128B Apr  6 21:35 ..
-rwx------  1 georgeradu  staff    13B Apr  6 21:37 0700
--w-r-xr--  1 georgeradu  staff    13B Apr  6 21:37 700
-rw-r--r--  1 georgeradu  staff   157B Apr  6 21:37 main.go
cla-bot[bot] commented 5 months ago

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, add yourself to the .clabot file as contributor, as a way of signing the CLA.

azukaar commented 5 months ago

Thanks for the fix, please the CLA and I can merge this (it will continue to complain because it's only checking master but that's ok)

cla-bot[bot] commented 5 months ago

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, add yourself to the .clabot file as contributor, as a way of signing the CLA.

azukaar commented 5 months ago

Thanks!