gosec icon indicating copy to clipboard operation
gosec copied to clipboard

gosec G101 false positive

Open mrvik opened this issue 4 years ago • 1 comments

Summary

gosec throws a false positive when using sql functions with placeholders

Offending line:

	e_USER_PASSWD := `UPDATE users set password=sha2(?, 256) where id=?`

Steps to reproduce the behavior

Create a file containing the previous line and run gosec

gosec version

GitLab Gosec analyzer v2.16.2

Go version (output of 'go version')

1.15.7

Operating system / Environment

Linux on a container. Image reference: registry.gitlab.com/gitlab-org/security-products/analyzers/gosec:2

Expected behavior

Recognizing the function and placeholder as non-password

Actual behavior

Issues a warning because it seems to recognize the function as a password.

mrvik avatar Jan 30 '21 18:01 mrvik

Looking into this, I can see that the reason it issues a warning is because the entropyPerChar for UPDATE users set password=sha2(?, 256) where id=? slightly exceeds the threshold of 3.0. SQL statements use a mix of uppercase and lowercase letters so that makes the entropy higher.

Possible quick fixes are 1) to slightly increase the entropy threshold 2) add exceptions to the entropy calculation for SQL reserved words or somehow check if the string is an sql statement.

HakuPiku avatar Mar 06 '22 19:03 HakuPiku

This can be fixed by tweaking the entropy and the custom patters of the rule G101.

ccojocar avatar Oct 18 '23 13:10 ccojocar