partially redacts IP address on token lookup page

This commit is contained in:
nai-degen
2023-09-17 17:53:29 -05:00
parent 5e57dbb8f1
commit 40e71435f0
5 changed files with 10 additions and 3 deletions
+1 -1
View File
@@ -50,7 +50,7 @@
<tr>
<th scope="row">IPs</th>
<td colspan="2">
<%- include("partials/shared_user_ip_list", { user }) %>
<%- include("partials/shared_user_ip_list", { user, shouldRedact: false }) %>
</td>
</tr>
<% if (user.type === "temporary") { %>
+2
View File
@@ -1,6 +1,7 @@
import { RequestHandler } from "express";
import { config } from "../config";
import { getTokenCostUsd, prettyTokens } from "./stats";
import { redactIp } from "./utils";
import * as userStore from "./users/user-store";
export const injectLocals: RequestHandler = (req, res, next) => {
@@ -25,6 +26,7 @@ export const injectLocals: RequestHandler = (req, res, next) => {
// view helpers
res.locals.prettyTokens = prettyTokens;
res.locals.tokenCost = getTokenCostUsd;
res.locals.redactIp = redactIp;
next();
};
+5
View File
@@ -75,3 +75,8 @@ export function makeOptionalPropsNullable<Schema extends z.AnyZodObject>(
);
return z.object(newProps);
}
export function redactIp(ip: string) {
const ipv6 = ip.includes(":");
return ipv6 ? "redacted:ipv6" : ip.replace(/\.\d+\.\d+$/, ".xxx.xxx");
}
@@ -1,7 +1,7 @@
<a href="#" id="ip-list-toggle">Show all (<%- user.ip.length %>)</a>
<ol id="ip-list" style="display: none; padding-left: 1em; margin: 0">
<% user.ip.forEach((ip) => { %>
<li><code><%- ip %></code></li>
<li><code><%- shouldRedact ? redactIp(ip) : ip %></code></li>
<% }) %>
</ol>
+1 -1
View File
@@ -52,7 +52,7 @@
</tr>
<tr>
<th scope="row">IPs<%- maxIps ? ` (max ${maxIps})` : "" %> </th>
<td colspan="2"><%- include("partials/shared_user_ip_list", { user }) %></td>
<td colspan="2"><%- include("partials/shared_user_ip_list", { user, shouldRedact: true }) %></td>
</tr>
<% if (user.type === "temporary") { %>
<tr>