A method or field is chosen by reflection with a name taken from an HTTP request
What it finds
reflect.ValueOf(api).MethodByName(r.FormValue("action")).Call(nil): choosing a method or field by a name from the request lets the client call any exported method of the value, including ones never meant to be reachable from outside, or read any exported field. A fixed map from accepted names to handlers keeps the choice in the program.
In files that import reflect, reported are calls of the methods MethodByName and FieldByName whose argument is 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_chosen_member.rs.
package p import ( "net/http" "reflect") type api struct{} func handle(w http.ResponseWriter, r *http.Request) { action := r.FormValue("action") reflect.ValueOf(api{}).MethodByName(action).Call(nil)tx0 reports: MethodByName is given a name taken from the request reflect.ValueOf(api{}).MethodByName("List").Call(nil)} 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:
[rules]
"tx0/go:request-chosen-member" = "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-chosen-member] reason="..."tx0 explain tx0/go:request-chosen-member shows the same in the terminal. Found a false positive? Report it.