Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new rule which detects when a file is created with os.Create but the configured permissions are less than 0666 #1020

Merged
merged 2 commits into from
Sep 25, 2023

Conversation

ccojocar
Copy link
Member

It seems that the os.Create will create by default a file with 0666 permissions.

This should be detected when the configured permissions are less than 0666. By default will not detect this case
unless the more restrictive mode is configured.

fixes #1019

…t the configured permissions are less than 0666

It seems that the os.Create will create by default a file with 0666 permissions.

This should be detected when the configured permissions are less than 0666. By default will not detect this case
unless the more restrictive mode is configured.

Signed-off-by: Cosmin Cojocar <[email protected]>
Signed-off-by: Cosmin Cojocar <[email protected]>
@ccojocar ccojocar merged commit 4def3a4 into master Sep 25, 2023
6 checks passed
@ldez
Copy link
Contributor

ldez commented Oct 9, 2023

Hello @ccojocar,

Is it expected to use a retire rule code (G307)?

gosec/README.md

Line 160 in 3952187

- G307: Poor file permissions used when creating a file with os.Create

gosec/README.md

Line 176 in 3952187

- G307: Deferring a method which returns an error - causing more inconvenience than fixing a security issue, despite the details from this [blog post](https://www.joeshaw.org/dont-defer-close-on-writable-files/)

@ccojocar ccojocar deleted the os-create-rule branch May 13, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

G306 can be easily bypassed by os.Create
2 participants