Tencent/WeKnora · critical
function '%s' is not allowed (dangerous prefix)
Error message
function '%s' is not allowed (dangerous prefix)
What it means
The SQL injection validator rejects any function whose name starts with a known-dangerous prefix (file_, copy_, binary_, etc.). This library parses untrusted SQL expressions before injecting them into queries, and prefixed functions can read/write files or execute binaries, so they are blocked outright. The check runs before the explicit dangerous-function blocklist and the whitelist.
Source
Thrown at internal/utils/inject.go:2208
}
if schemaName != "" && schemaName != "pg_catalog" {
return fmt.Errorf("schema-qualified function calls are not allowed: %s", schemaName)
}
}
// Block dangerous function prefixes
if v.checkDangerousFuncs {
dangerousPrefixes := []string{
"pg_", // All pg_* functions (pg_read_file, pg_reload_conf, pg_stat_*, etc.)
"lo_", // Large object functions (lo_import, lo_export, lo_from_bytea, lo_put, etc.)
"dblink", // Database link functions
"file_", // File functions
"copy_", // Copy functions
"binary_", // Binary functions
}
for _, prefix := range dangerousPrefixes {
if strings.HasPrefix(funcName, prefix) {
return fmt.Errorf("function '%s' is not allowed (dangerous prefix)", funcName)
}
}
// Block specific dangerous functions - comprehensive list for RCE prevention
dangerousFunctions := map[string]bool{
// Configuration and settings
"current_setting": true,
"set_config": true,
// XML/XPath functions (XXE risks)
"query_to_xml": true,
"xpath": true,
"xmlparse": true,
"xmlroot": true,
"xmlelement": true,
"xmlforest": true,
"xmlconcat": true,
"xmlagg": true,View on GitHub (pinned to 988cbb0330)
Solutions
- Remove the file_/copy_/binary_ function call and pre-load or pre-compute the data outside the injected expression
- Use an allowed scalar function or a parameter placeholder instead of a file/binary function
- If the operation is legitimately required, perform it via a dedicated server-side API endpoint rather than SQL injection into the expression
- Check the dangerousPrefixes list in internal/utils/inject.go to see which prefix matched and rename nothing — never bypass it; restructure the query
Example fix
// before
expr := "copy_('data.csv')"
ValidateExpression(expr)
// after
data := loadDataFromFile("data.csv") // server-side, outside SQL
expr := fmt.Sprintf("value IN (%s)", placeholdersFrom(data)) Defensive patterns
Strategy: validation
Validate before calling
var dangerousPrefixes = []string{"file_", "copy_", "binary_"}
func hasDangerousPrefix(fn string) bool {
for _, p := range dangerousPrefixes {
if strings.HasPrefix(fn, p) { return true }
}
return false
}
// call before submitting the expression
if hasDangerousPrefix(extractedFuncName(expr)) { return errors.New("expression uses a blocked function prefix") } Type guard
func isSafeFunctionName(name string) bool {
return !strings.HasPrefix(name, "file_") &&
!strings.HasPrefix(name, "copy_") &&
!strings.HasPrefix(name, "binary_")
} Try / catch
err := injector.Validate(expr)
if err != nil && strings.Contains(err.Error(), "dangerous prefix") {
http.Error(w, "expression contains a disallowed function", http.StatusBadRequest)
return
} Prevention
- Never expose file/copy/binary table functions in user-editable expressions; pre-compute such data server-side
- Sanitize LLM/ORM-generated SQL with the validator before injection
- Maintain a unit test asserting your app's expression corpus contains no dangerous prefixes
When it happens
Trigger: Calling the expression validation/injection API with a function call node whose funcName begins with one of the dangerousPrefixes entries (e.g. file_read('/etc/passwd'), copy_to(...), binary_exec(...)) in a column default, computed column, or filter expression.
Common situations: Developers porting DuckDB/postgres-flavored SQL that uses file_ or copy_ table functions to load CSVs; generated SQL from ORMs or LLMs that emit import/export helpers; users pasting data-loading snippets into filter or computed-field inputs.
Related errors
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/a7ef635cd8ddd10f.
Report an issue: GitHub.