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

Go dynamic input as array, items not considered dynamic input #362

Closed
elsapet opened this issue Apr 4, 2024 · 2 comments
Closed

Go dynamic input as array, items not considered dynamic input #362

elsapet opened this issue Apr 4, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@elsapet
Copy link
Collaborator

elsapet commented Apr 4, 2024

Description & Reproduction

If we have an array of strings passed to a function, for example, and we assign the first element to a variable, we do not consider this variable to be dynamic input.

Expected Behavior

The following code, for example, should flag our filereadtaint rule:

func someFunc(args []string) {
  filepath := args[0]
  os.Open(filepath) // dynamic input passed as filename
}

Actual Behavior

The above code does not flag our filereadtaint rule because filepath := args[0] is not considered dynamic input

Possible Fix

Your Environment

  • Operating System and version:
  • Output of 'bearer version':
bearer version: 0.00.0
sha: xxx
@elsapet elsapet added the bug Something isn't working label Apr 4, 2024
@elsapet
Copy link
Collaborator Author

elsapet commented Apr 5, 2024

The following are also not considered as dynamic input

func example(insecure string, insecureArgs any, moreInsecureArgs []string) {
	args := []string{"-c", insecure}

	var args2 []string
	for _, a := range insecureArgs {
		switch v := a.(type) {
		case string:
			args = append(args, v)
		default:
			return nil, fmt.Errorf("invalid argument to command: %T", a)
		}
	}

	var args3 := []string{"-f", insecure, "-i"}

	var args4 :=  make([]string, 0)
	args4 = append(args4, "-f "+insecure)

	var args5 := make([]string, 0)
	args5 = append(args5, moreInsecureArgs)
}

@elsapet
Copy link
Collaborator Author

elsapet commented Apr 9, 2024

The array access case is fixed by

Upon inspection, we realised that most of the cases detailed in the comment were missed not because of the array construction, but because of "splatted" args (args...). This is fixed by

@elsapet elsapet self-assigned this Apr 9, 2024
@elsapet elsapet closed this as completed Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant