Skip to content

Keep one user's conversation private

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.

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.

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 AUDIENCE
59DC51FBE17F6D27E0630201590AAD64 ADMIN APEX_PUBLIC_USER db

One conversation, two created_by columns, two different values.

  • uc_ai_chat_messages.created_by is ADMIN. That row is written while the browser request is running, so APEX knows who the user is.
  • uc_ai_agent_sessions.created_by is 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.

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
0

The plug-in adds exactly this condition to the fetch. A conversation id alone is not enough.

  • A conversation belongs to the user who sent its first message. Reading and sending are both checked.
  • uc_ai_chat_messages.created_by is the real user. uc_ai_agent_sessions.created_by is the background job.
  • Never pass APP_USER as the owner guard to the session writers. The write is discarded in silence.

Full reference: the Security section of the plug-in guide.