Skip to content

Resolve vulnerability: Incorrect permission assignment for critical resource

AI GENERATED PATCH

The suggested code changes were generated by GitLab Duo Vulnerability Resolution, an AI feature. Use this feature with caution. Before you apply the code changes, carefully review and test them, to ensure that they solve the vulnerability, don't harm the functional behavior of your application or introduce new vulnerabilities.

The large language model that generated the suggested code changes was only provided with the affected lines of code, and the vulnerability in that code. It is not aware of any functionality outside of this context.

Please see our documentation for more information about this feature. We'd love to hear your feedback so we can improve on this feature as we work to bring it to general availability.

Description:

The application was found setting file permissions to overly permissive values. Consider using the following values if the application user is the only process to access the file:

  • 0400 - read only access to the file
  • 0200 - write only access to the file
  • 0600 - read/write access to the file

Example creating a file with read/write permissions for the application user:

f, err := os.OpenFile("file.txt", os.O_CREATE, 0600)
if err != nil {
  log.Fatal(err)
}
defer f.Close()
// continue to work with file here

For all other values please see: https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation

Identifiers:

  • Gosec Rule ID G302
  • gosec.G302-1
  • CWE-732
  • A6:2017 - Security Misconfiguration
  • A5:2017 - Broken Access Control
  • A01:2021 - Broken Access Control

Merge request reports