An environment variable of the process is set from an HTTP request

tx0/go:request-value-in-environmentrecommendedwarningsecurity, cwe-15

What it finds

os.Setenv("LANG", r.Header.Get("Accept-Language")): the environment configures the process and every program it starts, so a variable set from a request can change their behaviour, as LD_PRELOAD, PATH or GIT_SSH_COMMAND do, and stays set for all later requests.

The name or value given to os.Setenv must be a request value of the handler, as described for the request values of the pack, that the function does not check in a condition.

From the rule's source, request_value_in_environment.rs.

Example from the rule's tests
package p import (	"net/http"	"os") func handle(w http.ResponseWriter, r *http.Request) {	os.Setenv("LANG", r.Header.Get("Accept-Language"))tx0 reports: the environment of the process is set from the request	os.Setenv("MODE", "web")}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:request-value-in-environment" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:request-value-in-environment] reason="..."

tx0 explain tx0/go:request-value-in-environment shows the same in the terminal. Found a false positive? Report it.