WeKnora/internal/im
lyingbug b82fd6c0f9
fix(security): close the low-severity shared-space findings (#3416)
* fix(security): close the low-severity shared-space findings

Verified and fixed from the shared-space permission review:

- Embed channels kept knowledge_ids, tag_ids, mentioned_items, skill_names
  and summary_model_id from anonymous visitors. Mentions are only scoped
  for shared agents, so a visitor could query any KB (and pick any model)
  of the channel workspace by ID. The payload now drops them; the widget
  never sends them.
- PUT /knowledgebase/:kb_id/wiki/issues/:issue_id/status updated any issue
  by ID. The update is now scoped to the path's KB (404 otherwise).
- A direct org invite let the inviter attach any user of the target
  workspace (or any user by ID) as its representative, whose username and
  email the roster then showed to all members. Direct adds attach no
  representative, and the roster returns emails only for the caller's own
  workspace.
- COS and KS3 dropped the bucket (and COS the region) segment when turning
  a path into an object key, while the tenant check scans every segment:
  cos://42/<region>/prefix/7/... passed as tenant 42 and read tenant 7's
  object from a shared bucket. Both must now match the service's config.
- Shared agent listings returned the full agent to receivers. Prompts and
  the creator's user ID are withheld; capabilities and scope stay visible.
- Temporary document uploads let the caller pick the parser engine (and
  its credentials) of a shared agent's workspace; only the agent's rules
  choose one there now.
- Suggested questions used request / message-snapshot knowledge_ids
  without a permission check. Each document is now resolved to its KB and
  checked like KB IDs, including a shared agent's scope.
- IM channels accepted any knowledge_base_id (and any agent ID on create).
  Both must belong to the channel's workspace, the KB also to a restricted
  API key's allow-list.
- KB-restricted API keys could list org-shared KBs outside their allow-list
  in the organization views; those listings are now filtered.
- With enable_rbac=false, RequireKBAccess let cross-workspace denials
  through. That switch is for roles inside a workspace; the guard now
  always denies another workspace's KB, since handlers behind it load by
  ID without a tenant filter.
- The org member limit was counted before and enforced apart from the
  insert; it is now checked in the insert's transaction with the
  organization row locked (SQLite serializes writers instead).
- The UpdateOrganization route comment and API doc said owner-only; the
  service and UI allow org admins. Comment and doc corrected.

Documented, not changed: issued /r/ and presigned links stay valid until
they expire after a share is revoked.

* fix(security): address review of the low-severity shared-space fixes

- Embed payloads also drop question_origin. It selects a KB like an
  @mention for agents that retrieve only when mentioned, and the widget
  never sends it; the selection stays inside the agent's scope, but an
  anonymous visitor should not pick among its KBs. suggestion_attribution is
  kept (the widget sends it and it is validated).
- The receiver view of a shared agent also withholds the follow-up
  suggestion instruction, a prompt like the others. Starter questions are
  shown to receivers anyway, and the sharer's name is displayed by design.
- Follow-up suggestion generation moves into the agent's workspace with
  types.WithExecutionTenant instead of a bare tenant rewrite, so the
  caller is pinned before the document permission check runs. The auth
  middleware and the shared run already pinned it; this removes the
  dependency on that.
- KS3 CopyFile copies only from the service's own bucket (as COS and S3
  do); another bucket's path is a cross-backend copy.

Tests cover the dropped question_origin, the follow-up instruction and the
/shared-agents listing, a follow-up context with the tenant switched, a
repeated wiki issue status update, and the KS3 copy source.
2026-09-18 22:58:46 +08:00
..
dingtalk fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
feishu fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
mattermost fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
qqbot fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
slack fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
telegram fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
wechat refactor: remove unused private Go helpers 2026-09-17 15:51:51 +08:00
wecom fix(im): handle WeCom 32-byte PKCS7 padding (#2848) 2026-08-28 15:40:42 +08:00
yunzhijia fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
adapter.go fix(im/feishu): show progress card in full output mode (#2909) 2026-09-01 13:09:11 +08:00
callback_validation_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
channel_agent_name_test.go fix(i18n): 修复内置智能体名称与描述不随界面语言切换的问题 (#2828) 2026-08-27 11:53:45 +08:00
channel_kb_scope_test.go fix(security): close the low-severity shared-space findings (#3416) 2026-09-18 22:58:46 +08:00
channel_mapping_test.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
channel_security.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
channel_security_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
cmd_clear.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_help.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_info.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_search.go fix(search): apply tag filters to knowledge search 2026-07-06 23:30:33 +08:00
cmd_stop.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
command.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
command_registry.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
content_rewrite_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
credentials.go refactor(im): move adapter factories into per-platform subpackages 2026-04-29 20:08:22 +08:00
file_message_test.go fix(im): tighten DingTalk rich-text follow-up handling 2026-08-24 14:51:04 +08:00
full_output_test.go fix(feishu): preserve active streams during long-running QA 2026-09-14 22:19:53 +08:00
identity_test.go test: address PR review follow-ups for OAuth and logger cleanup 2026-07-01 17:31:42 +08:00
im_config_warning_test.go fix(im): render resource:// images in IM channels (nginx /r/ + config guards) 2026-07-28 21:25:12 +08:00
im_file_service_test.go refactor(storage): extract storage reference URL rewriting into internal/storageurl 2026-08-05 14:42:51 +08:00
mode.go refactor(im): move adapter factories into per-platform subpackages 2026-04-29 20:08:22 +08:00
oauth_notice_test.go feat(im): include per-service MCP OAuth URLs in IM auth notices 2026-07-01 17:53:54 +08:00
qa_exit_test.go fix(im): finalize replies after agent QA returns (#3261) 2026-09-15 17:37:40 +08:00
qaqueue.go feat: add unit tests for COS object name parsing and enhance error handling 2026-05-29 13:47:32 +08:00
service.go fix(security): close the low-severity shared-space findings (#3416) 2026-09-18 22:58:46 +08:00
service_agent_test.go fix(integrations): polish agent filter UX and embed session rebind 2026-06-24 20:09:19 +08:00
service_lifecycle_test.go fix(im): recover after leader lock loss 2026-07-28 20:40:58 +08:00
service_quote_test.go fix(im): anti-hallucination for non-text quotes and unprocessable media messages 2026-04-03 11:34:22 +08:00
session_not_found_test.go fix(im): recover from deleted session when GetSession returns app sentinel (#1499) 2026-05-27 11:51:11 +08:00
session_test.go fix(im): tighten DingTalk rich-text follow-up handling 2026-08-24 14:51:04 +08:00
session_title_test.go feat(im): IM session improvements — titles, in-flight recovery, classification 2026-06-12 17:01:28 +08:00
stream_delivery_test.go fix(feishu): preserve active streams during long-running QA 2026-09-14 22:19:53 +08:00
stream_display_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
stream_exit_test.go fix(im): preserve errors emitted after agent completion 2026-09-15 17:56:54 +08:00
stream_lifecycle_test.go fix(im): address stream display review feedback 2026-06-24 10:33:55 +08:00
stream_section.go fix(im): address stream display review feedback 2026-06-24 10:33:55 +08:00
stream_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
supervisor.go fix(im): prevent DingTalk stream connection from going stale 2026-06-22 15:04:23 +08:00
think.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
think_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
tool_display.go refactor(agent): consolidate knowledge retrieval tools into search_knowledge, read_document, list_documents (#3381) 2026-09-18 14:12:22 +08:00
tool_display_test.go feat(agent): stream live +/- progress for sandbox write and edit 2026-09-02 23:36:58 +08:00
types.go feat(im): add Yunzhijia integration 2026-07-21 12:24:33 +08:00
types_summary_test.go fix(security): redact IM list credentials and harden MinerU SSRF 2026-07-02 17:58:20 +08:00
types_test.go feat(im): add Yunzhijia integration 2026-07-21 12:24:33 +08:00