Skip to content

(bugsbash) fixes potential file inclusion via variable#1155

Closed
rahulgrover99 wants to merge 5 commits intobuildpacks:mainfrom
rahulgrover99:fix/file-inclusion
Closed

(bugsbash) fixes potential file inclusion via variable#1155
rahulgrover99 wants to merge 5 commits intobuildpacks:mainfrom
rahulgrover99:fix/file-inclusion

Conversation

@rahulgrover99
Copy link
Copy Markdown
Contributor

Summary

gosec was showing the following warning "Potential file inclusion via variable". This is because we are trying to open files using dynamic variables. Hence, I've cleaned the bad file paths using filepath.Clean()

Output

Before

ioutil.ReadFile(file)

After

ioutil.ReadFile(filepath.Clean(etagFile))

Documentation

  • Should this change be documented?
    • Yes, see #___
    • No

Related

Resolves #___
G304 Potential file inclusion via variable

Signed-off-by: Rahul Grover <rahulgrover99@gmail.com>
Signed-off-by: Rahul Grover <rahulgrover99@gmail.com>
@rahulgrover99 rahulgrover99 requested a review from a team as a code owner May 4, 2021 12:16
@github-actions github-actions Bot added this to the 0.19.0 milestone May 4, 2021
@github-actions github-actions Bot added type/chore Issue that requests non-user facing changes. type/enhancement Issue that requests a new feature or improvement. labels May 4, 2021
@jromero
Copy link
Copy Markdown
Member

jromero commented May 11, 2021

Same issue here @rahulgrover99 (failing tests) :(. Sorry.

Copy link
Copy Markdown
Contributor

@dwillist dwillist left a comment

Choose a reason for hiding this comment

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

Hey @rahulgrover99 appreciate the PR! Looks like there are a few CI failures do to permission bits changing.

Comment thread internal/registry/registry_cache.go Outdated
}

f, err := os.OpenFile(index, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
f, err := os.OpenFile(filepath.Clean(index), os.O_APPEND|os.O_CREATE|os.O_RDWR, 0600)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these permission changes look like they are responsible for the test failures we are seeing

Comment thread testhelpers/testhelpers.go Outdated
}

return os.Chmod(dst, 0775)
return os.Chmod(dst, 0600)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Think we have tests that actually copy executable bits, 0600 is a bit too restrictive.

Comment thread testhelpers/testhelpers.go Outdated
err = os.Chtimes(filepath.Join(dst, fi.Name()), modifiedTime, modifiedTime)
AssertNil(t, err)
err = os.Chmod(filepath.Join(dst, fi.Name()), 0664)
err = os.Chmod(filepath.Join(dst, fi.Name()), 0600)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

permission change may be too restrictive

Comment thread testhelpers/testhelpers.go Outdated
err = os.Chtimes(dst, modifiedTime, modifiedTime)
AssertNil(t, err)
err = os.Chmod(dst, 0775)
err = os.Chmod(dst, 0600)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as above comments

@jromero jromero added status/incomplete Issue or PR that doesn't have enough information provided. and removed type/enhancement Issue that requests a new feature or improvement. labels May 11, 2021
Signed-off-by: Rahul Grover <rahulgrover99@gmail.com>
@github-actions github-actions Bot added the type/enhancement Issue that requests a new feature or improvement. label May 12, 2021
@rahulgrover99
Copy link
Copy Markdown
Contributor Author

I think it might be a good idea to revert the permission changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/incomplete Issue or PR that doesn't have enough information provided. type/chore Issue that requests non-user facing changes. type/enhancement Issue that requests a new feature or improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants