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
@@ -91,6 +91,7 @@ Everyone who has signed in through Authentik. The first one becomes admin.
|
|||||||
| `created_at` | text NOT NULL | SQLite UTC. |
|
| `created_at` | text NOT NULL | SQLite UTC. |
|
||||||
| `last_login_at` | text | ISO. |
|
| `last_login_at` | text | ISO. |
|
||||||
| `favorites` | text | JSON array of the page paths this person pinned to the top of their menu (`["/servers","/alerts"]`), up to 24. A path may carry a short query for a saved view of a page (`"/servers?status=offline"`). Follows them to any browser. |
|
| `favorites` | text | JSON array of the page paths this person pinned to the top of their menu (`["/servers","/alerts"]`), up to 24. A path may carry a short query for a saved view of a page (`"/servers?status=offline"`). Follows them to any browser. |
|
||||||
|
| `picture_url` | text | The `picture` claim the identity provider gave at the last sign-in. Only an address; nothing is fetched from it unless Settings → Sign-in → Profile pictures allows it (and then only Gravatar or the provider's own host). Pictures themselves are kept in the server's memory for a day, not in the database. |
|
||||||
| `dashboard_layout` | text | JSON object `{"hidden":["Gitea"],"order":{"Secrets":0,"DNS":1}}`: the dashboard cards this person hid and the order of the rest (lower first; a card with no entry goes last). Null = the default layout. Follows them to any browser. |
|
| `dashboard_layout` | text | JSON object `{"hidden":["Gitea"],"order":{"Secrets":0,"DNS":1}}`: the dashboard cards this person hid and the order of the rest (lower first; a card with no entry goes last). Null = the default layout. Follows them to any browser. |
|
||||||
| `groups` | text | JSON array of the groups the identity provider reported at this person's last sign-in (null until they have signed in with groups available) — shown on the Users page, and what "roles from groups" works from. |
|
| `groups` | text | JSON array of the groups the identity provider reported at this person's last sign-in (null until they have signed in with groups available) — shown on the Users page, and what "roles from groups" works from. |
|
||||||
| `last_looked_at` | text | ISO time this person last pressed "Got it" on the dashboard's "Since you last looked" card; the next summary starts there (null = never: the last day is shown). |
|
| `last_looked_at` | text | ISO time this person last pressed "Got it" on the dashboard's "Since you last looked" card; the next summary starts there (null = never: the last day is shown). |
|
||||||
|
|||||||
@@ -633,6 +633,13 @@ group rule, the first person ever is still the administrator, and while it is on
|
|||||||
Users page shows roles instead of letting you set them. The Users page also shows the
|
Users page shows roles instead of letting you set them. The Users page also shows the
|
||||||
groups each person had at their last sign-in.
|
groups each person had at their last sign-in.
|
||||||
|
|
||||||
|
**Profile pictures** (Settings → Sign-in, both sources off until switched on). Without one a person is their initials. An administrator can allow the picture the
|
||||||
|
identity provider names in its `picture` claim (kept at each sign-in; only an address on Authentik's own host or on Gravatar is ever used, so a claim can't make the
|
||||||
|
server fetch just anywhere) and/or **Gravatar** (by a SHA-256 hash of the person's email — never the address itself). The picture from the provider is tried first.
|
||||||
|
Either way it is **the server** that asks: it checks what comes back (a small PNG, JPEG, WebP or GIF — never SVG), keeps it for a day, and serves it from `/api/avatars/<id>`
|
||||||
|
to anyone signed in, so people's browsers never contact Gravatar or Authentik for it, and a person with no picture, or a host that can't be reached, simply shows initials.
|
||||||
|
The Privacy page says when it is on. The picture shows in the user menu and on the Users page.
|
||||||
|
|
||||||
**Prometheus and webhooks** (Settings → API and webhooks). `/metrics` answers in
|
**Prometheus and webhooks** (Settings → API and webhooks). `/metrics` answers in
|
||||||
Prometheus's text format — servers up or not, load, memory, disks, waiting updates,
|
Prometheus's text format — servers up or not, load, memory, disks, waiting updates,
|
||||||
agent versions, alert counts, which integrations work, maintenance, what is about to
|
agent versions, alert counts, which integrations work, maintenance, what is about to
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ even further, to admin only:
|
|||||||
ignore** on its Host health card. Everyone sees *What the agent couldn't collect*.
|
ignore** on its Host health card. Everyone sees *What the agent couldn't collect*.
|
||||||
- **Host health** (failed services, disk health, ZFS pools) is shown to everyone on a server's page; **Update agents automatically**
|
- **Host health** (failed services, disk health, ZFS pools) is shown to everyone on a server's page; **Update agents automatically**
|
||||||
on the Servers page is admin-only.
|
on the Servers page is admin-only.
|
||||||
|
- **Profile pictures** are shown to everyone signed in (`/api/avatars/<id>`, the same people whose names everyone already sees); which sources are allowed is under
|
||||||
|
Settings → Sign-in, so admin-only.
|
||||||
- **Sign-in groups, metrics tokens, event webhooks, share links (the wall display and the status pages, and what is on them) and the
|
- **Sign-in groups, metrics tokens, event webhooks, share links (the wall display and the status pages, and what is on them) and the
|
||||||
Grafana dashboard download** are all under Settings, so admin-only; `/metrics` itself needs a metrics token, not a login.
|
Grafana dashboard download** are all under Settings, so admin-only; `/metrics` itself needs a metrics token, not a login.
|
||||||
- Everything under **Settings** (notification channels, badge colors,
|
- Everything under **Settings** (notification channels, badge colors,
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE `users` ADD `picture_url` text;
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -288,6 +288,13 @@
|
|||||||
"when": 1792357895858,
|
"when": 1792357895858,
|
||||||
"tag": "0040_petite_invaders",
|
"tag": "0040_petite_invaders",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 41,
|
||||||
|
"version": "6",
|
||||||
|
"when": 1792359507903,
|
||||||
|
"tag": "0041_open_silvermane",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,7 @@ import { alertsRouter } from "./routes/alerts.js";
|
|||||||
import { mapRouter } from "./routes/map.js";
|
import { mapRouter } from "./routes/map.js";
|
||||||
import { generatorRouter } from "./routes/generator.js";
|
import { generatorRouter } from "./routes/generator.js";
|
||||||
import { alertTicketsRouter } from "./routes/alertTickets.js";
|
import { alertTicketsRouter } from "./routes/alertTickets.js";
|
||||||
|
import { avatarsRouter } from "./routes/avatars.js";
|
||||||
import { apiErrorHandler } from "./utils/apiErrorHandler.js";
|
import { apiErrorHandler } from "./utils/apiErrorHandler.js";
|
||||||
import { securityHeaders } from "./utils/securityHeaders.js";
|
import { securityHeaders } from "./utils/securityHeaders.js";
|
||||||
import { sameOriginGuard } from "./utils/sameOriginGuard.js";
|
import { sameOriginGuard } from "./utils/sameOriginGuard.js";
|
||||||
@@ -103,6 +104,7 @@ export function createApp() {
|
|||||||
|
|
||||||
app.use("/auth", authRouter);
|
app.use("/auth", authRouter);
|
||||||
app.use("/api/me", meRouter);
|
app.use("/api/me", meRouter);
|
||||||
|
app.use("/api/avatars", avatarsRouter);
|
||||||
app.use("/api/uptime", uptimeRouter);
|
app.use("/api/uptime", uptimeRouter);
|
||||||
app.use("/api/share-links", shareLinksRouter);
|
app.use("/api/share-links", shareLinksRouter);
|
||||||
app.use("/api/runbooks", runbooksRouter);
|
app.use("/api/runbooks", runbooksRouter);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { users } from "../db/schema.js";
|
|||||||
import { recordAudit } from "../services/audit.js";
|
import { recordAudit } from "../services/audit.js";
|
||||||
import { verifyIdTokenSignature } from "./idToken.js";
|
import { verifyIdTokenSignature } from "./idToken.js";
|
||||||
import { rateLimit } from "../utils/rateLimit.js";
|
import { rateLimit } from "../utils/rateLimit.js";
|
||||||
|
import { pictureFromClaims } from "../services/avatars.js";
|
||||||
|
|
||||||
export const authRouter = Router();
|
export const authRouter = Router();
|
||||||
|
|
||||||
@@ -130,7 +131,7 @@ authRouter.get("/callback", signInLimiter, async (req, res, next) => {
|
|||||||
console.warn(`[auth] roles follow groups, but the sign-in carried no "${signIn.groupsClaim}" claim — roles left as they are`);
|
console.warn(`[auth] roles follow groups, but the sign-in carried no "${signIn.groupsClaim}" claim — roles left as they are`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { user, created, roleChange } = await upsertUserFromLogin({ sub: claims.sub, email, name, groups });
|
const { user, created, roleChange } = await upsertUserFromLogin({ sub: claims.sub, email, name, groups, pictureUrl: pictureFromClaims(claimSources) });
|
||||||
if (roleChange) {
|
if (roleChange) {
|
||||||
await recordAudit({
|
await recordAudit({
|
||||||
actor: user,
|
actor: user,
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ export async function upsertUserFromLogin(params: {
|
|||||||
email?: string;
|
email?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
groups?: string[] | null;
|
groups?: string[] | null;
|
||||||
|
/** The identity provider's "picture" claim, when it gave one; left as it was when it did not. */
|
||||||
|
pictureUrl?: string;
|
||||||
}): Promise<{ user: typeof users.$inferSelect; created: boolean; roleChange?: RoleChange }> {
|
}): Promise<{ user: typeof users.$inferSelect; created: boolean; roleChange?: RoleChange }> {
|
||||||
const [existing] = await db.select().from(users).where(eq(users.oidcSub, params.sub)).limit(1);
|
const [existing] = await db.select().from(users).where(eq(users.oidcSub, params.sub)).limit(1);
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
@@ -55,6 +57,7 @@ export async function upsertUserFromLogin(params: {
|
|||||||
.set({
|
.set({
|
||||||
email: params.email ?? existing.email,
|
email: params.email ?? existing.email,
|
||||||
name: params.name ?? existing.name,
|
name: params.name ?? existing.name,
|
||||||
|
pictureUrl: params.pictureUrl ?? existing.pictureUrl,
|
||||||
lastLoginAt: now,
|
lastLoginAt: now,
|
||||||
role,
|
role,
|
||||||
...(groupsJson !== undefined ? { groups: groupsJson } : {}),
|
...(groupsJson !== undefined ? { groups: groupsJson } : {}),
|
||||||
@@ -74,6 +77,7 @@ export async function upsertUserFromLogin(params: {
|
|||||||
oidcSub: params.sub,
|
oidcSub: params.sub,
|
||||||
email: params.email,
|
email: params.email,
|
||||||
name: params.name,
|
name: params.name,
|
||||||
|
pictureUrl: params.pictureUrl ?? null,
|
||||||
role,
|
role,
|
||||||
lastLoginAt: now,
|
lastLoginAt: now,
|
||||||
...(groupsJson !== undefined ? { groups: groupsJson } : {}),
|
...(groupsJson !== undefined ? { groups: groupsJson } : {}),
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ export const users = sqliteTable("users", {
|
|||||||
// How this person arranged the dashboard: a JSON object with the cards they hid ("hidden": ["Gitea"]) and the order of the others
|
// How this person arranged the dashboard: a JSON object with the cards they hid ("hidden": ["Gitea"]) and the order of the others
|
||||||
// ("order": {"DNS": 0, "Secrets": 1}). Follows them to any browser; null is the default layout.
|
// ("order": {"DNS": 0, "Secrets": 1}). Follows them to any browser; null is the default layout.
|
||||||
dashboardLayout: text("dashboard_layout"),
|
dashboardLayout: text("dashboard_layout"),
|
||||||
|
// The address of the picture the identity provider gave for this person (the OIDC "picture" claim), as of their last sign-in. Only an address:
|
||||||
|
// nothing is fetched from it unless Settings → Sign-in → Profile pictures allows it, and then only by this server, never by the browser.
|
||||||
|
pictureUrl: text("picture_url"),
|
||||||
});
|
});
|
||||||
|
|
||||||
// ─── Audit log ──────────────────────────────────────────────────────────────
|
// ─── Audit log ──────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -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 { requireAuth } from "../auth/middleware.js";
|
||||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||||
import { FIRST_LOOKBACK_MS, getChangesSince } from "../services/changesSince.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();
|
export const meRouter = Router();
|
||||||
|
|
||||||
@@ -36,10 +38,12 @@ export function parseDashboardLayout(stored: string | null): DashboardLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
meRouter.get("/", requireAuth, (req, res) => {
|
meRouter.get("/", requireAuth, asyncHandler(async (req, res) => {
|
||||||
const { id, email, name, role, oidcSub, favorites, dashboardLayout } = req.currentUser!;
|
const me = req.currentUser!;
|
||||||
res.json({ user: { id, sub: oidcSub, email, name, role, favorites: parseFavorites(favorites), dashboard: parseDashboardLayout(dashboardLayout) } });
|
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,
|
// 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
|
// 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 { getSettings } from "../services/settingsStore.js";
|
||||||
import { listSessions } from "../services/sessionStore.js";
|
import { listSessions } from "../services/sessionStore.js";
|
||||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||||
|
import { env } from "../env.js";
|
||||||
|
|
||||||
export const privacyRouter = Router();
|
export const privacyRouter = Router();
|
||||||
privacyRouter.use(requireAuth);
|
privacyRouter.use(requireAuth);
|
||||||
@@ -46,7 +47,7 @@ privacyRouter.get("/", asyncHandler(async (req, res) => {
|
|||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
me: {
|
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,
|
auditEntries,
|
||||||
sessions: await ownSessions(me.oidcSub, req.sessionID),
|
sessions: await ownSessions(me.oidcSub, req.sessionID),
|
||||||
},
|
},
|
||||||
@@ -58,6 +59,7 @@ privacyRouter.get("/", asyncHandler(async (req, res) => {
|
|||||||
tlsCertificateChecks: tlsChecks,
|
tlsCertificateChecks: tlsChecks,
|
||||||
servers: serverCount,
|
servers: serverCount,
|
||||||
serversWithAgent: agentCount,
|
serversWithAgent: agentCount,
|
||||||
|
profilePictures: { ...settings.profilePictures, identityProviderHost: isAdmin ? hostOf(env.authentik.issuerUrl) : null },
|
||||||
channels: {
|
channels: {
|
||||||
gotify: channel(settings.gotify.enabled, hostOf(settings.gotify.url)),
|
gotify: channel(settings.gotify.enabled, hostOf(settings.gotify.url)),
|
||||||
ntfy: channel(settings.ntfy.enabled, hostOf(settings.ntfy.url)),
|
ntfy: channel(settings.ntfy.enabled, hostOf(settings.ntfy.url)),
|
||||||
@@ -84,7 +86,7 @@ privacyRouter.get("/export", asyncHandler(async (req, res) => {
|
|||||||
const body = {
|
const body = {
|
||||||
exportedAt: new Date().toISOString(),
|
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.",
|
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),
|
sessions: await ownSessions(me.oidcSub, req.sessionID),
|
||||||
auditLog: entries.map((e) => ({ ...e, detail: e.detail ? safeJson(e.detail) : null })),
|
auditLog: entries.map((e) => ({ ...e, detail: e.detail ? safeJson(e.detail) : null })),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ const updateSchema = z.object({
|
|||||||
})
|
})
|
||||||
.partial()
|
.partial()
|
||||||
.optional(),
|
.optional(),
|
||||||
|
profilePictures: z.object({ gravatar: z.boolean(), identityProvider: z.boolean() }).partial().optional(),
|
||||||
digest: z
|
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$/) })
|
.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()
|
.partial()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { recordAudit } from "../services/audit.js";
|
|||||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||||
import { getSettings } from "../services/settingsStore.js";
|
import { getSettings } from "../services/settingsStore.js";
|
||||||
import { roleFromGroups } from "../auth/groups.js";
|
import { roleFromGroups } from "../auth/groups.js";
|
||||||
|
import { avatarUrlFor } from "../services/avatars.js";
|
||||||
|
|
||||||
export const usersRouter = Router();
|
export const usersRouter = Router();
|
||||||
|
|
||||||
@@ -26,9 +27,9 @@ export function parseGroups(stored: string | null): string[] | null {
|
|||||||
|
|
||||||
usersRouter.get("/", asyncHandler(async (_req, res) => {
|
usersRouter.get("/", asyncHandler(async (_req, res) => {
|
||||||
const rows = await db.select().from(users).orderBy(users.createdAt);
|
const rows = await db.select().from(users).orderBy(users.createdAt);
|
||||||
const { signIn } = await getSettings();
|
const { signIn, profilePictures } = await getSettings();
|
||||||
res.json({
|
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.
|
// 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,
|
rolesFollowGroups: signIn.roleFromGroups,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,186 @@
|
|||||||
|
/**
|
||||||
|
* Profile pictures, fetched and kept by this server so that people's browsers never contact an outside address.
|
||||||
|
*
|
||||||
|
* Where a picture can come from (Settings → Sign-in → Profile pictures, both off until an administrator turns them on):
|
||||||
|
* - the identity provider's own "picture" claim, tried first, and
|
||||||
|
* - Gravatar, by a SHA-256 hash of the person's email address (never the address itself).
|
||||||
|
*
|
||||||
|
* The server only ever asks the hosts it is allowed to: gravatar.com, and the identity provider's own host. A "picture" claim naming anywhere
|
||||||
|
* else is ignored, so a claim cannot be used to make the server fetch an arbitrary address. What comes back must be a small PNG, JPEG, WebP or
|
||||||
|
* GIF — never SVG, which can carry script and would be served from this app's own origin.
|
||||||
|
*/
|
||||||
|
import { createHash } from "node:crypto";
|
||||||
|
import { env } from "../env.js";
|
||||||
|
import type { ProfilePictureSettings } from "./settingsStore.js";
|
||||||
|
|
||||||
|
/** What the server will accept as a picture. */
|
||||||
|
const MAX_BYTES = 256 * 1024;
|
||||||
|
const TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
|
||||||
|
const FETCH_TIMEOUT_MS = 4000;
|
||||||
|
const MAX_REDIRECTS = 2;
|
||||||
|
const FOUND_TTL_MS = 24 * 3600_000;
|
||||||
|
/** Someone with no picture is asked about again after this, so adding one shows up the same day without asking every page view. */
|
||||||
|
const MISSING_TTL_MS = 3600_000;
|
||||||
|
/** A host that could not be reached is tried again soon. */
|
||||||
|
const FAILED_TTL_MS = 5 * 60_000;
|
||||||
|
const MAX_CACHED = 200;
|
||||||
|
|
||||||
|
export interface AvatarImage {
|
||||||
|
contentType: string;
|
||||||
|
body: Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AvatarFetcher = (url: string) => Promise<Response>;
|
||||||
|
|
||||||
|
const realFetcher: AvatarFetcher = (url) =>
|
||||||
|
fetch(url, { redirect: "manual", signal: AbortSignal.timeout(FETCH_TIMEOUT_MS), headers: { accept: [...TYPES].join(", "), "user-agent": "HomelabManager" } });
|
||||||
|
|
||||||
|
let fetcher: AvatarFetcher = realFetcher;
|
||||||
|
/** Tests stand in for the network. */
|
||||||
|
export function setAvatarFetcherForTests(f: AvatarFetcher | null): void {
|
||||||
|
fetcher = f ?? realFetcher;
|
||||||
|
cache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A person's email as Gravatar wants it: trimmed, lower case, SHA-256. */
|
||||||
|
export function gravatarHash(email: string): string {
|
||||||
|
return createHash("sha256").update(email.trim().toLowerCase()).digest("hex");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function gravatarUrl(email: string): string {
|
||||||
|
return `https://gravatar.com/avatar/${gravatarHash(email)}?s=128&d=404`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function issuerHost(): string | null {
|
||||||
|
try {
|
||||||
|
return new URL(env.authentik.issuerUrl).host.toLowerCase();
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isGravatarHost = (host: string) => host === "gravatar.com" || host.endsWith(".gravatar.com");
|
||||||
|
|
||||||
|
/** Whether the server may ask this address for a picture: Gravatar over HTTPS, or the identity provider's own host. */
|
||||||
|
export function isAllowedPictureUrl(raw: string, idpHost: string | null = issuerHost()): boolean {
|
||||||
|
let url: URL;
|
||||||
|
try {
|
||||||
|
url = new URL(raw);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const host = url.host.toLowerCase();
|
||||||
|
if (url.username || url.password) return false;
|
||||||
|
if (isGravatarHost(url.hostname.toLowerCase())) return url.protocol === "https:";
|
||||||
|
return idpHost !== null && host === idpHost && (url.protocol === "https:" || url.protocol === "http:");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The "picture" claim, if it is an address at all; kept as given and judged again whenever it is used. */
|
||||||
|
export function pictureFromClaims(sources: Record<string, unknown>[]): string | undefined {
|
||||||
|
for (const source of sources) {
|
||||||
|
const value = source.picture;
|
||||||
|
if (typeof value !== "string") continue;
|
||||||
|
const trimmed = value.trim();
|
||||||
|
if (trimmed.length === 0 || trimmed.length > 500) continue;
|
||||||
|
try {
|
||||||
|
const url = new URL(trimmed);
|
||||||
|
if (url.protocol === "https:" || url.protocol === "http:") return trimmed;
|
||||||
|
} catch {
|
||||||
|
// not an address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The addresses this person's picture may be fetched from under the current settings, in the order they are tried. */
|
||||||
|
export function avatarSources(user: { email: string | null; pictureUrl: string | null }, settings: ProfilePictureSettings, idpHost: string | null = issuerHost()): string[] {
|
||||||
|
const out: string[] = [];
|
||||||
|
if (settings.identityProvider && user.pictureUrl && isAllowedPictureUrl(user.pictureUrl, idpHost)) {
|
||||||
|
// A claim that names Gravatar is Gravatar all the same: it needs that switched on too.
|
||||||
|
let host = "";
|
||||||
|
try {
|
||||||
|
host = new URL(user.pictureUrl).hostname.toLowerCase();
|
||||||
|
} catch {
|
||||||
|
// judged above
|
||||||
|
}
|
||||||
|
if (!isGravatarHost(host) || settings.gravatar) out.push(user.pictureUrl);
|
||||||
|
}
|
||||||
|
if (settings.gravatar && user.email && user.email.includes("@")) out.push(gravatarUrl(user.email));
|
||||||
|
return [...new Set(out)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The address the browser asks this server for, or null when there is no picture to look for. `v` changes with the source so a new one is not hidden by the browser's copy. */
|
||||||
|
export function avatarUrlFor(user: { id: number; email: string | null; pictureUrl: string | null }, settings: ProfilePictureSettings): string | null {
|
||||||
|
const sources = avatarSources(user, settings);
|
||||||
|
if (sources.length === 0) return null;
|
||||||
|
return `/api/avatars/${user.id}?v=${createHash("sha256").update(sources.join("\n")).digest("hex").slice(0, 8)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Fetching and keeping ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
interface Entry {
|
||||||
|
until: number;
|
||||||
|
image: AvatarImage | null;
|
||||||
|
}
|
||||||
|
const cache = new Map<string, Entry>();
|
||||||
|
|
||||||
|
function remember(url: string, image: AvatarImage | null, ttl: number): void {
|
||||||
|
cache.delete(url);
|
||||||
|
cache.set(url, { until: Date.now() + ttl, image });
|
||||||
|
while (cache.size > MAX_CACHED) cache.delete(cache.keys().next().value as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One picture from one address: followed through at most two redirects, only to addresses that are allowed too. */
|
||||||
|
async function download(start: string): Promise<{ image: AvatarImage | null; failed: boolean }> {
|
||||||
|
let url = start;
|
||||||
|
for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
|
||||||
|
let res: Response;
|
||||||
|
try {
|
||||||
|
res = await fetcher(url);
|
||||||
|
} catch {
|
||||||
|
return { image: null, failed: true };
|
||||||
|
}
|
||||||
|
if (res.status >= 300 && res.status < 400) {
|
||||||
|
const location = res.headers.get("location");
|
||||||
|
let next: string | null = null;
|
||||||
|
try {
|
||||||
|
next = location ? new URL(location, url).toString() : null;
|
||||||
|
} catch {
|
||||||
|
next = null;
|
||||||
|
}
|
||||||
|
if (!next || !isAllowedPictureUrl(next)) return { image: null, failed: false };
|
||||||
|
url = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (res.status >= 500) return { image: null, failed: true };
|
||||||
|
if (!res.ok) return { image: null, failed: false };
|
||||||
|
const type = (res.headers.get("content-type") ?? "").split(";")[0].trim().toLowerCase();
|
||||||
|
if (!TYPES.has(type)) return { image: null, failed: false };
|
||||||
|
const declared = Number(res.headers.get("content-length"));
|
||||||
|
if (Number.isFinite(declared) && declared > MAX_BYTES) return { image: null, failed: false };
|
||||||
|
let body: Buffer;
|
||||||
|
try {
|
||||||
|
body = Buffer.from(await res.arrayBuffer());
|
||||||
|
} catch {
|
||||||
|
return { image: null, failed: true };
|
||||||
|
}
|
||||||
|
if (body.length === 0 || body.length > MAX_BYTES) return { image: null, failed: false };
|
||||||
|
return { image: { contentType: type, body }, failed: false };
|
||||||
|
}
|
||||||
|
return { image: null, failed: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The first of this person's sources that has a picture, from the keep or from the source itself. Null when none does. */
|
||||||
|
export async function getAvatar(user: { email: string | null; pictureUrl: string | null }, settings: ProfilePictureSettings): Promise<AvatarImage | null> {
|
||||||
|
for (const source of avatarSources(user, settings)) {
|
||||||
|
const kept = cache.get(source);
|
||||||
|
if (kept && kept.until > Date.now()) {
|
||||||
|
if (kept.image) return kept.image;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const { image, failed } = await download(source);
|
||||||
|
remember(source, image, image ? FOUND_TTL_MS : failed ? FAILED_TTL_MS : MISSING_TTL_MS);
|
||||||
|
if (image) return image;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -135,6 +135,17 @@ export interface SignInSettings {
|
|||||||
otherwise: "viewer" | "keep";
|
otherwise: "viewer" | "keep";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where people's profile pictures may come from. Both are off until an administrator turns them on, because each means this server asks an
|
||||||
|
* outside address for a picture (Gravatar is told a hash of the person's email). The browser never does: pictures are fetched and kept by the server.
|
||||||
|
*/
|
||||||
|
export interface ProfilePictureSettings {
|
||||||
|
/** gravatar.com, by a hash of the person's email address. */
|
||||||
|
gravatar: boolean;
|
||||||
|
/** The picture the identity provider (Authentik) names for the person in its "picture" claim. */
|
||||||
|
identityProvider: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/** How the agents out on the servers are kept up to date. Off until an administrator turns it on. */
|
/** How the agents out on the servers are kept up to date. Off until an administrator turns it on. */
|
||||||
export interface AgentSettings {
|
export interface AgentSettings {
|
||||||
/** An agent that is behind downloads the newer script from this app, checks it and replaces itself. */
|
/** An agent that is behind downloads the newer script from this app, checks it and replaces itself. */
|
||||||
@@ -215,6 +226,7 @@ export interface AppSettings {
|
|||||||
healthChecks: HealthCheckSettings;
|
healthChecks: HealthCheckSettings;
|
||||||
digest: DigestSettings;
|
digest: DigestSettings;
|
||||||
signIn: SignInSettings;
|
signIn: SignInSettings;
|
||||||
|
profilePictures: ProfilePictureSettings;
|
||||||
inventory: InventorySettings;
|
inventory: InventorySettings;
|
||||||
selfBackup: SelfBackupSettings;
|
selfBackup: SelfBackupSettings;
|
||||||
agents: AgentSettings;
|
agents: AgentSettings;
|
||||||
@@ -258,6 +270,7 @@ const DEFAULTS: AppSettings = {
|
|||||||
inventory: { currency: "", pricePerKwh: null },
|
inventory: { currency: "", pricePerKwh: null },
|
||||||
agents: { autoUpdate: false },
|
agents: { autoUpdate: false },
|
||||||
selfBackup: { enabled: true, time: "03:30", keep: 14 },
|
selfBackup: { enabled: true, time: "03:30", keep: 14 },
|
||||||
|
profilePictures: { gravatar: false, identityProvider: false },
|
||||||
signIn: { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" },
|
signIn: { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" },
|
||||||
healthChecks: { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0 },
|
healthChecks: { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0 },
|
||||||
// Docker's default bridge (172.17.0.0/16) and the pool it hands custom networks from (172.18–31) live here, and every
|
// Docker's default bridge (172.17.0.0/16) and the pool it hands custom networks from (172.18–31) live here, and every
|
||||||
|
|||||||
@@ -0,0 +1,252 @@
|
|||||||
|
/**
|
||||||
|
* Profile pictures: where they may come from, what is accepted, that nothing is asked of anyone while the settings are off, and that the
|
||||||
|
* browser only ever talks to this app.
|
||||||
|
*
|
||||||
|
* Run with: npm test --workspace server
|
||||||
|
*/
|
||||||
|
import { test, describe, before, after, beforeEach } from "node:test";
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { createHash } from "node:crypto";
|
||||||
|
import { mkdtempSync, rmSync } from "node:fs";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import type { AddressInfo } from "node:net";
|
||||||
|
import type { Server } from "node:http";
|
||||||
|
|
||||||
|
const dir = mkdtempSync(join(tmpdir(), "hm-avatars-"));
|
||||||
|
process.env.DATABASE_PATH = join(dir, "test.sqlite");
|
||||||
|
process.env.SESSION_DIR = join(dir, "sessions");
|
||||||
|
process.env.CREDENTIALS_ENCRYPTION_KEY = "ab".repeat(32);
|
||||||
|
process.env.HEALTH_STARTUP_GRACE_MS = "0";
|
||||||
|
process.env.AUTHENTIK_ISSUER_URL = "https://auth.example.lan/application/o/homelab/";
|
||||||
|
|
||||||
|
const express = (await import("express")).default;
|
||||||
|
const { db } = await import("../src/db/client.js");
|
||||||
|
const { users } = await import("../src/db/schema.js");
|
||||||
|
const { runMigrations } = await import("../src/db/migrate.js");
|
||||||
|
const { avatarsRouter } = await import("../src/routes/avatars.js");
|
||||||
|
const { meRouter } = await import("../src/routes/me.js");
|
||||||
|
const { usersRouter } = await import("../src/routes/users.js");
|
||||||
|
const { upsertUserFromLogin } = await import("../src/auth/users.js");
|
||||||
|
const { updateSettings } = await import("../src/services/settingsStore.js");
|
||||||
|
const { gravatarHash, gravatarUrl, isAllowedPictureUrl, pictureFromClaims, avatarSources, avatarUrlFor, getAvatar, setAvatarFetcherForTests } = await import("../src/services/avatars.js");
|
||||||
|
|
||||||
|
await runMigrations();
|
||||||
|
|
||||||
|
const IDP = "auth.example.lan";
|
||||||
|
const PNG = Buffer.from("89504e470d0a1a0a0000000d49484452", "hex");
|
||||||
|
const none = { gravatar: false, identityProvider: false };
|
||||||
|
const both = { gravatar: true, identityProvider: true };
|
||||||
|
|
||||||
|
describe("where a picture may come from", () => {
|
||||||
|
test("Gravatar gets a hash of the address — trimmed, lower case, SHA-256 — never the address itself", () => {
|
||||||
|
const hash = createHash("sha256").update("olga@example.com").digest("hex");
|
||||||
|
assert.equal(gravatarHash(" Olga@Example.COM "), hash);
|
||||||
|
assert.equal(gravatarUrl("Olga@example.com"), `https://gravatar.com/avatar/${hash}?s=128&d=404`);
|
||||||
|
assert.equal(gravatarUrl("Olga@example.com").includes("olga"), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("only Gravatar over HTTPS and the identity provider's own host are allowed", () => {
|
||||||
|
assert.equal(isAllowedPictureUrl("https://gravatar.com/avatar/abc", IDP), true);
|
||||||
|
assert.equal(isAllowedPictureUrl("https://secure.gravatar.com/avatar/abc", IDP), true);
|
||||||
|
assert.equal(isAllowedPictureUrl("http://gravatar.com/avatar/abc", IDP), false, "Gravatar only over HTTPS");
|
||||||
|
assert.equal(isAllowedPictureUrl("https://auth.example.lan/media/me.png", IDP), true);
|
||||||
|
assert.equal(isAllowedPictureUrl("http://auth.example.lan/media/me.png", IDP), true, "the provider's own host may be plain HTTP on a LAN");
|
||||||
|
for (const bad of ["https://evil.example/me.png", "https://gravatar.com.evil.example/a", "https://evilgravatar.com/a", "http://169.254.169.254/latest", "https://user:pw@auth.example.lan/x", "file:///etc/passwd", "not a url"]) {
|
||||||
|
assert.equal(isAllowedPictureUrl(bad, IDP), false, bad);
|
||||||
|
}
|
||||||
|
assert.equal(isAllowedPictureUrl("https://auth.example.lan/x", null), false, "with no provider known, only Gravatar");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the picture claim is read from the ID token or userinfo, and only if it is an address", () => {
|
||||||
|
assert.equal(pictureFromClaims([{ sub: "a" }, { picture: "https://auth.example.lan/media/me.png" }]), "https://auth.example.lan/media/me.png");
|
||||||
|
assert.equal(pictureFromClaims([{ picture: "not an address" }, { picture: "https://x.example/p.png" }]), "https://x.example/p.png", "an unusable claim is skipped for a usable one");
|
||||||
|
assert.equal(pictureFromClaims([{ picture: "javascript:alert(1)" }, { picture: 5 }, { picture: "" }, { picture: "https://x/" + "a".repeat(600) }]), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the provider's picture is tried before Gravatar; each needs its own setting; a claim naming Gravatar needs Gravatar on", () => {
|
||||||
|
const user = { email: "olga@example.com", pictureUrl: "https://auth.example.lan/media/olga.png" };
|
||||||
|
assert.deepEqual(avatarSources(user, none, IDP), []);
|
||||||
|
assert.deepEqual(avatarSources(user, { gravatar: false, identityProvider: true }, IDP), ["https://auth.example.lan/media/olga.png"]);
|
||||||
|
assert.deepEqual(avatarSources(user, { gravatar: true, identityProvider: false }, IDP), [gravatarUrl("olga@example.com")]);
|
||||||
|
assert.deepEqual(avatarSources(user, both, IDP), ["https://auth.example.lan/media/olga.png", gravatarUrl("olga@example.com")]);
|
||||||
|
const viaGravatar = { email: null, pictureUrl: gravatarUrl("olga@example.com") };
|
||||||
|
assert.deepEqual(avatarSources(viaGravatar, { gravatar: false, identityProvider: true }, IDP), [], "that would tell Gravatar all the same");
|
||||||
|
assert.deepEqual(avatarSources(viaGravatar, both, IDP), [gravatarUrl("olga@example.com")], "and one address is not asked twice");
|
||||||
|
assert.deepEqual(avatarSources({ email: "no-at-sign", pictureUrl: "https://evil.example/x.png" }, both, IDP), [], "a claim naming anywhere else, and no address, is no source");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the address the page uses changes when the source does, and is null with nothing to look for", () => {
|
||||||
|
const a = avatarUrlFor({ id: 7, email: "a@example.com", pictureUrl: null }, { gravatar: true, identityProvider: false })!;
|
||||||
|
const b = avatarUrlFor({ id: 7, email: "b@example.com", pictureUrl: null }, { gravatar: true, identityProvider: false })!;
|
||||||
|
assert.match(a, /^\/api\/avatars\/7\?v=[0-9a-f]{8}$/);
|
||||||
|
assert.notEqual(a, b);
|
||||||
|
assert.equal(avatarUrlFor({ id: 7, email: "a@example.com", pictureUrl: null }, none), null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fetching and keeping", () => {
|
||||||
|
let calls: string[] = [];
|
||||||
|
const image = (type = "image/png", body: Buffer = PNG) => new Response(body, { status: 200, headers: { "content-type": type } });
|
||||||
|
const answer = (fn: (url: string) => Response) => setAvatarFetcherForTests(async (url) => (calls.push(url), fn(url)));
|
||||||
|
const user = { email: "olga@example.com", pictureUrl: null };
|
||||||
|
const on = { gravatar: true, identityProvider: false };
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
calls = [];
|
||||||
|
});
|
||||||
|
after(() => setAvatarFetcherForTests(null));
|
||||||
|
|
||||||
|
test("nothing is asked of anyone while both settings are off", async () => {
|
||||||
|
answer(() => image());
|
||||||
|
assert.equal(await getAvatar(user, none), null);
|
||||||
|
assert.deepEqual(calls, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a picture comes back with its type, and is kept so the next ask does not go out again", async () => {
|
||||||
|
answer(() => image());
|
||||||
|
const first = await getAvatar(user, on);
|
||||||
|
assert.equal(first?.contentType, "image/png");
|
||||||
|
assert.deepEqual(first?.body, PNG);
|
||||||
|
await getAvatar(user, on);
|
||||||
|
assert.equal(calls.length, 1);
|
||||||
|
assert.equal(calls[0], gravatarUrl("olga@example.com"));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("no picture (404) is kept for a while too, and falls through to the next source", async () => {
|
||||||
|
answer((url) => (url.includes("auth.example.lan") ? new Response("", { status: 404 }) : image("image/jpeg")));
|
||||||
|
const both_ = { user: { email: "olga@example.com", pictureUrl: "https://auth.example.lan/media/olga.png" }, settings: both };
|
||||||
|
assert.equal((await getAvatar(both_.user, both_.settings))?.contentType, "image/jpeg", "the provider had none, so Gravatar's");
|
||||||
|
await getAvatar(both_.user, both_.settings);
|
||||||
|
assert.equal(calls.filter((c) => c.includes("auth.example.lan")).length, 1, "the provider is not asked again straight away");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("only small PNG, JPEG, WebP and GIF are accepted — not SVG, not HTML, not something huge", async () => {
|
||||||
|
answer(() => image("image/svg+xml", Buffer.from("<svg onload=alert(1)/>")));
|
||||||
|
assert.equal(await getAvatar({ email: "svg@example.com", pictureUrl: null }, on), null);
|
||||||
|
answer(() => image("text/html", Buffer.from("<script>")));
|
||||||
|
assert.equal(await getAvatar({ email: "html@example.com", pictureUrl: null }, on), null);
|
||||||
|
answer(() => image("image/png", Buffer.alloc(300 * 1024)));
|
||||||
|
assert.equal(await getAvatar({ email: "big@example.com", pictureUrl: null }, on), null);
|
||||||
|
answer(() => new Response(PNG, { status: 200, headers: { "content-type": "image/png", "content-length": "9999999" } }));
|
||||||
|
assert.equal(await getAvatar({ email: "declared@example.com", pictureUrl: null }, on), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a redirect is followed only to an address that is allowed, and not for ever", async () => {
|
||||||
|
answer((url) => (url.startsWith("https://gravatar.com/") ? new Response("", { status: 302, headers: { location: "https://secure.gravatar.com/avatar/x" } }) : image()));
|
||||||
|
assert.ok(await getAvatar({ email: "r1@example.com", pictureUrl: null }, on));
|
||||||
|
assert.equal(calls.length, 2);
|
||||||
|
|
||||||
|
calls = [];
|
||||||
|
answer(() => new Response("", { status: 302, headers: { location: "http://169.254.169.254/latest/meta-data" } }));
|
||||||
|
assert.equal(await getAvatar({ email: "r2@example.com", pictureUrl: null }, on), null);
|
||||||
|
assert.equal(calls.length, 1, "the metadata address was never asked");
|
||||||
|
|
||||||
|
calls = [];
|
||||||
|
answer((url) => new Response("", { status: 302, headers: { location: url + "x" } }));
|
||||||
|
assert.equal(await getAvatar({ email: "r3@example.com", pictureUrl: null }, on), null);
|
||||||
|
assert.ok(calls.length <= 3, "a redirect loop ends");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("an unreachable host gives no picture and does not throw; it is tried again soon, not every page view", async () => {
|
||||||
|
setAvatarFetcherForTests(async (url) => {
|
||||||
|
calls.push(url);
|
||||||
|
throw new Error("connection refused");
|
||||||
|
});
|
||||||
|
assert.equal(await getAvatar({ email: "down@example.com", pictureUrl: null }, on), null);
|
||||||
|
await getAvatar({ email: "down@example.com", pictureUrl: null }, on);
|
||||||
|
assert.equal(calls.length, 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("through the routes", () => {
|
||||||
|
let app: Server;
|
||||||
|
let base = "";
|
||||||
|
let who = "olga";
|
||||||
|
let olgaId = 0;
|
||||||
|
let fetched: string[] = [];
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const a = express();
|
||||||
|
a.use(express.json());
|
||||||
|
a.use((req, _res, next) => {
|
||||||
|
(req as unknown as { session: unknown }).session = { user: { sub: who } };
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
a.use("/api/me", meRouter);
|
||||||
|
a.use("/api/avatars", avatarsRouter);
|
||||||
|
a.use("/api/users", usersRouter);
|
||||||
|
app = await new Promise<Server>((resolve) => {
|
||||||
|
const s = a.listen(0, "127.0.0.1", () => resolve(s));
|
||||||
|
});
|
||||||
|
base = `http://127.0.0.1:${(app.address() as AddressInfo).port}/api`;
|
||||||
|
|
||||||
|
// Through the sign-in code, as a login would: the first person is the administrator, and the picture claim is kept.
|
||||||
|
const olga = await upsertUserFromLogin({ sub: "olga", email: "Olga@example.com", name: "Olga", pictureUrl: "https://auth.example.lan/media/olga.png" });
|
||||||
|
olgaId = olga.user.id;
|
||||||
|
await upsertUserFromLogin({ sub: "vic", email: "vic@example.com", name: "Vic" });
|
||||||
|
setAvatarFetcherForTests(async (url) => {
|
||||||
|
fetched.push(url);
|
||||||
|
return url.includes("auth.example.lan") ? new Response("", { status: 404 }) : new Response(PNG, { status: 200, headers: { "content-type": "image/png" } });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
app.close();
|
||||||
|
setAvatarFetcherForTests(null);
|
||||||
|
try {
|
||||||
|
rmSync(dir, { recursive: true, force: true });
|
||||||
|
} catch {
|
||||||
|
// Windows keeps the database file locked until the process exits.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const get = (path: string) => fetch(`${base}${path}`);
|
||||||
|
|
||||||
|
test("the picture claim from the sign-in is kept, and is still there when a later sign-in carries none", async () => {
|
||||||
|
const [row] = await db.select().from(users);
|
||||||
|
assert.equal(row.pictureUrl, "https://auth.example.lan/media/olga.png");
|
||||||
|
await upsertUserFromLogin({ sub: "olga", email: "Olga@example.com", name: "Olga" });
|
||||||
|
assert.equal((await db.select().from(users)).find((u) => u.oidcSub === "olga")!.pictureUrl, "https://auth.example.lan/media/olga.png");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("with the settings off there is no picture address for anyone and nothing is fetched", async () => {
|
||||||
|
assert.equal((await (await get("/me")).json()).user.avatarUrl, null);
|
||||||
|
assert.equal((await get(`/avatars/${olgaId}`)).status, 404);
|
||||||
|
const list = (await (await get("/users")).json()).users as { avatarUrl: string | null }[];
|
||||||
|
assert.deepEqual(list.map((u) => u.avatarUrl), [null, null]);
|
||||||
|
assert.deepEqual(fetched, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("turned on, the browser is given an address on this app, and the picture is served from here with safe headers", async () => {
|
||||||
|
await updateSettings({ profilePictures: { gravatar: true, identityProvider: true } });
|
||||||
|
const me = (await (await get("/me")).json()).user;
|
||||||
|
assert.match(me.avatarUrl, new RegExp(`^/api/avatars/${olgaId}\\?v=`));
|
||||||
|
|
||||||
|
who = "vic"; // anyone signed in may see anyone's picture
|
||||||
|
const res = await fetch(`${base.slice(0, -"/api".length)}${me.avatarUrl}`);
|
||||||
|
assert.equal(res.status, 200);
|
||||||
|
assert.equal(res.headers.get("content-type"), "image/png");
|
||||||
|
assert.match(res.headers.get("cache-control") ?? "", /private, max-age=\d+/);
|
||||||
|
assert.match(res.headers.get("content-security-policy") ?? "", /sandbox/);
|
||||||
|
assert.deepEqual(Buffer.from(await res.arrayBuffer()), PNG);
|
||||||
|
assert.deepEqual(fetched[0], "https://auth.example.lan/media/olga.png", "the provider is tried first");
|
||||||
|
assert.equal(fetched[1], gravatarUrl("olga@example.com"), "then Gravatar, with the address lower-cased and hashed");
|
||||||
|
who = "olga";
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the Users page is told who has a picture to look for; someone unknown or a bad id is simply not found", async () => {
|
||||||
|
const list = (await (await get("/users")).json()).users as { name: string; avatarUrl: string | null }[];
|
||||||
|
assert.match(list.find((u) => u.name === "Olga")!.avatarUrl!, /^\/api\/avatars\//);
|
||||||
|
assert.equal((await get("/avatars/99999")).status, 404);
|
||||||
|
assert.equal((await get("/avatars/abc")).status, 404);
|
||||||
|
assert.equal((await get("/avatars/1e3")).status, 404);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a person with no email and no usable claim has no picture to look for", async () => {
|
||||||
|
await upsertUserFromLogin({ sub: "nomail", name: "No Mail" });
|
||||||
|
who = "nomail";
|
||||||
|
assert.equal((await (await get("/me")).json()).user.avatarUrl, null);
|
||||||
|
who = "olga";
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -158,7 +158,8 @@ describe("the Users routes", () => {
|
|||||||
assert.equal(body.rolesFollowGroups, true);
|
assert.equal(body.rolesFollowGroups, true);
|
||||||
const olga = body.users.find((u: { name: string }) => u.name === "olga");
|
const olga = body.users.find((u: { name: string }) => u.name === "olga");
|
||||||
assert.deepEqual(olga.groups, ["cooks"]);
|
assert.deepEqual(olga.groups, ["cooks"]);
|
||||||
assert.deepEqual(Object.keys(olga).sort(), ["createdAt", "email", "groups", "id", "lastLoginAt", "name", "oidcSub", "role"]);
|
assert.deepEqual(Object.keys(olga).sort(), ["avatarUrl", "createdAt", "email", "groups", "id", "lastLoginAt", "name", "oidcSub", "role"]);
|
||||||
|
assert.equal(olga.avatarUrl, null, "no picture source is on, so none to look for");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a role can't be set by hand while groups decide it", async () => {
|
test("a role can't be set by hand while groups decide it", async () => {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ export interface CurrentUser {
|
|||||||
email?: string;
|
email?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
role: UserRole;
|
role: UserRole;
|
||||||
|
/** Where this person's picture is, on this app (the server fetches it); null when no picture source is switched on for them. */
|
||||||
|
avatarUrl?: string | null;
|
||||||
/** Pages this person pinned to the top of their menu, by path — a page alone, or with filters ("/servers?status=offline"). */
|
/** Pages this person pinned to the top of their menu, by path — a page alone, or with filters ("/servers?status=offline"). */
|
||||||
favorites?: string[];
|
favorites?: string[];
|
||||||
/** How this person arranged the dashboard cards. */
|
/** How this person arranged the dashboard cards. */
|
||||||
@@ -134,6 +136,13 @@ export interface UserRecord {
|
|||||||
lastLoginAt: string | null;
|
lastLoginAt: string | null;
|
||||||
/** The groups the identity provider reported at their last sign-in; null until they have signed in with groups available. */
|
/** The groups the identity provider reported at their last sign-in; null until they have signed in with groups available. */
|
||||||
groups: string[] | null;
|
groups: string[] | null;
|
||||||
|
avatarUrl: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Where profile pictures may come from. Both off until an administrator allows them. */
|
||||||
|
export interface ProfilePictureSettings {
|
||||||
|
gravatar: boolean;
|
||||||
|
identityProvider: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** How roles are decided at sign-in: by hand on the Users page, or from the groups the identity provider reports. */
|
/** How roles are decided at sign-in: by hand on the Users page, or from the groups the identity provider reports. */
|
||||||
@@ -533,6 +542,7 @@ export interface AppSettings {
|
|||||||
healthChecks: HealthCheckSettings;
|
healthChecks: HealthCheckSettings;
|
||||||
digest: DigestSettings;
|
digest: DigestSettings;
|
||||||
signIn: SignInSettings;
|
signIn: SignInSettings;
|
||||||
|
profilePictures: ProfilePictureSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AppSettingsPatch = { [K in keyof AppSettings]?: Partial<AppSettings[K]> };
|
export type AppSettingsPatch = { [K in keyof AppSettings]?: Partial<AppSettings[K]> };
|
||||||
@@ -1483,6 +1493,7 @@ export interface PrivacyOverview {
|
|||||||
tlsCertificateChecks: number;
|
tlsCertificateChecks: number;
|
||||||
servers: number;
|
servers: number;
|
||||||
serversWithAgent: number;
|
serversWithAgent: number;
|
||||||
|
profilePictures: ProfilePictureSettings & { identityProviderHost: string | null };
|
||||||
channels: Record<"gotify" | "ntfy" | "smtp" | "webhook" | "webPush", { enabled: boolean; host: string | null }>;
|
channels: Record<"gotify" | "ntfy" | "smtp" | "webhook" | "webPush", { enabled: boolean; host: string | null }>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
/** Up to two initials, for when a person has no picture. */
|
||||||
|
export function initialsOf(name: string): string {
|
||||||
|
const words = name.replace(/@.*$/, "").split(/[\s._-]+/).filter(Boolean);
|
||||||
|
return (words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? "?").slice(0, 2)).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A person's picture where there is one, their initials where there is not (no picture set up, the setting is off, or it could not be fetched).
|
||||||
|
* The picture comes from this app's own address — the server fetches it — so the browser never contacts Gravatar or the identity provider.
|
||||||
|
*/
|
||||||
|
export default function Avatar({ name, src, size = "sm" }: { name: string; src?: string | null; size?: "sm" | "md" }) {
|
||||||
|
const [failed, setFailed] = useState(false);
|
||||||
|
// A different picture (or a person) gets its own chance.
|
||||||
|
useEffect(() => setFailed(false), [src]);
|
||||||
|
return (
|
||||||
|
<span className={`avatar avatar-${size}`} aria-hidden="true">
|
||||||
|
{src && !failed ? <img className="avatar-img" src={src} alt="" loading="lazy" onError={() => setFailed(true)} /> : initialsOf(name)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ import { useStackedTables } from "../hooks/useStackedTables";
|
|||||||
import { useShortcuts } from "../hooks/useShortcuts";
|
import { useShortcuts } from "../hooks/useShortcuts";
|
||||||
import { useFormLabels } from "../hooks/useFormLabels";
|
import { useFormLabels } from "../hooks/useFormLabels";
|
||||||
import ShortcutHelp from "../components/ShortcutHelp";
|
import ShortcutHelp from "../components/ShortcutHelp";
|
||||||
|
import Avatar from "../components/Avatar";
|
||||||
import { useBreadcrumbTailValue } from "../utils/breadcrumb";
|
import { useBreadcrumbTailValue } from "../utils/breadcrumb";
|
||||||
|
|
||||||
const RAIL_KEY = "hlm-sidebar-rail";
|
const RAIL_KEY = "hlm-sidebar-rail";
|
||||||
@@ -33,12 +34,6 @@ function useMediaQuery(query: string): boolean {
|
|||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Up to two initials for the little avatar in the user menu. */
|
|
||||||
function initialsOf(name: string): string {
|
|
||||||
const words = name.replace(/@.*$/, "").split(/[\s._-]+/).filter(Boolean);
|
|
||||||
return (words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? "?").slice(0, 2)).toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
const OPEN_GROUPS_KEY = "hlm-nav-open-groups";
|
const OPEN_GROUPS_KEY = "hlm-nav-open-groups";
|
||||||
|
|
||||||
function loadOpenGroups(): Set<string> {
|
function loadOpenGroups(): Set<string> {
|
||||||
@@ -326,7 +321,7 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
|||||||
title={user.email ?? undefined}
|
title={user.email ?? undefined}
|
||||||
onClick={() => setMenuOpen((open) => !open)}
|
onClick={() => setMenuOpen((open) => !open)}
|
||||||
>
|
>
|
||||||
<span className="avatar avatar-sm">{initialsOf(user.name ?? user.email ?? user.sub)}</span>
|
<Avatar name={user.name ?? user.email ?? user.sub} src={user.avatarUrl} />
|
||||||
<span className="user-menu-who">
|
<span className="user-menu-who">
|
||||||
<span className="d-block text-truncate">{user.name ?? user.email ?? user.sub}</span>
|
<span className="d-block text-truncate">{user.name ?? user.email ?? user.sub}</span>
|
||||||
<span className="d-block small opacity-75">{user.role}</span>
|
<span className="d-block small opacity-75">{user.role}</span>
|
||||||
|
|||||||
@@ -260,6 +260,20 @@ export default function Privacy() {
|
|||||||
<strong>Certificate checks</strong> — for {outbound?.tlsCertificateChecks ?? 0} secret{outbound?.tlsCertificateChecks === 1 ? "" : "s"} with
|
<strong>Certificate checks</strong> — for {outbound?.tlsCertificateChecks ?? 0} secret{outbound?.tlsCertificateChecks === 1 ? "" : "s"} with
|
||||||
a host to check, the app connects to that host to read its certificate — never to this server itself, a loopback or link-local address, or a cloud metadata address.
|
a host to check, the app connects to that host to read its certificate — never to this server itself, a loopback or link-local address, or a cloud metadata address.
|
||||||
</li>
|
</li>
|
||||||
|
<li className="mb-2">
|
||||||
|
<strong>Profile pictures</strong> —{" "}
|
||||||
|
{outbound && (outbound.profilePictures.gravatar || outbound.profilePictures.identityProvider) ? (
|
||||||
|
<>
|
||||||
|
this server fetches pictures
|
||||||
|
{outbound.profilePictures.identityProvider ? ` from the identity provider${outbound.profilePictures.identityProviderHost ? ` (${outbound.profilePictures.identityProviderHost})` : ""}` : ""}
|
||||||
|
{outbound.profilePictures.identityProvider && outbound.profilePictures.gravatar ? " and" : ""}
|
||||||
|
{outbound.profilePictures.gravatar ? " from Gravatar, which is sent a hash of each person's email address and sees this server's IP address" : ""}. Your browser never
|
||||||
|
contacts either: it asks this app, which keeps each picture for a day.
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"switched off, so nothing is fetched. People are shown as their initials."
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
<li className="mb-2">
|
<li className="mb-2">
|
||||||
<strong>Skatteverket</strong> — only when an admin clicks "Import from Skatteverket" under Settings → Names, the app asks
|
<strong>Skatteverket</strong> — only when an admin clicks "Import from Skatteverket" under Settings → Names, the app asks
|
||||||
Skatteverket's open name statistics for the most common given names. The request carries a sex and a birth year, nothing about you
|
Skatteverket's open name statistics for the most common given names. The request carries a sex and a birth year, nothing about you
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { ErrorNotice } from "../components/Notice";
|
|||||||
import { SearchBox } from "../components/TableToolbar";
|
import { SearchBox } from "../components/TableToolbar";
|
||||||
import { useTableSearch } from "../hooks/useTableSearch";
|
import { useTableSearch } from "../hooks/useTableSearch";
|
||||||
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
||||||
|
import Avatar from "../components/Avatar";
|
||||||
|
|
||||||
const ROLES: UserRole[] = ["viewer", "operator", "admin"];
|
const ROLES: UserRole[] = ["viewer", "operator", "admin"];
|
||||||
|
|
||||||
@@ -95,7 +96,12 @@ export default function Users() {
|
|||||||
<tbody>
|
<tbody>
|
||||||
{sorted?.map((u) => (
|
{sorted?.map((u) => (
|
||||||
<tr key={u.id}>
|
<tr key={u.id}>
|
||||||
<td>{u.name ?? "—"}</td>
|
<td>
|
||||||
|
<span className="d-inline-flex align-items-center gap-2">
|
||||||
|
<Avatar name={u.name ?? u.email ?? u.oidcSub} src={u.avatarUrl} />
|
||||||
|
{u.name ?? "—"}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
<td>{u.email ?? "—"}</td>
|
<td>{u.email ?? "—"}</td>
|
||||||
<td style={{ maxWidth: 160 }}>
|
<td style={{ maxWidth: 160 }}>
|
||||||
<select
|
<select
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { api, type GroupRolePreview, type SignInSettings as SignInSettingsData } from "../../api/client";
|
import { api, type GroupRolePreview, type ProfilePictureSettings, type SignInSettings as SignInSettingsData } from "../../api/client";
|
||||||
import { ErrorNotice } from "../../components/Notice";
|
import { ErrorNotice } from "../../components/Notice";
|
||||||
import { PageSkeleton } from "../../components/Skeleton";
|
import { PageSkeleton } from "../../components/Skeleton";
|
||||||
import { readableError } from "../../utils/errors";
|
import { readableError } from "../../utils/errors";
|
||||||
@@ -7,6 +7,7 @@ import { toast } from "../../utils/toast";
|
|||||||
import ExportTableButton from "../../components/ExportTableButton";
|
import ExportTableButton from "../../components/ExportTableButton";
|
||||||
|
|
||||||
const DEFAULTS: SignInSettingsData = { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" };
|
const DEFAULTS: SignInSettingsData = { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" };
|
||||||
|
const NO_PICTURES: ProfilePictureSettings = { gravatar: false, identityProvider: false };
|
||||||
|
|
||||||
/** One name per line or separated by commas — whichever is easier to paste in. */
|
/** One name per line or separated by commas — whichever is easier to paste in. */
|
||||||
const parseNames = (text: string): string[] => [...new Set(text.split(/[\n,]/).map((s) => s.trim()).filter(Boolean))];
|
const parseNames = (text: string): string[] => [...new Set(text.split(/[\n,]/).map((s) => s.trim()).filter(Boolean))];
|
||||||
@@ -25,6 +26,8 @@ export default function SignInSettings() {
|
|||||||
const [operatorText, setOperatorText] = useState("");
|
const [operatorText, setOperatorText] = useState("");
|
||||||
const [otherwise, setOtherwise] = useState<"viewer" | "keep">("viewer");
|
const [otherwise, setOtherwise] = useState<"viewer" | "keep">("viewer");
|
||||||
const [preview, setPreview] = useState<GroupRolePreview | null>(null);
|
const [preview, setPreview] = useState<GroupRolePreview | null>(null);
|
||||||
|
const [loadedPictures, setLoadedPictures] = useState<ProfilePictureSettings>(NO_PICTURES);
|
||||||
|
const [pictures, setPictures] = useState<ProfilePictureSettings>(NO_PICTURES);
|
||||||
const [busy, setBusy] = useState<"check" | "save" | null>(null);
|
const [busy, setBusy] = useState<"check" | "save" | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -38,6 +41,9 @@ export default function SignInSettings() {
|
|||||||
setAdminText(s.adminGroups.join("\n"));
|
setAdminText(s.adminGroups.join("\n"));
|
||||||
setOperatorText(s.operatorGroups.join("\n"));
|
setOperatorText(s.operatorGroups.join("\n"));
|
||||||
setOtherwise(s.otherwise);
|
setOtherwise(s.otherwise);
|
||||||
|
const p = res.settings.profilePictures ?? NO_PICTURES;
|
||||||
|
setLoadedPictures(p);
|
||||||
|
setPictures(p);
|
||||||
})
|
})
|
||||||
.catch((err) => setError(readableError(err)));
|
.catch((err) => setError(readableError(err)));
|
||||||
}, []);
|
}, []);
|
||||||
@@ -45,7 +51,7 @@ export default function SignInSettings() {
|
|||||||
if (!loaded) return error ? <ErrorNotice error={error} /> : <PageSkeleton />;
|
if (!loaded) return error ? <ErrorNotice error={error} /> : <PageSkeleton />;
|
||||||
|
|
||||||
const draft = (): SignInSettingsData => ({ roleFromGroups: enabled, groupsClaim: claim.trim() || "groups", adminGroups: parseNames(adminText), operatorGroups: parseNames(operatorText), otherwise });
|
const draft = (): SignInSettingsData => ({ roleFromGroups: enabled, groupsClaim: claim.trim() || "groups", adminGroups: parseNames(adminText), operatorGroups: parseNames(operatorText), otherwise });
|
||||||
const dirty = JSON.stringify(draft()) !== JSON.stringify(loaded);
|
const dirty = JSON.stringify(draft()) !== JSON.stringify(loaded) || JSON.stringify(pictures) !== JSON.stringify(loadedPictures);
|
||||||
|
|
||||||
async function check() {
|
async function check() {
|
||||||
setBusy("check");
|
setBusy("check");
|
||||||
@@ -65,8 +71,9 @@ export default function SignInSettings() {
|
|||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
const d = draft();
|
const d = draft();
|
||||||
await api.settings.update({ signIn: d });
|
await api.settings.update({ signIn: d, profilePictures: pictures });
|
||||||
setLoaded(d);
|
setLoaded(d);
|
||||||
|
setLoadedPictures(pictures);
|
||||||
toast.success(d.roleFromGroups ? "Saved. Roles now follow groups at each sign-in." : "Saved. Roles are set by hand on the Users page.");
|
toast.success(d.roleFromGroups ? "Saved. Roles now follow groups at each sign-in." : "Saved. Roles are set by hand on the Users page.");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(readableError(err));
|
setError(readableError(err));
|
||||||
@@ -144,6 +151,38 @@ export default function SignInSettings() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="card mb-3">
|
||||||
|
<div className="card-header">
|
||||||
|
<h3 className="card-title">Profile pictures</h3>
|
||||||
|
</div>
|
||||||
|
<div className="card-body">
|
||||||
|
<p className="text-secondary">
|
||||||
|
Without a picture a person is shown as their initials. Either source below can be allowed; the picture from the identity provider is tried first. Both are off, because each means
|
||||||
|
<strong> this server</strong> asks an outside address for a picture. People's browsers never do: the server fetches, checks (small PNG, JPEG, WebP or GIF only) and keeps the pictures for a day,
|
||||||
|
and serves them from this app. A change shows within a day, or on the next sign-in for a new picture address.
|
||||||
|
</p>
|
||||||
|
<label className="form-check mb-2">
|
||||||
|
<input type="checkbox" className="form-check-input" checked={pictures.identityProvider} onChange={(e) => setPictures({ ...pictures, identityProvider: e.target.checked })} />
|
||||||
|
<span className="form-check-label">
|
||||||
|
The picture the identity provider gives
|
||||||
|
<span className="form-hint d-block">
|
||||||
|
The <code>picture</code> claim from Authentik, kept at each sign-in. Only addresses on Authentik's own host (or Gravatar, if that is allowed too) are used.
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<label className="form-check mb-0">
|
||||||
|
<input type="checkbox" className="form-check-input" checked={pictures.gravatar} onChange={(e) => setPictures({ ...pictures, gravatar: e.target.checked })} />
|
||||||
|
<span className="form-check-label">
|
||||||
|
Gravatar
|
||||||
|
<span className="form-hint d-block">
|
||||||
|
gravatar.com is sent a SHA-256 hash of the person's email address (not the address itself), and sees this server's IP address. Anyone who already knows an address can check
|
||||||
|
it against a hash, so leave this off if the email addresses are private.
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{preview && (
|
{preview && (
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<div className="card-header">
|
<div className="card-header">
|
||||||
|
|||||||
@@ -149,6 +149,14 @@ html[data-env] .navbar-vertical {
|
|||||||
background: color-mix(in srgb, currentColor 14%, transparent);
|
background: color-mix(in srgb, currentColor 14%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A profile picture fills the little circle; without one the circle holds initials. */
|
||||||
|
.avatar .avatar-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
.user-menu-who {
|
.user-menu-who {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|||||||
Reference in new issue
Block a user