Skip to content

Chat pane serves a stale Content-Security-Policy after Posit Assistant is updated in-session #18831

Closed

Description

@gtritchie

Summary

loadCspDirectives() (src/cpp/session/modules/chat/ChatStaticFiles.cpp) reads dist/csp.json from the Posit Assistant installation into a function-local static const auto, so the directives are read once and kept for the lifetime of the rsession process. The doc comment states this deliberately:

Once loaded (or once a failure is encountered), the result is cached for the lifetime of the session. A missing or broken file will not be retried.

That holds even when the installation changes underneath it. Updating Posit Assistant from the chat pane does not restart the session: chatUpdatePositAssistant stops the backend via stopChatBackendForInstallMutation("update"), installs, and the frontend then restarts the backend and reloads the UI (ChatPresenter.installUpdate() -- "Update complete - restart backend and reload UI"). The new package's dist/csp.json is never read, so the newly installed client is served under the previous version's CSP.

Why it matters

The CSP is emitted by the databot build and is expected to track the client it ships with. If a new Posit Assistant version needs a directive the old one did not -- another connect-src origin, an img-src, a worker or font source -- the browser blocks it, and the symptom is a chat pane that is subtly or completely broken until RStudio itself is restarted. The user did nothing wrong and has no reason to connect the breakage to the update they just accepted.

The reverse case is quieter but also wrong: a new version that tightens its CSP is served under the older, looser policy.

Scope

This is pre-existing, from #17132. It is not caused by #18774/#18815/#18819, though it came up twice while reviewing #18819, because the resolver and the served installation were being reworked there. The directives were always frozen at first read; #18819 only changed which installation seeds them.

Options

  • Key the cache on the installation path, so a restart onto a different installation re-reads dist/csp.json and an unchanged one still costs nothing. Fits how the served installation is now pinned per backend start (staticfiles::setInstallationPath()).
  • Invalidate it explicitly wherever the installation is mutated -- the update and uninstall paths in SessionChat.cpp. Fewer moving parts, but it is another thing for a future install path to remember.

The first keeps the invalidation next to the thing being cached, and needs no cooperation from callers.

Note that rebuildCspHeaderCache() already re-runs on every setChatBackendPort(), so the surrounding header string is rebuilt on each backend start. Only the csp.json directive map is stuck, which is why the staleness is easy to miss.

Related: #18819, #17132.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions