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

G107 fails if behind sanitize function, but not if manually outlined #321

Open
JAicewizard opened this issue May 26, 2019 · 1 comment
Open

Comments

@JAicewizard
Copy link

JAicewizard commented May 26, 2019

Summary

G107 fails if behind sanitize function, but not if function i smanually outlined

Steps to reproduce the behavior

	url, valid := sanitizeURL(url)
	if !valid {
		return errors.New("an invalid URL is provided")
	}
	resp, err := http.Get(url)

func sanitizeURL(URL string) (string, bool) {
	u, err := url.Parse(URL)
	if err != nil || u.Host == "" {
		return "", false

	}

	if u.Scheme != "" {
		u.Scheme = "https"
	}
	return u.String(), true
}

does result in G107 being thrown

	u, err := url.Parse(URL)
	if err != nil || u.Host == "" {
		return errors.New("an invalid URL is provided")

	}
	if u.Scheme != "" {
		u.Scheme = "https"
	}

	resp, err := http.Get(u.String())

does not throw G107

gosec version

latest(master)

Go version (output of 'go version')

1.12.4

Operating system / Environment

linux/amd64

Expected behavior

both should at least behave the same(I assume passing since that's the inlined behavior)

Actual behavior

different behavior depending on if it is inlined

@JAicewizard JAicewizard changed the title G107 fails if behind sanitize function, but not if function i smanually outlined G107 fails if behind sanitize function, but not if manually outlined May 26, 2019
@gcmurphy
Copy link
Member

I think what is happening here is G107 is trying to resolve the url variable to a known constant or basic literal. This mechanism is currently pretty basic and unable to ascertain the return value of sanitizeURL. As such it is treated as untrusted / tainted input.

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

No branches or pull requests

3 participants