Keep one user's conversation private
By the end of this lesson, you can inspect and test the conversation-owner filter.
Restrict conversations to their owner
Section titled “Restrict conversations to their owner”In the first course there was one user: you, in SQLcl. A page has many.
Two engineers open the same page. Each has a conversation. The conversation id is a value in a page item, and a page item is not a secret. Nothing so far stops the second engineer from reading the first one’s chat.
What the plug-in does
Section titled “What the plug-in does”Every request that touches a conversation is checked. The rule is small:
- A conversation with no rows is open. The first message decides who owns it.
- Once it has rows, only the user who wrote them can read it or add to it.
That covers both directions. Reading is checked, and so is sending. A forged conversation id gets nothing back and cannot be written to.
You do not configure this. It is on.
The column that records the owner
Section titled “The column that records the owner”Run this for one conversation:
select m.session_id, max(m.created_by) as chat_created_by, max(s.created_by) as core_created_by, max(s.audience) as audience from uc_ai_chat_messages m join uc_ai_agent_sessions s on s.session_id = m.session_id group by m.session_id order by max(m.id) desc fetch first 1 rows only;SESSION_ID CHAT_CREATED_BY CORE_CREATED_BY AUDIENCE59DC51FBE17F6D27E0630201590AAD64 ADMIN APEX_PUBLIC_USER dbOne conversation, two created_by columns, two different values.
uc_ai_chat_messages.created_byis ADMIN. That row is written while the browser request is running, so APEX knows who the user is.uc_ai_agent_sessions.created_byis APEX_PUBLIC_USER. That row is written by the background job, which has no APEX session, so UC AI records the database user.
The owner of a conversation is the first column. The second one is the job.
Test the owner filter
Section titled “Test the owner filter”Run this query to count the conversation rows visible to a second user:
select count(*) as rows_user_b_can_see from uc_ai_chat_messages where session_id = 'a conversation started by user A' and created_by = 'USER_B';ROWS_USER_B_CAN_SEE 0The plug-in adds exactly this condition to the fetch. A conversation id alone is not enough.
Key takeaways
Section titled “Key takeaways”- A conversation belongs to the user who sent its first message. Reading and sending are both checked.
uc_ai_chat_messages.created_byis the real user.uc_ai_agent_sessions.created_byis the background job.- Never pass
APP_USERas the owner guard to the session writers. The write is discarded in silence.
Full reference: the Security section of the plug-in guide.