Why it matters
The caller can run code, or read anything the environment passed to the engine exposes.
How to fix it
Do not evaluate request data. If users must supply expressions, compile a server-held expression and pass the value as a variable, with an environment that exposes nothing else.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
package calc
import (
"net/http"
"github.com/expr-lang/expr"
)
func Eval(w http.ResponseWriter, r *http.Request) {
out, err := expr.Eval(r.FormValue("expr"), nil)
_, _ = out, err
}package calc
import (
"net/http"
"strconv"
"github.com/expr-lang/expr"
)
func Eval(w http.ResponseWriter, r *http.Request) {
a, _ := strconv.Atoi(r.FormValue("a"))
out, err := expr.Eval("a * 2", map[string]any{"a": a})
_, _ = out, err
}What TrustIvan reads
Runs on repository scans of Go source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- NoSQL injection from request input (Go)
GoSeverity: High
trustivan-go-taint-nosql-injection - JWT none algorithm (Go)
GoSeverity: High
trustivan-go-jwt-none-algorithm - Regex injection from request input (Go)
GoSeverity: Medium
trustivan-go-taint-regex-injection - Weak RSA key (Go)
GoSeverity: Medium
trustivan-go-weak-rsa-key - XPath injection from request input (Go)
GoSeverity: High
trustivan-go-taint-xpath-injection - CORS wildcard credentials (Go)
GoSeverity: High
trustivan-go-cors-wildcard-credentials
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation