Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Golang: Mark filepath.IsLocal as a tainted-path sanitizer guard#20056

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
smowton merged 3 commits intomainfromsmowton/fix/tainted-path-is-local
Jul 15, 2025

Conversation

smowton
Copy link
Contributor

No description provided.

@CopilotCopilotAI review requested due to automatic review settingsJuly 15, 2025 13:47
@smowtonsmowton requested a review froma team as acode ownerJuly 15, 2025 13:47
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds support for recognizingfilepath.IsLocal() as a path traversal sanitizer in the Go security analysis. The change treats calls to this function as a security guard that can prevent path traversal attacks when the function returns true.

  • Adds a newIsLocalCheck sanitizer guard class to recognizefilepath.IsLocal() calls
  • Updates test cases to include an example of the sanitized path usage pattern

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

FileDescription
go/ql/lib/semmle/go/security/TaintedPathCustomizations.qllImplements theIsLocalCheck class to treatfilepath.IsLocal() as a tainted-path sanitizer guard
go/ql/test/query-tests/Security/CWE-022/TaintedPath.goAdds test case demonstrating proper usage offilepath.IsLocal() as a security check

Comment on lines +98 to +99
if filepath.IsLocal(tainted_path) {
data, _ = ioutil.ReadFile(tainted_path)
Copy link
Preview

CopilotAIJul 15, 2025

Choose a reason for hiding this comment

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

The filepath.IsLocal() check alone may not provide complete path traversal protection. Consider combining it with additional validation such as filepath.Clean() or checking against an allowlist of permitted directories, as IsLocal() only validates that the path doesn't escape the current directory but doesn't prevent access to sensitive files within it.

Suggested change
iffilepath.IsLocal(tainted_path) {
data,_=ioutil.ReadFile(tainted_path)
cleanedPath:=filepath.Clean(tainted_path)
allowedDir:="/allowed/directory"// Replace with the actual allowed directory
iffilepath.IsLocal(cleanedPath)&&strings.HasPrefix(cleanedPath,allowedDir) {
data,_=ioutil.ReadFile(cleanedPath)

Copilot uses AI. Check for mistakes.

owen-mc
owen-mc previously approved these changesJul 15, 2025
@smowtonsmowton merged commit16f3fc6 intomainJul 15, 2025
17 checks passed
@smowtonsmowton deleted the smowton/fix/tainted-path-is-local branchJuly 15, 2025 16:40
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@owen-mcowen-mcowen-mc approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@smowton@owen-mc

[8]ページ先頭

©2009-2025 Movatter.jp