Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
feat(ap): protect featured streams from impersonation
Gabe Kangasfa28e99d9751
diff --git a/docs/features/server-federation-security.md b/docs/features/server-federation-security.mdnew file mode 100644index 0000000000..aac6fdd70a--- /dev/null+++ b/docs/features/server-federation-security.md@@ -0,0 +1,65 @@+# Featured Streams: Security & Trust Model++Featured streams let an Owncast server display a small directory of other+Owncast servers and their live status. Because ActivityPub is an open protocol,+any server can send anything and assert any identity. This document describes+what is and isn't guaranteed, so operators understand the trust boundary.++## What is guaranteed++- **The directory is admin-curated.** Entries in your featured directory are+ created only by an admin adding a server URL. No inbound ActivityPub activity+ can insert an entry — inbound `Offer`/`Accept`/`Leave` only *update* rows that+ already exist. A remote server cannot put itself on your list.+- **The link is the URL you entered, and it is immutable.** The link target for+ an entry is the `https` URL the admin typed (non-`https` is rejected). No+ inbound handler ever changes it, so a remote server cannot repoint your+ directory entry somewhere else after the fact.+- **Status and metadata are bound to that host.** Inbound activities are+ HTTP-signature verified, and the activity's `actor` must share the host of the+ verified signing key (a server cannot sign with its own key while claiming to+ be another). The featured-follow also pins the resolved actor to the host of+ the URL you entered. Together these ensure an entry's live status and metadata+ genuinely come from the server at that URL.+- **The real hostname is shown.** The public stream card displays the entry's+ hostname (from the immutable URL), so a remote server cannot fully masquerade+ behind a spoofed display name.+- **Being featured requires approval.** Another server asking to feature your+ stream appears under "Requests to feature your stream" and must be approved by+ an admin, regardless of whether your server otherwise accepts follows+ automatically.++## What is NOT guaranteed (inherent to an open protocol)++- **"Is this really Owncast?" is self-asserted.** Adding a server validates its+ `nodeinfo` (software name `owncast`, ActivityPub enabled), but any server can+ serve a `nodeinfo` claiming that. Treat this as a sanity check, not proof. The+ real trust anchor is your own curation plus the guarantees above.+- **A featured server controls its own name, logo, title and thumbnail.** These+ are supplied by the remote server and can change over time (including+ bait-and-switch). The link, however, always points to the host you vetted, and+ that host is shown in the UI.++## Practical guidance for operators++- Only feature servers you trust; the directory is a curation you stand behind.+- The shown hostname is the source of truth for where a card leads — judge an+ entry by its hostname, not its display name.+- If a featured server starts misrepresenting itself, unfeature it.++## Hardening implemented++- HTTP-signature verification binds an activity's `actor` to the signing key's+ host (`services/activitypub/inbox/worker.go`).+- IRI/actor/key resolution refuses internal/loopback addresses and caps response+ size; redirects are re-validated (`services/activitypub/resolvers/resolve.go`,+ `utils/tlsconfig.go`).+- Replayed (stale-`Date`) signed requests are rejected within a tolerance window+ (`services/activitypub/inbox/worker.go`).+- Remote-supplied metadata is length/count clamped before storage+ (`services/activitypub/inbox/offer.go`, `accept.go`).+- The featured-follow pins the resolved actor to the entered URL's host+ (`services/activitypub/outbox/follow.go`).+- Remote URLs rendered as links are validated to be `http(s)`+ (`web/components/admin/FederatedServers/FeatureRequests.tsx`), and the public+ card surfaces the real hostname (`web/components/ui/StreamCard/StreamCard.tsx`).diff --git a/services/activitypub/outbox/follow.go b/services/activitypub/outbox/follow.goindex 2aab7d66f8..deeb20d30a 100644--- a/services/activitypub/outbox/follow.go+++ b/services/activitypub/outbox/follow.go@@ -3,6 +3,7 @@ package outboximport ("fmt""net/url"+ "strings""github.com/go-fed/activity/streams"log "github.com/sirupsen/logrus"@@ -71,6 +72,21 @@ func (s *Service) SendFollowToAccount(targetActorAccount string, isStreamConnectreturn fmt.Errorf("failed to resolve actor from IRI %s: %w", actorIRI, err)}+ // Pin the resolved actor to the host of the account we were asked to+ // follow. The featured-streams flow always targets a server URL the admin+ // entered, and an Owncast server's actor lives on that same host. If+ // webfinger points us at a different host, the directory entry would link+ // to one server while actually representing another, so refuse it. (This+ // path is only used by featured streams; general fediverse follows, which+ // may legitimately delegate the actor to another host, do not go through+ // here.)+ if at := strings.LastIndex(targetActorAccount, "@"); at != -1 {+ expectedHost := targetActorAccount[at+1:]+ if !strings.EqualFold(actor.ActorIri.Host, expectedHost) {+ return fmt.Errorf("resolved actor host %q does not match requested server host %q", actor.ActorIri.Host, expectedHost)+ }+ }+return s.SendFollowToAccountURI(actor.ActorIri.String(), actor.Username, actor.ActorIri.Host, isStreamConnected)}diff --git a/web/components/admin/FederatedServers/FeatureRequests.tsx b/web/components/admin/FederatedServers/FeatureRequests.tsxindex 7ef7780e4d..8d4a750c3b 100644--- a/web/components/admin/FederatedServers/FeatureRequests.tsx+++ b/web/components/admin/FederatedServers/FeatureRequests.tsx@@ -5,6 +5,7 @@ import { CheckOutlined, CloseOutlined } from '@ant-design/icons';import { Translation } from '../../ui/Translation/Translation';import { Localization } from '../../../types/localization';import { FeatureRequest } from '../../../hooks/useFeatureRequests';+import { isValidUrl } from '../../../utils/validators';const { Text, Title, Paragraph } = Typography;@@ -133,9 +134,16 @@ export const FeatureRequests: FC<FeatureRequestsProps> = ({)}title={- <a href={request.link} target="_blank" rel="noopener noreferrer">- {request.name || request.username || request.link}- </a>+ // Only render the remote-supplied link as a clickable anchor+ // when it is a valid http(s) URL; otherwise show plain text so+ // a hostile value (e.g. a javascript: URL) can't reach href.+ isValidUrl(request.link) ? (+ <a href={request.link} target="_blank" rel="noopener noreferrer">+ {request.name || request.username || request.link}+ </a>+ ) : (+ <span>{request.name || request.username || request.link}</span>+ )}description={<Text type="secondary">{request.username || request.link}</Text>}/>diff --git a/web/components/ui/StreamCard/StreamCard.module.scss b/web/components/ui/StreamCard/StreamCard.module.scssindex 3ee19c7236..213ac6dbaa 100644--- a/web/components/ui/StreamCard/StreamCard.module.scss+++ b/web/components/ui/StreamCard/StreamCard.module.scss@@ -117,6 +117,13 @@color: var(--theme-color-components-text-on-light);}+ .serverHost {+ display: block;+ font-size: 11px;+ line-height: 1.4;+ color: var(--theme-color-components-text-on-light-disabled);+ }+.streamTitle {display: block;font-size: 12px;diff --git a/web/components/ui/StreamCard/StreamCard.tsx b/web/components/ui/StreamCard/StreamCard.tsxindex 5e559b9be5..9422338127 100644--- a/web/components/ui/StreamCard/StreamCard.tsx+++ b/web/components/ui/StreamCard/StreamCard.tsx@@ -36,6 +36,18 @@ export const StreamCard: FC<StreamCardProps> = ({}};+ // The server-supplied name/logo are not trustworthy (a remote server can+ // call itself anything), but the link target is the immutable URL the admin+ // vetted. Surface its hostname so visitors can see where a card actually+ // leads rather than relying on the spoofable display name.+ const serverHost = (() => {+ try {+ return new URL(serverUrl).hostname;+ } catch {+ return serverUrl;+ }+ })();+const cardCover = (<div className={styles.coverContainer}>{thumbnail ? (@@ -61,6 +73,9 @@ export const StreamCard: FC<StreamCardProps> = ({<Text strong className={styles.serverName}>{serverName}</Text>+ <Text type="secondary" className={styles.serverHost} ellipsis>+ {serverHost}+ </Text>{isOnline && streamTitle && (<Text className={styles.streamTitle} ellipsis>{streamTitle}diff --git a/web/tests/FeatureRequests.test.tsx b/web/tests/FeatureRequests.test.tsxindex d98caf9400..4cafce4f7d 100644--- a/web/tests/FeatureRequests.test.tsx+++ b/web/tests/FeatureRequests.test.tsx@@ -58,6 +58,23 @@ describe('FeatureRequests', () => {expect(onApprove).not.toHaveBeenCalled();});+ it('does not render a non-http link as a clickable anchor', () => {+ // A deliberately hostile non-http(s) link is the whole point of this test.+ // eslint-disable-next-line no-script-url+ const maliciousLink = 'javascript:alert(1)';+ const malicious: FeatureRequest[] = [+ { link: maliciousLink, name: 'Evil Server', username: 'evil' },+ ];+ const { container } = render(+ <FeatureRequests requests={malicious} onApprove={onApprove} onReject={onReject} />,+ );++ // No anchor should ever carry a javascript: href.+ expect(container.querySelector('a[href^="javascript:"]')).toBeNull();+ // The name is still shown, just as plain text.+ expect(screen.getByText('Evil Server')).toBeInTheDocument();+ });+it('calls onApprove with the actor IRI after confirmation', async () => {onApprove.mockResolvedValue(undefined);render(<FeatureRequests requests={requests} onApprove={onApprove} onReject={onReject} />);diff --git a/web/tests/StreamCard.test.tsx b/web/tests/StreamCard.test.tsxindex 45f823a121..11c2b4c4da 100644--- a/web/tests/StreamCard.test.tsx+++ b/web/tests/StreamCard.test.tsx@@ -25,6 +25,14 @@ describe('StreamCard', () => {expect(screen.getByText('OFFLINE')).toBeInTheDocument();});+ it('shows the real server hostname so a spoofed name cannot fully masquerade', () => {+ render(<StreamCard {...defaultProps} serverName="Totally Legit News" />);++ // The display name is shown, but so is the actual hostname of the link.+ expect(screen.getByText('Totally Legit News')).toBeInTheDocument();+ expect(screen.getByText('test.example.com')).toBeInTheDocument();+ });+it('renders online server with stream info', () => {const props: StreamCardProps = {...defaultProps,