mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
fix(logging): keep reviewers unlinkable, look admin users up by explicit id
- Requests carry userId on warn and error records only. The app calls /api/user on every page load, so a userId on routine info records sat next to the repoId a signed-in reviewer opened, and timestamps linked them. Jobs keep it at every level. Logger, collector and the admin projection apply the same rule. - Admin user routes take an _id only as id:<_id>; a 24-hex GitHub login can no longer match another account's _id for ban or promote. - The download-job expectation includes the owner id the PR adds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c281841f91
commit
d8a777cd35
8 files changed
+58
-20
No files matched your search
+10
-4
@@ -51,8 +51,14 @@ export function setLogContext(fields: Pick<LogContext, "repoId" | "pullRequestId
|
||||
* the project's owner, a co-author or an admin. Visitors and anonymous readers
|
||||
* get a viewer label and no userId. Requests on any other route (assets,
|
||||
* "other", webhooks) get no userId.
|
||||
*
|
||||
* Requests carry userId on warn and error records only. The app calls
|
||||
* /api/user on every page load, so a userId on routine info records would sit
|
||||
* milliseconds before the repoId of the anonymized page a signed-in reviewer
|
||||
* opens, and matching timestamps would tell who reviewed what. Jobs are the
|
||||
* owner's own work and keep it at every level.
|
||||
*/
|
||||
export function logIdentity(context: LogContext, details: Record<string, unknown> = {}) {
|
||||
export function logIdentity(context: LogContext, details: Record<string, unknown> = {}, level?: string) {
|
||||
const out: Record<string, string> = {};
|
||||
const { route, service, viewer, userId } = context;
|
||||
// Upstream lookups (/api/repo/:owner/:repo) put an owner name where a repoId would sit.
|
||||
@@ -64,9 +70,9 @@ export function logIdentity(context: LogContext, details: Record<string, unknown
|
||||
if (validViewer(viewer)) out.viewer = viewer;
|
||||
if (validUserId(userId)) {
|
||||
const privileged = validViewer(viewer) && PRIVILEGED_VIEWERS.includes(viewer);
|
||||
const visible = validViewer(viewer) || anonymizedRoute(route, service) ? privileged
|
||||
: accountRoute(route) || (route === undefined && service === "worker");
|
||||
if (visible) out.userId = userId;
|
||||
const job = route === undefined && service === "worker";
|
||||
const visible = validViewer(viewer) || anonymizedRoute(route, service) ? privileged : accountRoute(route) || job;
|
||||
if (visible && (job || level === "warn" || level === "error")) out.userId = userId;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ export function logRecord(level: string, module: string, args: unknown[]) {
|
||||
if (context.method && allowed(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "OTHER"], context.method)) record.method = context.method;
|
||||
Object.assign(record, safeDiagnosticFields(details));
|
||||
// Validated public project IDs, viewer role and, where allowed, the internal user _id.
|
||||
Object.assign(record, logIdentity(context, details));
|
||||
Object.assign(record, logIdentity(context, details, level));
|
||||
// Anonymous request paths are diagnostic fields, never metric labels.
|
||||
const requestPath = safeReproductionPath(context.requestPath || details.requestPath, record.method);
|
||||
if (requestPath) Object.assign(record, requestReproduction(requestPath, record.method));
|
||||
|
||||
@@ -1207,9 +1207,12 @@ router.get("/users", async (req, res) => {
|
||||
|
||||
res.json({ query: filter, page, total, sort, results, statusCounts });
|
||||
});
|
||||
// Log records carry the internal user _id, never the username; accept either.
|
||||
function adminUserFilter(param: string) {
|
||||
return /^[a-f0-9]{24}$/.test(param) ? { $or: [{ username: param }, { _id: param }] } : { username: param };
|
||||
// Log records carry the internal user _id, never the username. An _id is
|
||||
// asked for explicitly as "id:<_id>": a GitHub login can also be 24 hex
|
||||
// characters, and ban or promote must never hit a different account.
|
||||
export function adminUserFilter(param: string) {
|
||||
const id = /^id:([a-f0-9]{24})$/.exec(param);
|
||||
return id ? { _id: id[1] } : { username: param };
|
||||
}
|
||||
|
||||
router.get(
|
||||
|
||||
Reference in new issue
Block a user