{"record":{"id":"d0ac9176f12c49d4","repo":"Tencent/WeKnora","slug":"no-valid-table-found-in-query","errorCode":null,"errorMessage":"no valid table found in query","messagePattern":"no valid table found in query","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/utils/inject.go","lineNumber":1410,"sourceCode":"\t}\n\n\t// Validate HAVING clause\n\tif stmt.HavingClause != nil {\n\t\tif err := v.validateNode(stmt.HavingClause, result); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// Validate ORDER BY clause\n\tfor _, sortBy := range stmt.SortClause {\n\t\tif err := v.validateNode(sortBy, result); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// Ensure at least one valid table is referenced\n\tif len(tablesInQuery) == 0 {\n\t\treturn fmt.Errorf(\"no valid table found in query\")\n\t}\n\n\treturn nil\n}\n\n// validateFromItem validates a FROM clause item\nfunc (v *sqlValidator) validateFromItem(node *pg_query.Node, tables map[string]string, result *SQLValidationResult) error {\n\tif node == nil {\n\t\treturn nil\n\t}\n\n\t// Handle RangeVar (simple table reference)\n\tif rv := node.GetRangeVar(); rv != nil {\n\t\ttableName := strings.ToLower(rv.Relname)\n\n\t\t// Check for schema qualification\n\t\tif v.checkSchemaAccess && rv.Schemaname != \"\" {\n\t\t\tschemaName := strings.ToLower(rv.Schemaname)","sourceCodeStart":1392,"sourceCodeEnd":1428,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/utils/inject.go#L1392-L1428","documentation":"Guard error in the SQL validator (inject.go): after validating FROM, JOIN, HAVING, and ORDER BY clauses, no recognized table was collected into tablesInQuery, meaning the query references no permitted table. This is a security fail-closed rejection of queries the validator cannot map to allowed tables.","triggerScenarios":"Thrown at internal/utils/inject.go:1410 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reference at least one allowed table in FROM/JOIN","Remove constructs that hide tables from validation (e.g. bare SELECT without FROM)","Check table-name casing; names are lowercased before matching"],"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-08T10:18:20.063Z"}