Skip to content

Fix: clear GetByID - #20371

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
Lynn-Inf:refactor/get-chat-channel
Sep 29, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
Lynn-Inf:refactor/get-chat-channel

Conversation

@Lynn-Inf

Copy link
Copy Markdown
Contributor

Summary

As title, fix GetByID semantics by removing the tenant_id variant.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 95e8f67c-d713-4466-8820-2e6a30d684d8

📥 Commits

Reviewing files that changed from the base of the PR and between 2a94c6c and 23c4cdd.

📒 Files selected for processing (3)
  • internal/dao/chat_channel.go
  • internal/dao/chat_channel_test.go
  • internal/service/chat_channel.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The chat channel DAO now retrieves channels by ID and checks tenant ownership before updates and deletions. Service methods use the updated lookup method, and DAO tests cover the lookup and mutation behavior.

Changes

Chat channel lookup and mutations

Layer / File(s) Summary
DAO lookup and tenant-checked mutations
internal/dao/chat_channel.go, internal/dao/chat_channel_test.go
GetByID now looks up a channel by ID alone. Updates and deletions load the channel first and return gorm.ErrRecordNotFound when its tenant ID does not match. Tests verify ID-only lookup and tenant checks.
Service lookup call sites
internal/service/chat_channel.go
Service methods now load channels with GetByID instead of GetByIDOnly. Existing authorization checks and incoming-message routing remain unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: jinhai-cn

Merge Risk: ⚪ Minimal · up to 23c4c

This change renames the DAO lookup to an ID-only GetByID and keeps the tenant checks on channel updates and deletions. No concrete merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 23c4c

Existing channel access checks remain in place, but updates and deletions no longer bind tenant ownership to the final database operation. A cross-tenant effect would require ownership to change concurrently; whether that can happen in production remains unresolved.

Retained concerns

  • Medium · security · inferred: Tenant ownership is checked before, rather than as part of, the final channel update or delete. If ownership can change between the read and mutation, a request authorized for the previous owner could affect a channel belonging to the new owner.
Security review details

Security Blast Radius

  • inferred — The conditional mutation race concerns a channel row whose tenant ownership changes between the DAO read and write. The inspected request path does not give an ordinary channel user a way to reassign that ownership; privileged or external writers remain unverified.

Security Findings and Attack Paths

  • inferred — If another writer reassigns tenant ownership after the DAO's successful check but before its ID-only mutation, an authorized request for the former owner could update or delete the new owner's channel. No supported concurrent ownership writer was established, so the attack path remains conditional rather than verified.

Trust Boundaries and Controls

  • observed — The accessible check compares the loaded channel's tenant with the user identity or that user's tenant memberships; the inspected get, update, and delete service operations reject callers when it fails.

Resilience and Maintainability Implications

  • observed — Head returns not-found on an ownership mismatch before mutating, but the final mutation no longer checks ownership in its database predicate. A prior successful check is therefore not protection against a subsequent ownership change.

Hardening Proposals

  • proposed — Retain tenant ID in the final UPDATE and DELETE predicates, even if a separate read is needed to return a not-found error. This would preserve the mutation's ownership invariant without relying on tenant immutability or timing.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the main change to GetByID. It is concise and related to the updated tenant-handling semantics, although it could state the change more precisely.
Description check ✅ Passed The description includes the required ### Summary section and states that the PR removes the tenant_id variant from GetByID. It provides sufficient context for this change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

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.

❤️ Share

A rabbit checks the channel by ID,
Then guards each change with tenant pride.
A wrong tenant gets not found,
The service calls the new lookup around.
The burrow’s tests confirm each stride.

Comment @coderabbitai help to get the list of available commands.

@Lynn-Inf
Lynn-Inf requested a review from wangq8 September 29, 2026 08:18
@Lynn-Inf Lynn-Inf added the ci Continue Integration label Sep 29, 2026
@wangq8
wangq8 merged commit 9d66daa into infiniflow:main Sep 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants