-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Remove global clients #1014
base: datarace-on-config-access
Are you sure you want to change the base?
Remove global clients #1014
Conversation
} | ||
log.Printf("Saving %s on %s", extraFile.Filename, path) | ||
|
||
err = os.MkdirAll(filepath.Dir(path), 0744) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 1 month ago
To fix the problem, we need to ensure that the user-provided filenames in extraFile.Filename
do not contain any path separators or parent directory references. This can be done by validating the filenames before using them to construct file paths. We will add a validation step to check for the presence of "/" or "\" or ".." in the filenames and reject the input if any are found.
-
Copy modified lines R137-R141
@@ -136,2 +136,7 @@ | ||
for _, extraFile := range data.ExtraFiles { | ||
if strings.Contains(extraFile.Filename, "/") || strings.Contains(extraFile.Filename, "\\") || strings.Contains(extraFile.Filename, "..") { | ||
c.String(http.StatusBadRequest, "Invalid file name") | ||
return | ||
} | ||
|
||
path, err := utilities.SafeJoin(tmpdir, extraFile.Filename) |
return | ||
} | ||
|
||
err = os.WriteFile(path, extraFile.Hex, 0644) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 1 month ago
To fix the problem, we need to ensure that the extraFile.Filename
does not contain any path traversal characters or sequences. We can achieve this by validating the filename to ensure it does not contain any path separators ("/" or "\") or ".." sequences. This validation should be done before using the filename to construct the path.
- Add a validation step to check that
extraFile.Filename
does not contain any path separators or ".." sequences. - If the validation fails, return an error response to the client.
- If the validation passes, proceed with the existing logic to save the file.
-
Copy modified lines R137-R140
@@ -136,2 +136,6 @@ | ||
for _, extraFile := range data.ExtraFiles { | ||
if strings.Contains(extraFile.Filename, "/") || strings.Contains(extraFile.Filename, "\\") || strings.Contains(extraFile.Filename, "..") { | ||
c.String(http.StatusBadRequest, "Invalid file name") | ||
return | ||
} | ||
path, err := utilities.SafeJoin(tmpdir, extraFile.Filename) |
Please check if the PR fulfills these requirements
before creating one)