Repository navigation
Conversation
Signed-off-by: Indra Prasetya <11029197+prascli@users.noreply.github.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 5 |
| Duplication | 0 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
Two security issues should be fixed before merging: encoded traversal may be decoded by SQLite after validation, and symlinks can redirect an apparently contained path outside the conversations directory. The current tests also do not demonstrate rejection when an outside database actually exists.
The required independent containment-failure test scenario is missing.
Test suggestions
- Reject IDs containing slash, backslash, or dot-dot traversal patterns.
- Successfully read a database for a valid conversation ID.
- Return nil when the conversation database does not exist.
- Exercise the containment-check failure path independently.
- Verify percent-encoded traversal cannot open a database outside the conversations directory.
- Verify symlinked conversation database paths cannot escape the conversations directory.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Exercise the containment-check failure path independently.
2. Verify percent-encoded traversal cannot open a database outside the conversations directory.
3. Verify symlinked conversation database paths cannot escape the conversations directory.
TIP Add review instructions in .codacy/instructions/review.md, or an AGENTS.md, so the reviewer knows your conventions.
TIP How was this review? Give us feedback
| } | ||
|
|
||
| db, err := sql.Open("sqlite", "file:"+dbPath+"?mode=ro") | ||
| db, err := sql.Open("sqlite", "file:"+cleanPath+"?mode=ro") |
There was a problem hiding this comment.
🔴 HIGH RISK
Percent-encoded traversal such as %2e%2e%2f can pass the current validation and then be decoded by SQLite when opening the URI. Construct the SQLite URI with safe path escaping or otherwise validate the decoded path, and add a regression test with an accessible database outside the conversations directory.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| } | ||
|
|
||
| func TestReadAntigravityRejectsTraversal(t *testing.T) { | ||
| for _, id := range []string{"../etc/passwd", "../../secret", "a/b", `a\b`, "a..b"} { |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Strengthen these tests by creating a readable database outside the conversations directory at the traversal target and asserting that the traversal ID returns nil. This ensures the test detects an actual path escape rather than only a missing-file result.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| dbPath := filepath.Join(baseDir, conversationID+".db") | ||
| // Containment check: the resolved path must stay inside baseDir. | ||
| cleanPath := filepath.Clean(dbPath) | ||
| rel, err := filepath.Rel(baseDir, cleanPath) |
There was a problem hiding this comment.
🟡 MEDIUM RISK
A symlink inside the conversations directory can point to a database outside that directory while still satisfying the string-based containment check. Enforce containment after resolving filesystem links, or prevent symlink traversal when opening the database, and add a symlink regression test.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
Summary
readAntigravitybuilt the SQLite database path by directly joining an attacker-influenceableconversationIDinto the conversations directory. A crafted ID containing../(or path separators) could escape that directory and open an arbitrary SQLite file readable by the process.This change rejects any
conversationIDcontaining path separators or..segments, and adds a containment check (filepath.Clean+filepath.Rel) so the resolved path must remain inside the conversations directory before the file is opened.Changes
packages/guard/tokens/parse.go: sanitize and contain the conversation ID path.packages/guard/tokens/parse_test.go: addTestReadAntigravityRejectsTraversal.Verification
cd packages/guard/tokens && go test ./...— PASSgo vet ./...— cleangofmt -l .— no filesRelated issue
Fixes #107.