Skip to content

Commit f8ae986

Browse files
committed
fix: Drop auth failure logger
1 parent 360ef9d commit f8ae986

File tree

4 files changed

+11
-61
lines changed

4 files changed

+11
-61
lines changed

apps/web/server/auth.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import NextAuth, {
99
import { Adapter as NextAuthAdapater } from "next-auth/adapters";
1010
import CredentialsProvider from "next-auth/providers/credentials";
1111
import { Provider } from "next-auth/providers/index";
12-
import requestIp from "request-ip";
1312

1413
import { db } from "@karakeep/db";
1514
import {
@@ -19,7 +18,7 @@ import {
1918
verificationTokens,
2019
} from "@karakeep/db/schema";
2120
import serverConfig from "@karakeep/shared/config";
22-
import { logAuthenticationError, validatePassword } from "@karakeep/trpc/auth";
21+
import { validatePassword } from "@karakeep/trpc/auth";
2322
import { createUserRaw } from "@karakeep/trpc/routers/users";
2423

2524
type UserRole = "admin" | "user";
@@ -100,7 +99,7 @@ const providers: Provider[] = [
10099
email: { label: "Email", type: "email", placeholder: "Email" },
101100
password: { label: "Password", type: "password" },
102101
},
103-
async authorize(credentials, req) {
102+
async authorize(credentials) {
104103
if (!credentials) {
105104
return null;
106105
}
@@ -110,13 +109,7 @@ const providers: Provider[] = [
110109
credentials?.email,
111110
credentials?.password,
112111
);
113-
} catch (e) {
114-
const error = e as Error;
115-
logAuthenticationError(
116-
credentials?.email,
117-
error.message,
118-
requestIp.getClientIp({ headers: req.headers }),
119-
);
112+
} catch {
120113
return null;
121114
}
122115
},

packages/shared/logger.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,3 @@ const logger = winston.createLogger({
1515
});
1616

1717
export default logger;
18-
19-
export const authFailureLogger = winston.createLogger({
20-
level: "debug",
21-
format: winston.format.combine(
22-
winston.format.timestamp(),
23-
winston.format.printf(
24-
(info) => `${info.timestamp} ${info.level}: ${info.message}`,
25-
),
26-
),
27-
transports: [
28-
new winston.transports.Console(),
29-
new winston.transports.File({
30-
filename: "auth_failures.log",
31-
dirname: serverConfig.dataDir,
32-
maxFiles: 2,
33-
maxsize: 1024 * 1024,
34-
}),
35-
],
36-
});

packages/trpc/auth.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as bcrypt from "bcryptjs";
44
import { db } from "@karakeep/db";
55
import { apiKeys } from "@karakeep/db/schema";
66
import serverConfig from "@karakeep/shared/config";
7-
import { authFailureLogger } from "@karakeep/shared/logger";
87

98
// API Keys
109

@@ -116,13 +115,3 @@ export async function validatePassword(email: string, password: string) {
116115

117116
return user;
118117
}
119-
120-
export function logAuthenticationError(
121-
user: string,
122-
message: string,
123-
ip: string | null,
124-
): void {
125-
authFailureLogger.error(
126-
`Authentication error. User: "${user}", Message: "${message}", IP-Address: "${ip}"`,
127-
);
128-
}

packages/trpc/routers/apiKeys.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import { z } from "zod";
55
import { apiKeys } from "@karakeep/db/schema";
66
import serverConfig from "@karakeep/shared/config";
77

8-
import {
9-
authenticateApiKey,
10-
generateApiKey,
11-
logAuthenticationError,
12-
validatePassword,
13-
} from "../auth";
8+
import { authenticateApiKey, generateApiKey, validatePassword } from "../auth";
149
import {
1510
authedProcedure,
1611
createRateLimitMiddleware,
@@ -90,7 +85,7 @@ export const apiKeysAppRouter = router({
9085
}),
9186
)
9287
.output(zApiKeySchema)
93-
.mutation(async ({ input, ctx }) => {
88+
.mutation(async ({ input }) => {
9489
let user;
9590
// Special handling as otherwise the extension would show "username or password is wrong"
9691
if (serverConfig.auth.disablePasswordAuth) {
@@ -101,9 +96,7 @@ export const apiKeysAppRouter = router({
10196
}
10297
try {
10398
user = await validatePassword(input.email, input.password);
104-
} catch (e) {
105-
const error = e as Error;
106-
logAuthenticationError(input.email, error.message, ctx.req.ip);
99+
} catch {
107100
throw new TRPCError({ code: "UNAUTHORIZED" });
108101
}
109102
return await generateApiKey(input.keyName, user.id);
@@ -118,16 +111,10 @@ export const apiKeysAppRouter = router({
118111
) // 30 requests per minute
119112
.input(z.object({ apiKey: z.string() }))
120113
.output(z.object({ success: z.boolean() }))
121-
.mutation(async ({ input, ctx }) => {
122-
try {
123-
await authenticateApiKey(input.apiKey); // Throws if the key is invalid
124-
return {
125-
success: true,
126-
};
127-
} catch (e) {
128-
const error = e as Error;
129-
logAuthenticationError("<unknown>", error.message, ctx.req.ip);
130-
throw e;
131-
}
114+
.mutation(async ({ input }) => {
115+
await authenticateApiKey(input.apiKey); // Throws if the key is invalid
116+
return {
117+
success: true,
118+
};
132119
}),
133120
});

0 commit comments

Comments
 (0)