-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add per-user knowledge isolation, prompt enhancement, and CI #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| version: 2 | ||
| updates: | ||
| - package-ecosystem: gomod | ||
| directory: / | ||
| schedule: | ||
| interval: weekly | ||
| open-pull-requests-limit: 5 | ||
|
|
||
| - package-ecosystem: github-actions | ||
| directory: / | ||
| schedule: | ||
| interval: weekly | ||
| open-pull-requests-limit: 5 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Fuzz | ||
|
|
||
| on: | ||
| schedule: | ||
| # Weekly: Sunday 03:00 UTC | ||
| - cron: "0 3 * * 0" | ||
| workflow_dispatch: # Allow manual trigger | ||
|
|
||
| jobs: | ||
| fuzz: | ||
| name: Fuzz Tests | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| fuzz-target: | ||
| - FuzzPathValidation | ||
| - FuzzPathValidationWithSymlinks | ||
| - FuzzCommandValidation | ||
| - FuzzURLValidation | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: "1.25" | ||
|
|
||
| - name: Run ${{ matrix.fuzz-target }} | ||
| run: go test -fuzz=${{ matrix.fuzz-target }} -fuzztime=30s ./internal/security/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| DROP INDEX IF EXISTS idx_documents_owner; | ||
| ALTER TABLE documents DROP COLUMN IF EXISTS owner_id; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| -- Add owner_id to documents for per-user knowledge isolation. | ||
| -- Prevents RAG poisoning: user A's stored knowledge cannot influence user B's results. | ||
| -- Existing documents get NULL owner_id (legacy/shared — visible to all users). | ||
| ALTER TABLE documents ADD COLUMN owner_id TEXT; | ||
|
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ambiguous ownership for legacy data: Recommendation: |
||
|
|
||
| CREATE INDEX idx_documents_owner ON documents(owner_id); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,6 +233,11 @@ func (h *chatHandler) streamWithFlow(ctx context.Context, w http.ResponseWriter, | |
| emitter := &jsonToolEmitter{w: w, msgID: msgID} | ||
| ctx = tools.ContextWithEmitter(ctx, emitter) | ||
|
Comment on lines
233
to
234
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential Data Race on The Recommendation:
|
||
|
|
||
| // Inject owner identity for per-user knowledge isolation (RAG poisoning prevention). | ||
| if ownerID, ok := userIDFromContext(ctx); ok && ownerID != "" { | ||
| ctx = tools.ContextWithOwnerID(ctx, ownerID) | ||
| } | ||
|
Comment on lines
+237
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security: Owner ID Injection into Context Injecting the owner ID into the context for per-user knowledge isolation is a good security practice. However, it is crucial to ensure that the owner ID extracted from the context is always validated and cannot be spoofed or manipulated by a malicious client. Recommendation:
|
||
|
|
||
| h.logger.Debug("starting stream", "sessionId", sessionID) | ||
|
|
||
| var ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing referential integrity constraints:
The
owner_idcolumn is added asTEXTwithout any constraints (e.g., foreign key to a users table, NOT NULL, or default value). This allows invalid or orphaned values, which may compromise data integrity and security.Recommendation:
Consider adding a foreign key constraint to ensure
owner_idreferences a valid user, or at minimum document the expected values and add validation at the application layer.