How to fix the "G101: Potential hardcoded credentials (gosec)"
Crash course in fixing a "gosec" Golang linter issue

Software Engineer x Data Engineer - I make the world a better place to live with software that enables data-driven decision-making
Search for a command to run...
Crash course in fixing a "gosec" Golang linter issue

Software Engineer x Data Engineer - I make the world a better place to live with software that enables data-driven decision-making
No comments yet. Be the first to comment.
In this series, I will discuss the Go linters, use cases, how-tos and everything related
Crash course in fixing a "tagalign" Golang linter issue
Optimize context budgets and eliminate prompt bloat by decoupling skill discovery triggers from execution details.

Why fanning out OAuth introspection inside your VPC creates a distributed bottleneck - and how to keep internal auth fast.

How Model Context Protocol and Agent Communication Protocol shape the AI stack.

A practical follow-up on turning agent instructions into focused, testable workflows.

How to reduce context size, improve reasoning, and build more predictable AI coding workflows

SecureGo is a project that is behind the gosec - the great Go security checker tool. Their page is basically dead and full of TODOs, but their GitHub profile is alive and full of releases. Definitely worth visiting and leaving them a ⭐.
The issue is that in some older versions the gosec had a tendency for a false positives. They officialy stated that some keywords will trigger the warning:
[1] Variables are considered to look like a password if they have match any one of:
“password”
“pass”
“passwd”
“pwd”
“secret”
“token”
Note: this can be noisy and may generate false positives.
It would be great if only those keywords or real passwords would trigger the warning.
Your go file might looks as follows:
package linter
const Location = "var_host_locale_location"
And guess what?
➜ tools git:(main) ✗ docker run --rm -v ./:/app -w /app custom-golangci-lint:v1.54.2 | grep linter
linter/credentials.go:3:7: G101: Potential hardcoded credentials (gosec)
The combination of string literals causing this warning can be unpredictable.
We have a few solutions that can help us with this problem.
If you can allow to upgrade the gosec or the golangci-lint then this is a recommended solution. The mentioned error was triggered on a specific version, after upgrading it was no longer a problem.
[2] You can also configure the hard-coded credentials rule
G101with additional patterns, or adjust the entropy threshold:
{
"G101": {
"pattern": "(?i)passwd|pass|password|pwd|secret|private_key|token",
"ignore_entropy": false,
"entropy_threshold": "80.0",
"per_char_threshold": "3.0",
"truncate": "32"
}
}
You can easily ignore the line causing the false-positive with the #nosec annotation:
package linter
const Location = "var_host_locale_location" // #nosec G101
And we're good:
➜ tools git:(main) ✗ docker run --rm -v ./:/app -w /app custom-golangci-lint:v1.54.2 | grep linter
➜
More on annotations with the #nosec can be found on the project's page.