Skip to content

Commit f8e35af

Browse files
authored
feat: avatar upload UI, self-service profiles, server-side avatar route (#111421)
* feat: avatar upload UI, self-service profiles, server-side avatar proxy * refactor(ui): make resolveAvatar synchronous so avatar updates render immediately resolveAvatar no longer does async work (gravatar moved server-side), so the until()-deferred render left the identity chip img stale after updateSelfUser. Rendering synchronously reuses the img element and reflects avatarUrl changes on the next render. * fix(gateway): bound avatar Gravatar lookup to one timeout budget Linked-email Gravatar lookups ran sequentially, each with its own 5s timeout, so an upstream outage stalled the held connection for 5s x linked-email-count. Resolve them concurrently and pick the first hit in email order, keeping primary-email precedence while capping the request to a single timeout budget. * fix(gateway): cap per-profile Gravatar fan-out to bound sockets and memory A profile with many linked emails would fan out one concurrent fetch per email with no bound, each able to buffer up to MAX_GRAVATAR_BYTES before the cache budget applies. Cap the lookups to the first 8 primary-ordered emails so a single avatar request holds a bounded number of sockets and transient bytes. * test: reconcile avatar tests with server-side gravatar model after merge main landed a client-side Gravatar path (browser computes the gravatar.com URL); this branch resolves avatars through the same-origin gateway route, which is the only approach that works under the Control UI CSP (img-src 'self'). Update the identity-section, app-sidebar footer chip, and profile-page e2e expectations to assert the canonical /api/users/<id>/avatar route (gateway serves the Gravatar fallback behind it) instead of a CSP-blocked direct gravatar.com image. * test(gateway): fix fetchImpl mock param type for check-test-types The Gravatar mock typed its param as (url: string), narrower than the fetchImpl signature (URL | RequestInfo); function-param contravariance made it unassignable under tsgo:test. Widen to the fetch input type and extract the URL via a small helper that avoids no-base-to-string on a Request. * fix(gateway): short-circuit Gravatar lookups and version presence avatar URL Two autoreview findings on the avatar path: - Privacy: the concurrent Promise.all fan-out queried every linked email's hash against Gravatar even when the primary already had one, exposing secondary work/personal addresses. Resolve sequentially with short-circuit so a later hash is disclosed only after the earlier email is a definite miss, under one shared request deadline that still bounds total latency. - Staleness: presence published an unversioned /api/users/<id>/avatar, so a reconnecting viewer's <img> kept the stale cached image after an upload. Carry the profile revision as ?v=<updatedAt> so a changed avatar refetches.
1 parent 1ef99e6 commit f8e35af

27 files changed

Lines changed: 1105 additions & 408 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Docs: https://docs.openclaw.ai
77
### Changes
88

99
- **Discord and Slack native login:** register `/login` in native command menus while keeping pairing-code issuance limited to private chats and the Web UI.
10+
- **Control UI user profiles:** let trusted-proxy users manage their own display name and avatar, resolve attributed chat and presence identities through uploaded avatars or a private cached Gravatar proxy, and keep other users' profiles admin-only.
1011
- **Trusted-proxy browser pairing:** optionally auto-approve new Control UI and WebChat devices from allowlisted proxy identities with non-admin scope caps, while keeping existing-device upgrades manual.
1112
- **Channel plugin ingress monitors:** add a shared plugin SDK monitor for durable admission, polling, pruning, claim identity validation, adoption handoff, and shutdown, and migrate IRC, Synology Chat, and Google Chat to the shared lifecycle.
1213
- **External gateway supervision:** add `OPENCLAW_SUPERVISOR_MODE=external` for lifecycle owners such as OCM, preserving verified restart and deferral behavior without exposing native service authority, blocking native service mutation and self-update, and providing a versioned atomic restart-handoff consume contract. Thanks @shakkernerd.

‎src/gateway/server-methods/shared-types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export type GatewayClient = {
7474
profileId: string;
7575
displayName: string | null;
7676
hasAvatar: boolean;
77+
updatedAt: number;
7778
};
7879
pluginSurfaceUrls?: Record<string, string>;
7980
pluginNodeCapabilitySurfaces?: Record<string, PluginNodeCapabilitySurface>;

‎src/gateway/server-methods/users.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,27 @@ describe("users gateway methods", () => {
215215
expect(ensureProfileForEmail).toHaveBeenCalledWith("[email protected]");
216216
});
217217

218+
it("denies an identified write caller changing another profile's avatar", async () => {
219+
ensureProfileForEmail.mockReturnValue(profile);
220+
resolveUserProfileId.mockReturnValue("profile-2");
221+
222+
expect(
223+
await runUsersHandler(
224+
"users.setAvatar",
225+
{ profileId: "profile-2", mime: "image/png", avatarBase64: "AQ==" },
226+
selfClient,
227+
),
228+
).toHaveBeenCalledWith(
229+
false,
230+
undefined,
231+
expect.objectContaining({
232+
code: "FORBIDDEN",
233+
message: "profile edits require the owning user or operator.admin",
234+
}),
235+
);
236+
expect(setAvatar).not.toHaveBeenCalled();
237+
});
238+
218239
it("allows an owner to edit through a tombstoned durable profile id", async () => {
219240
ensureProfileForEmail.mockReturnValue(profile);
220241
resolveUserProfileId.mockReturnValue(profile.id);

‎src/gateway/server/ws-connection/connect-session.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
type PluginNodeCapabilitySurface,
3333
} from "../../plugin-node-capability.js";
3434
import { MAX_PAYLOAD_BYTES } from "../../server-constants.js";
35+
import { formatUserProfileAvatarPath } from "../../user-profiles-http-path.js";
3536
import { formatForLog, logWs } from "../../ws-log.js";
3637
import { truncateCloseReason } from "../close-reason.js";
3738
import { incrementPresenceVersion } from "../health-state.js";
@@ -149,6 +150,7 @@ export async function attachAuthenticatedGatewayConnect(
149150
profileId: profile.id,
150151
displayName: profile.displayName,
151152
hasAvatar: profile.avatarMime !== null,
153+
updatedAt: profile.updatedAt,
152154
};
153155
} catch (error) {
154156
// Profile storage must not block login; retain the legacy email-only identity on failure.
@@ -359,11 +361,12 @@ export async function attachAuthenticatedGatewayConnect(
359361
...(authenticatedUserProfile.displayName
360362
? { name: authenticatedUserProfile.displayName }
361363
: {}),
362-
...(authenticatedUserProfile.hasAvatar
363-
? {
364-
avatarUrl: `/api/users/${authenticatedUserProfile.profileId}/avatar`,
365-
}
366-
: {}),
364+
// This authenticated route resolves the uploaded avatar first, then the
365+
// gateway-side Gravatar proxy, so clients never need an email-hash URL.
366+
// The ?v=<updatedAt> revision changes when the profile (avatar) is
367+
// updated, so a reconnecting viewer's <img> refetches instead of reusing
368+
// a stale cached image for the unchanged route.
369+
avatarUrl: `${formatUserProfileAvatarPath(authenticatedUserProfile.profileId)}?v=${authenticatedUserProfile.updatedAt}`,
367370
}
368371
: { id: authenticatedUserId, email: authenticatedUserId },
369372
}

‎src/gateway/server/ws-connection/message-handler.post-connect-health.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,12 @@ describe("attachGatewayWsMessageHandler post-connect health refresh", () => {
617617
id: profileId,
618618
619619
name: "alice",
620+
// Published route carries the profile revision (?v=<updatedAt>) so a
621+
// reconnecting viewer's <img> refetches after an avatar upload instead
622+
// of reusing the stale cached image for an unchanged URL.
623+
avatarUrl: expect.stringMatching(
624+
new RegExp(`^/api/users/${profileId}/avatar\\?v=\\d+$`, "u"),
625+
),
620626
});
621627
expect(first.harness.client).toMatchObject({
622628
authenticatedUserId: "[email protected]",
@@ -633,7 +639,9 @@ describe("attachGatewayWsMessageHandler post-connect health refresh", () => {
633639
id: profileId,
634640
635641
name: "alice",
636-
avatarUrl: `/api/users/${profileId}/avatar`,
642+
avatarUrl: expect.stringMatching(
643+
new RegExp(`^/api/users/${profileId}/avatar\\?v=\\d+$`, "u"),
644+
),
637645
});
638646
expect(second.harness.client).toMatchObject({
639647
authenticatedUserProfile: { profileId, hasAvatar: true },

‎src/gateway/server/ws-types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type GatewayWsClient = PluginNodeCapabilityClient & {
3737
profileId: string;
3838
displayName: string | null;
3939
hasAvatar: boolean;
40+
updatedAt: number;
4041
};
4142
clientIp?: string;
4243
internal?: {

‎src/gateway/user-profiles-http-path.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const USER_PROFILE_AVATAR_PATH = /^\/api\/users\/([^/]+)\/avatar$/u;
22

3+
export function formatUserProfileAvatarPath(profileId: string): string {
4+
return `/api/users/${encodeURIComponent(profileId)}/avatar`;
5+
}
6+
37
export function matchUserProfileAvatarPath(pathname: string): string | undefined {
48
const profileId = USER_PROFILE_AVATAR_PATH.exec(pathname)?.[1];
59
if (!profileId) {

0 commit comments

Comments
 (0)