Skip to content
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

Fix static analysis issues #480

Merged
merged 6 commits into from
Aug 20, 2024

Conversation

MatheusFranco99
Copy link
Contributor

Overview

This PR adds fixes for static analysis issues including:

  • file permission issues
  • file inclusion via variable issues

It also adds a nosec comment for a cryptographically insecure PRNG (pseudo-random number generator) used in tests. We use this PRNG (math/rand) since the secure crypto/rand doesn't allow seeding (which is important for consistent tests).

An existing issue with implicit memory aliasing in a for loop will be automatically fixed by the go update to 1.22.

@@ -92,7 +93,7 @@ func writeJsonStateComparison(name, testType string, post interface{}) {

file := filepath.Join(scDir, fmt.Sprintf("%s.json", name))
log.Printf("writing state comparison json: %s\n", file)
if err := os.WriteFile(file, byts, 0644); err != nil {
if err := os.WriteFile(file, byts, 0600); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would update to 0444

The reason is that we don't want anyone writing to the file, to make tests pass/fail.
There's nothing confidential here so might as well let everyone read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I agree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, gosec still complains about 0444:

G306 (CWE-276): Expect WriteFile permissions to be 0600 or less (Confidence: HIGH, Severity: MEDIUM)

Can't it be 0400? Why do we need to allow "read" for group and others?

Copy link
Contributor

@GalRogozinski GalRogozinski Aug 15, 2024

Choose a reason for hiding this comment

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

hmm
if CI passes then it can be 0400 honestly
I just think that there is no confidential information and the SSV repo generate jsons itself.

I just saw no sec concern so you can choose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also don't see security concerns, but gosec complains and I also don't see a reason for the group and others read permission.
Updating it to 0400

@@ -119,7 +120,7 @@ func writeJson(data []byte) {

file := filepath.Join(basedir, "tests.json")
log.Printf("writing spec tests json to: %s\n", file)
if err := os.WriteFile(file, data, 0644); err != nil {
if err := os.WriteFile(file, data, 0600); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -112,7 +113,7 @@ func writeSingleSCJson(path string, testType string, post interface{}) {
}

log.Printf("writing state comparison json: %s\n", file)
if err := os.WriteFile(file, byts, 0644); err != nil {
if err := os.WriteFile(file, byts, 0444); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -156,7 +157,7 @@ func writeJson(data []byte) {
}

// Write the gzipped data to a file
if err := os.WriteFile(file, buf.Bytes(), 0644); err != nil {
if err := os.WriteFile(file, buf.Bytes(), 0444); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -108,7 +109,7 @@ func writeJson(data []byte) {
file := filepath.Join(basedir, "tests.json")

fmt.Printf("writing spec tests json to: %s\n", file)
if err := os.WriteFile(file, data, 0644); err != nil {
if err := os.WriteFile(file, data, 0444); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

just the permissions

@MatheusFranco99 MatheusFranco99 merged commit 9bf4379 into ssvlabs:dev Aug 20, 2024
2 checks passed
@MatheusFranco99 MatheusFranco99 deleted the static-analysis-issues branch August 20, 2024 10:41
GalRogozinski pushed a commit that referenced this pull request Sep 12, 2024
* Solve potential file inclusion via variable

* Fix file permission (0644 to 0600)

* Add nosec comment for PRNG (pseudo-random number generator) used for testing

* Fix lint issue on nil check in []byte type

* Update permission from 0444 to 0600

* Update 0444 to 0400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants