SMOODEV-1878: Embeddable-widget auth hook — origin allowlist + public-key authContext#2
Merged
Merged
Conversation
…-key authContext
Adds a pluggable WidgetAuthProvider hook to the public smooth-operator server
that secures <smooth-agent-chat> embedding (the gate for repointing the SmooAI
dashboard embed off the legacy widget):
- smooth_operator::widget_auth (lib): the WidgetAuthProvider async trait +
AgentWidgetAuth policy, a PermissiveWidgetAuth default (no enforcement) and a
StaticWidgetAuth (JSON map) impl, plus origin_allowed (exact / host-wildcard /
`*`) and verify_auth_context (HMAC-SHA256 over "{userId}:{timestamp}",
replay-windowed) primitives.
- Server: capture the WS handshake Origin header, thread it through
connection_loop → handle_frame → handle_create_session, and enforce the
agent's policy before creating a session — origin allowlist (fail closed) +
optional authContext verification. AppState gains a widget_auth provider
(with_widget_auth builder, PermissiveWidgetAuth default) and a
WIDGET_AUTH_STRICT config flag that rejects unknown agents.
A host (SmooAI) plugs in a concrete provider backed by its agent DB; the OSS
server stays open by default. New error codes: ORIGIN_NOT_ALLOWED,
AUTH_CONTEXT_INVALID, AGENT_NOT_AUTHORIZED.
Tests: 5 lib unit (origin matching, HMAC verify, providers) + 4 WS integration
(allowed/disallowed/missing origin, unpolicied passthrough). fmt + clippy clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 221b16d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The gate for repointing the SmooAI dashboard embed off the legacy
<smooai-chat-widget>to<smooth-agent-chat>. The public smooth-operator server had no agent resolution and no embed auth — any origin could drive any agent. This adds a pluggable hook so a host (SmooAI) can enforce a per-agent origin allowlist + public-keyauthContext, while standalone OSS stays open by default.Design (the hook lives in the public code)
smooth_operator::widget_auth(lib):WidgetAuthProviderasync trait +AgentWidgetAuth { allowed_origins, public_key }policy.PermissiveWidgetAuth(default — no policy → no enforcement) andStaticWidgetAuth(JSON map) impls.origin_allowed(exact /scheme://*.suffixhost wildcard /*) andverify_auth_context(HMAC-SHA256 over"{userId}:{timestamp}", constant-time, 60s replay window).Originheader and threads itws_upgrade → connection_loop → handle_frame → handle_create_session, enforcing the agent's policy before a session is created — origin allowlist (fail closed) + optionalauthContextverification.AppStategains awidget_authprovider (with_widget_authbuilder) and aWIDGET_AUTH_STRICTflag that rejects unknown agents.New error codes:
ORIGIN_NOT_ALLOWED,AUTH_CONTEXT_INVALID,AGENT_NOT_AUTHORIZED.Verification
124 + 21 + 4 + 4green.cargo fmt --checkclean; no new clippy warnings.@smooai/smooth-operatorminor).Follow-up (SmooAI side, unblocks SMOODEV-1845)
Wire a concrete
WidgetAuthProvider(agent allowed-origins + public key from the SmooAI agent store) into SmooAI's smooth-operator deployment withWIDGET_AUTH_STRICT=1, then repoint the dashboardgenerateInstallCode()to emit<smooth-agent-chat>and deprecate@smooai/ui-chat-widget.🤖 Generated with Claude Code