Skip to content

Fix CWE-73: File Manipulation #75

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Yummikko
Copy link

CWE Description

File Manipulation vulnerability occurs when an application allows user input to control or influence paths or file names that are used in file system operations. This could allow an attacker to access or modify system files or other files that are critical to the application. For example, an application may give an attacker the ability to overwrite a specified file or run with a configuration controlled by the attacker

@Yummikko Yummikko force-pushed the fix_file_manipulation branch from 49c1a5c to 7e46b12 Compare May 15, 2025 11:57
Signed-off-by: Aleksandra Chyła <[email protected]>
@Yummikko Yummikko force-pushed the fix_file_manipulation branch from 6a89d38 to 6333f32 Compare May 15, 2025 12:34
Comment on lines -428 to +437
fileName := deviceDir + "/ownership_voucher.txt"
fileName := filepath.Clean(filepath.Join(deviceDir, "ownership_voucher.txt"))
outils.Verbose("POST /api/orgs/%s/fdo/vouchers: creating %s ...", deviceOrgId, fileName)
if err := ioutil.WriteFile(filepath.Clean(fileName), bodyBytes, 0644); err != nil {
if err := os.WriteFile(fileName, bodyBytes, 0644); err != nil {
http.Error(w, "could not create "+fileName+": "+err.Error(), http.StatusInternalServerError)
return
}

// Create orgid.txt file to identify what org this device/voucher is part of
fileName = deviceDir + "/orgid.txt"
fileName = filepath.Clean(filepath.Join(deviceDir, "orgid.txt"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use Clean() where the deviceDir is defined (line 422) and skip subsequent Clean() calls.

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.

2 participants