{"record":{"id":"d7dada8bb4c9e2b1","repo":"Tencent/WeKnora","slug":"functions-in-from-clause-are-not-allowed","errorCode":null,"errorMessage":"functions in FROM clause are not allowed","messagePattern":"functions in FROM clause are not allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/utils/inject.go","lineNumber":1474,"sourceCode":"\t\treturn nil\n\t}\n\n\t// Handle RangeSubselect (subquery in FROM)\n\tif rss := node.GetRangeSubselect(); rss != nil {\n\t\tif v.checkSubqueries {\n\t\t\treturn fmt.Errorf(\"subqueries in FROM clause are not allowed\")\n\t\t}\n\t\t// SECURITY: Even when subqueries are permitted, recurse into the\n\t\t// subquery so dangerous constructs hidden inside it are still\n\t\t// validated. Without this, a FROM subquery like\n\t\t//   (SELECT * FROM read_text('/etc/passwd'))\n\t\t// smuggles a RangeFunction past the check below.\n\t\treturn v.validateSubquery(rss.Subquery, tables, result)\n\t}\n\n\t// Handle RangeFunction (function in FROM)\n\tif node.GetRangeFunction() != nil {\n\t\treturn fmt.Errorf(\"functions in FROM clause are not allowed\")\n\t}\n\n\treturn nil\n}\n\n// validateSubquery validates a SELECT statement nested in a FROM subquery.\n// It reuses the FROM-item and expression validators so RangeFunction and\n// dangerous function checks apply recursively to arbitrarily nested subqueries.\nfunc (v *sqlValidator) validateSubquery(node *pg_query.Node, tables map[string]string, result *SQLValidationResult) error {\n\tif node == nil {\n\t\treturn nil\n\t}\n\tsub := node.GetSelectStmt()\n\tif sub == nil {\n\t\treturn nil\n\t}\n\tfor _, fromItem := range sub.FromClause {\n\t\tif err := v.validateFromItem(fromItem, tables, result); err != nil {","sourceCodeStart":1456,"sourceCodeEnd":1492,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/utils/inject.go#L1456-L1492","documentation":"Policy error in validateFromItem: a RangeFunction (set-returning or scalar function used as a FROM item) was encountered and is never permitted, blocking constructs like generate_series or file-reading functions from appearing in FROM.","triggerScenarios":"Thrown at internal/utils/inject.go:1474 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the function from FROM and express the logic in allowed columns","Materialize the needed rows into an allowed table beforehand","Use JOINs against permitted tables instead of set-returning functions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}