Profile pictures from Gravatar or the identity provider, fetched and kept by the server
Both sources are off until switched on under Settings, Sign-in. The server asks only gravatar.com (by a hash of the email) and the identity provider's own host, accepts only small PNG/JPEG/WebP/GIF, keeps each picture for a day and serves it from /api/avatars/<id>, so browsers never contact either. Shown in the user menu and on the Users page, with initials as the fallback; the Privacy page says when it is on. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9782bd3252
commit
c05c847d17
26 files changed
+4361
-21
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { Router } from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { users } from "../db/schema.js";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { getAvatar } from "../services/avatars.js";
|
||||
import { getSettings } from "../services/settingsStore.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const avatarsRouter = Router();
|
||||
avatarsRouter.use(requireAuth);
|
||||
|
||||
// A person's profile picture, for anyone signed in (their names are shown to everyone already). The server asks Gravatar or the identity
|
||||
// provider; the browser only ever talks to this app. 404 means "no picture": the page falls back to initials. With the setting off nothing is asked.
|
||||
avatarsRouter.get("/:id", asyncHandler(async (req, res) => {
|
||||
const id = /^\d+$/.test(req.params.id) ? Number(req.params.id) : NaN;
|
||||
if (!Number.isSafeInteger(id)) return res.status(404).json({ error: "not_found" });
|
||||
const [person] = await db.select({ email: users.email, pictureUrl: users.pictureUrl }).from(users).where(eq(users.id, id)).limit(1);
|
||||
if (!person) return res.status(404).json({ error: "not_found" });
|
||||
|
||||
const image = await getAvatar(person, (await getSettings()).profilePictures);
|
||||
if (!image) return res.status(404).json({ error: "no_picture" });
|
||||
|
||||
res.setHeader("Content-Type", image.contentType);
|
||||
// Kept an hour by the browser: short enough that turning the setting off, or a new picture, is not long in showing.
|
||||
res.setHeader("Cache-Control", "private, max-age=3600");
|
||||
res.setHeader("Content-Security-Policy", "default-src 'none'; sandbox");
|
||||
res.send(image.body);
|
||||
}));
|
||||
@@ -6,6 +6,8 @@ import { users } from "../db/schema.js";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
import { FIRST_LOOKBACK_MS, getChangesSince } from "../services/changesSince.js";
|
||||
import { avatarUrlFor } from "../services/avatars.js";
|
||||
import { getSettings } from "../services/settingsStore.js";
|
||||
|
||||
export const meRouter = Router();
|
||||
|
||||
@@ -36,10 +38,12 @@ export function parseDashboardLayout(stored: string | null): DashboardLayout {
|
||||
}
|
||||
}
|
||||
|
||||
meRouter.get("/", requireAuth, (req, res) => {
|
||||
const { id, email, name, role, oidcSub, favorites, dashboardLayout } = req.currentUser!;
|
||||
res.json({ user: { id, sub: oidcSub, email, name, role, favorites: parseFavorites(favorites), dashboard: parseDashboardLayout(dashboardLayout) } });
|
||||
});
|
||||
meRouter.get("/", requireAuth, asyncHandler(async (req, res) => {
|
||||
const me = req.currentUser!;
|
||||
const { id, email, name, role, oidcSub, favorites, dashboardLayout } = me;
|
||||
const avatarUrl = avatarUrlFor(me, (await getSettings()).profilePictures);
|
||||
res.json({ user: { id, sub: oidcSub, email, name, role, avatarUrl, favorites: parseFavorites(favorites), dashboard: parseDashboardLayout(dashboardLayout) } });
|
||||
}));
|
||||
|
||||
// Paths inside the app only: a slash, then letters, digits, dashes, underscores and further slashes — and, for a saved view of a page,
|
||||
// a short query of the characters a browser leaves as they are or percent-encodes (the search words, a status, a sort). Which of them
|
||||
|
||||
@@ -7,6 +7,7 @@ import { recordAudit } from "../services/audit.js";
|
||||
import { getSettings } from "../services/settingsStore.js";
|
||||
import { listSessions } from "../services/sessionStore.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
import { env } from "../env.js";
|
||||
|
||||
export const privacyRouter = Router();
|
||||
privacyRouter.use(requireAuth);
|
||||
@@ -46,7 +47,7 @@ privacyRouter.get("/", asyncHandler(async (req, res) => {
|
||||
|
||||
res.json({
|
||||
me: {
|
||||
user: { email: me.email, name: me.name, role: me.role, subject: me.oidcSub, createdAt: me.createdAt, lastLoginAt: me.lastLoginAt },
|
||||
user: { email: me.email, name: me.name, role: me.role, subject: me.oidcSub, createdAt: me.createdAt, lastLoginAt: me.lastLoginAt, pictureUrl: me.pictureUrl },
|
||||
auditEntries,
|
||||
sessions: await ownSessions(me.oidcSub, req.sessionID),
|
||||
},
|
||||
@@ -58,6 +59,7 @@ privacyRouter.get("/", asyncHandler(async (req, res) => {
|
||||
tlsCertificateChecks: tlsChecks,
|
||||
servers: serverCount,
|
||||
serversWithAgent: agentCount,
|
||||
profilePictures: { ...settings.profilePictures, identityProviderHost: isAdmin ? hostOf(env.authentik.issuerUrl) : null },
|
||||
channels: {
|
||||
gotify: channel(settings.gotify.enabled, hostOf(settings.gotify.url)),
|
||||
ntfy: channel(settings.ntfy.enabled, hostOf(settings.ntfy.url)),
|
||||
@@ -84,7 +86,7 @@ privacyRouter.get("/export", asyncHandler(async (req, res) => {
|
||||
const body = {
|
||||
exportedAt: new Date().toISOString(),
|
||||
note: "Everything Homelab Manager holds that is specifically about you. Other people's data, server data and shared inventory are not included.",
|
||||
account: { email: row.email, name: row.name, role: row.role, subject: row.oidcSub, createdAt: row.createdAt, lastLoginAt: row.lastLoginAt },
|
||||
account: { email: row.email, name: row.name, role: row.role, subject: row.oidcSub, createdAt: row.createdAt, lastLoginAt: row.lastLoginAt, pictureUrl: row.pictureUrl },
|
||||
sessions: await ownSessions(me.oidcSub, req.sessionID),
|
||||
auditLog: entries.map((e) => ({ ...e, detail: e.detail ? safeJson(e.detail) : null })),
|
||||
};
|
||||
|
||||
@@ -160,6 +160,7 @@ const updateSchema = z.object({
|
||||
})
|
||||
.partial()
|
||||
.optional(),
|
||||
profilePictures: z.object({ gravatar: z.boolean(), identityProvider: z.boolean() }).partial().optional(),
|
||||
digest: z
|
||||
.object({ enabled: z.boolean(), day: z.number().int().min(0).max(6), time: z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/) })
|
||||
.partial()
|
||||
|
||||
@@ -8,6 +8,7 @@ import { recordAudit } from "../services/audit.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
import { getSettings } from "../services/settingsStore.js";
|
||||
import { roleFromGroups } from "../auth/groups.js";
|
||||
import { avatarUrlFor } from "../services/avatars.js";
|
||||
|
||||
export const usersRouter = Router();
|
||||
|
||||
@@ -26,9 +27,9 @@ export function parseGroups(stored: string | null): string[] | null {
|
||||
|
||||
usersRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
const rows = await db.select().from(users).orderBy(users.createdAt);
|
||||
const { signIn } = await getSettings();
|
||||
const { signIn, profilePictures } = await getSettings();
|
||||
res.json({
|
||||
users: rows.map((u) => ({ id: u.id, oidcSub: u.oidcSub, email: u.email, name: u.name, role: u.role, createdAt: u.createdAt, lastLoginAt: u.lastLoginAt, groups: parseGroups(u.groups) })),
|
||||
users: rows.map((u) => ({ id: u.id, oidcSub: u.oidcSub, email: u.email, name: u.name, role: u.role, createdAt: u.createdAt, lastLoginAt: u.lastLoginAt, groups: parseGroups(u.groups), avatarUrl: avatarUrlFor(u, profilePictures) })),
|
||||
// When roles follow groups, a role set by hand would be undone at the next sign-in, so the page says so instead of offering it.
|
||||
rolesFollowGroups: signIn.roleFromGroups,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user