A response allows every origin, or the origin the request names, to read it

tx0/go:cors-any-originrecommendedwarningsecurity/configurationdepth fastsecurity, cwe-942

What it finds

w.Header().Set("Access-Control-Allow-Origin", "*"): every web site may read the responses of this server from its visitors' browsers. Copying the request's Origin into the header is the same, and with Access-Control-Allow-Credentials it lets any site act with the visitor's cookies. A fixed list of trusted origins limits who reads the responses.

Reported is a Set or Add of the header Access-Control-Allow-Origin, in any case, to the constant * or to a value taken from the request, in a file that imports net/http or a web framework of the pack.

From the rule's source, cors_any_origin.rs.

Example from the rule's tests
package p import "net/http" func open(w http.ResponseWriter, r *http.Request) {	w.Header().Set("Access-Control-Allow-Origin", "*")tx0 reports: every origin may read this response	w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))tx0 reports: the origin named by the request may read this response, which is every origin	w.Header().Set("Access-Control-Allow-Origin", "https://example.com")}
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:cors-any-origin" = "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:cors-any-origin] reason="..."

tx0 explain tx0/go:cors-any-origin shows the same in the terminal. Found a false positive? Report it.