Files
accounted/components/agent/AgentAvatar.tsx
T
Jakob Wennberg 2da96c0be2 fix(agent): stop sending every page view to a third-party avatar CDN (#1226)
* fix(agent): stop sending every page view to a third-party avatar CDN

Eight avatar SVGs were loaded from api.dicebear.com on every render. In an
accounting product that meant every authenticated page view told a third party
who was looking at it, from a domain we do not control, on the path of a
logged-in surface. A firewalled or self-hosted install showed no faces at all.

The SVGs are now generated once and served from public/agent-avatars. Each
entry records the seed it came from, so the set can be regenerated
reproducibly, and the command to do it is in the file.

The licence question that made this look like a founder decision resolved
itself on inspection: Notionists is by Zoish under CC0 1.0, public domain, no
attribution required. Confirmed on dicebear.com/licenses and, more usefully, in
each downloaded file's own RDF metadata, so the terms travel with the asset
rather than living in a commit message.

Tests pin the properties that matter rather than the file list: no entry may be
a remote URL, every entry must have a file behind it, and no shipped SVG may
carry an <image href>, a url(https://…), an xlink:href or a <script>, since
self-hosting a file that then phones home would reintroduce exactly the request
this removes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(agent): assert the property, not a list of elements, for avatar externals

The external-reference check enumerated <image href>, url(https://…) and
xlink:href, which left <use href>, <feImage href> and scheme-relative //host
through: exactly the requests the guard claims to prevent, via elements it
happened not to list. That is how this sort of allowlist rots.

It now strips the parts that legitimately carry URLs and are never fetched (the
RDF metadata block, xmlns declarations) and then asserts that NOTHING in what
remains points off-origin. Verified by injecting each of the four bypasses into
a real asset and confirming the test fails on all of them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 15:35:14 +02:00

61 lines
1.6 KiB
TypeScript

'use client'
import { MessageCircle } from 'lucide-react'
import { cn } from '@/lib/utils'
import { getAvatarUrl } from './avatars'
interface Props {
avatarId: string | null | undefined
size?: 'xs' | 'sm' | 'md' | 'lg'
className?: string
alt?: string
}
// Renders the agent's avatar: either the chosen SVG from the AVATAR_OPTIONS
// registry, or a fallback MessageCircle glyph on a dark circle when no avatar
// is set yet (free tier / older profiles).
//
// `next/image` is intentionally NOT used: these are tiny static SVGs served
// from our own /public, and the optimizer does not process SVG anyway, so it
// would add a round trip through /_next/image for nothing.
export default function AgentAvatar({ avatarId, size = 'sm', className, alt }: Props) {
const url = getAvatarUrl(avatarId)
const dim = SIZES[size]
const altText = alt ?? 'Avatar'
if (!url) {
return (
<span
className={cn(
'inline-flex items-center justify-center rounded-full bg-foreground text-background shrink-0',
dim.box,
className,
)}
aria-label={altText}
>
<MessageCircle className={dim.icon} />
</span>
)
}
// eslint-disable-next-line @next/next/no-img-element
return (
<img
src={url}
alt={altText}
className={cn(
'rounded-full shrink-0 bg-secondary object-cover',
dim.box,
className,
)}
/>
)
}
const SIZES = {
xs: { box: 'h-5 w-5', icon: 'h-2.5 w-2.5' },
sm: { box: 'h-8 w-8', icon: 'h-3.5 w-3.5' },
md: { box: 'h-10 w-10', icon: 'h-4 w-4' },
lg: { box: 'h-14 w-14', icon: 'h-5 w-5' },
}