@better-auth/core 1.4.16 → 1.4.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/dist/context/global.mjs +1 -1
- package/dist/types/init-options.d.mts +1 -1
- package/dist/utils/ip.d.mts +1 -1
- package/dist/utils/ip.mjs +2 -2
- package/package.json +2 -2
- package/src/types/init-options.ts +1 -1
- package/src/utils/ip.test.ts +31 -19
- package/src/utils/ip.ts +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/core@1.4.
|
|
2
|
+
> @better-auth/core@1.4.17 build /home/runner/work/better-auth/better-auth/packages/core
|
|
3
3
|
> tsdown
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m tsdown [2mv0.17.2[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
[34mℹ[39m [2mdist/[22m[32m[1merror/index.d.mts[22m[39m [2m 0.27 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
101
101
|
[34mℹ[39m [2mdist/[22m[32m[1masync_hooks/index.d.mts[22m[39m [2m 0.24 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
102
102
|
[34mℹ[39m [2mdist/[22m[32m[1masync_hooks/pure.index.d.mts[22m[39m [2m 0.22 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
103
|
-
[34mℹ[39m [2mdist/[22m[32mtypes/init-options.d.mts[39m [2m39.
|
|
103
|
+
[34mℹ[39m [2mdist/[22m[32mtypes/init-options.d.mts[39m [2m39.00 kB[22m [2m│ gzip: 8.77 kB[22m
|
|
104
104
|
[34mℹ[39m [2mdist/[22m[32mtypes/context.d.mts[39m [2m 9.09 kB[22m [2m│ gzip: 2.66 kB[22m
|
|
105
105
|
[34mℹ[39m [2mdist/[22m[32msocial-providers/zoom.d.mts[39m [2m 6.71 kB[22m [2m│ gzip: 2.29 kB[22m
|
|
106
106
|
[34mℹ[39m [2mdist/[22m[32moauth2/oauth-provider.d.mts[39m [2m 5.92 kB[22m [2m│ gzip: 1.67 kB[22m
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
[34mℹ[39m [2mdist/[22m[32msocial-providers/kick.d.mts[39m [2m 1.62 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
139
139
|
[34mℹ[39m [2mdist/[22m[32msocial-providers/linkedin.d.mts[39m [2m 1.61 kB[22m [2m│ gzip: 0.60 kB[22m
|
|
140
140
|
[34mℹ[39m [2mdist/[22m[32msocial-providers/linear.d.mts[39m [2m 1.60 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
141
|
-
[34mℹ[39m [2mdist/[22m[32mutils/ip.d.mts[39m [2m 1.58 kB[22m [2m│ gzip: 0.
|
|
141
|
+
[34mℹ[39m [2mdist/[22m[32mutils/ip.d.mts[39m [2m 1.58 kB[22m [2m│ gzip: 0.68 kB[22m
|
|
142
142
|
[34mℹ[39m [2mdist/[22m[32moauth2/validate-authorization-code.d.mts[39m [2m 1.57 kB[22m [2m│ gzip: 0.49 kB[22m
|
|
143
143
|
[34mℹ[39m [2mdist/[22m[32msocial-providers/notion.d.mts[39m [2m 1.56 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
144
144
|
[34mℹ[39m [2mdist/[22m[32msocial-providers/reddit.d.mts[39m [2m 1.54 kB[22m [2m│ gzip: 0.57 kB[22m
|
|
@@ -180,5 +180,5 @@
|
|
|
180
180
|
[34mℹ[39m [2mdist/[22m[32mutils/json.d.mts[39m [2m 0.13 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
181
181
|
[34mℹ[39m [2mdist/[22m[32mutils/id.d.mts[39m [2m 0.12 kB[22m [2m│ gzip: 0.12 kB[22m
|
|
182
182
|
[34mℹ[39m [2mdist/[22m[32menv/color-depth.d.mts[39m [2m 0.12 kB[22m [2m│ gzip: 0.11 kB[22m
|
|
183
|
-
[34mℹ[39m 173 files, total: 448.
|
|
184
|
-
[32m✔[39m Build complete in [
|
|
183
|
+
[34mℹ[39m 173 files, total: 448.94 kB
|
|
184
|
+
[32m✔[39m Build complete in [32m7089ms[39m
|
package/dist/context/global.mjs
CHANGED
|
@@ -138,7 +138,7 @@ type BetterAuthAdvancedOptions = {
|
|
|
138
138
|
* Note: This only affects IPv6 addresses. IPv4 addresses are always
|
|
139
139
|
* rate limited individually.
|
|
140
140
|
*
|
|
141
|
-
* @default
|
|
141
|
+
* @default 64 (/64 subnet)
|
|
142
142
|
*/
|
|
143
143
|
ipv6Subnet?: 128 | 64 | 48 | 32 | undefined;
|
|
144
144
|
} | undefined;
|
package/dist/utils/ip.d.mts
CHANGED
|
@@ -30,7 +30,7 @@ declare function isValidIP(ip: string): boolean;
|
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
32
|
* normalizeIP("2001:DB8::1")
|
|
33
|
-
* // -> "2001:0db8:0000:0000:0000:0000:0000:
|
|
33
|
+
* // -> "2001:0db8:0000:0000:0000:0000:0000:0000"
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
36
|
* normalizeIP("::ffff:192.0.2.1")
|
package/dist/utils/ip.mjs
CHANGED
|
@@ -85,7 +85,7 @@ function normalizeIPv6(ipv6, subnetPrefix) {
|
|
|
85
85
|
*
|
|
86
86
|
* @example
|
|
87
87
|
* normalizeIP("2001:DB8::1")
|
|
88
|
-
* // -> "2001:0db8:0000:0000:0000:0000:0000:
|
|
88
|
+
* // -> "2001:0db8:0000:0000:0000:0000:0000:0000"
|
|
89
89
|
*
|
|
90
90
|
* @example
|
|
91
91
|
* normalizeIP("::ffff:192.0.2.1")
|
|
@@ -100,7 +100,7 @@ function normalizeIP(ip, options = {}) {
|
|
|
100
100
|
if (!isIPv6(ip)) return ip.toLowerCase();
|
|
101
101
|
const ipv4 = extractIPv4FromMapped(ip);
|
|
102
102
|
if (ipv4) return ipv4.toLowerCase();
|
|
103
|
-
return normalizeIPv6(ip, options.ipv6Subnet ||
|
|
103
|
+
return normalizeIPv6(ip, options.ipv6Subnet || 64);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Creates a rate limit key from IP and path
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.17",
|
|
4
4
|
"description": "The most comprehensive authentication framework for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
},
|
|
123
123
|
"dependencies": {
|
|
124
124
|
"@standard-schema/spec": "^1.0.0",
|
|
125
|
-
"zod": "^4.
|
|
125
|
+
"zod": "^4.3.5"
|
|
126
126
|
},
|
|
127
127
|
"peerDependencies": {
|
|
128
128
|
"@better-auth/utils": "0.3.0",
|
|
@@ -158,7 +158,7 @@ export type BetterAuthAdvancedOptions = {
|
|
|
158
158
|
* Note: This only affects IPv6 addresses. IPv4 addresses are always
|
|
159
159
|
* rate limited individually.
|
|
160
160
|
*
|
|
161
|
-
* @default
|
|
161
|
+
* @default 64 (/64 subnet)
|
|
162
162
|
*/
|
|
163
163
|
ipv6Subnet?: 128 | 64 | 48 | 32 | undefined;
|
|
164
164
|
}
|
package/src/utils/ip.test.ts
CHANGED
|
@@ -34,20 +34,22 @@ describe("IP Normalization", () => {
|
|
|
34
34
|
|
|
35
35
|
describe("IPv6 Normalization", () => {
|
|
36
36
|
it("should normalize compressed IPv6 to full form", () => {
|
|
37
|
-
expect(normalizeIP("2001:db8::1")).toBe(
|
|
37
|
+
expect(normalizeIP("2001:db8::1", { ipv6Subnet: 128 })).toBe(
|
|
38
38
|
"2001:0db8:0000:0000:0000:0000:0000:0001",
|
|
39
39
|
);
|
|
40
|
-
expect(normalizeIP("::1")).toBe(
|
|
40
|
+
expect(normalizeIP("::1", { ipv6Subnet: 128 })).toBe(
|
|
41
41
|
"0000:0000:0000:0000:0000:0000:0000:0001",
|
|
42
42
|
);
|
|
43
|
-
expect(normalizeIP("::")).toBe(
|
|
43
|
+
expect(normalizeIP("::", { ipv6Subnet: 128 })).toBe(
|
|
44
|
+
"0000:0000:0000:0000:0000:0000:0000:0000",
|
|
45
|
+
);
|
|
44
46
|
});
|
|
45
47
|
|
|
46
48
|
it("should normalize uppercase to lowercase", () => {
|
|
47
|
-
expect(normalizeIP("2001:DB8::1")).toBe(
|
|
49
|
+
expect(normalizeIP("2001:DB8::1", { ipv6Subnet: 128 })).toBe(
|
|
48
50
|
"2001:0db8:0000:0000:0000:0000:0000:0001",
|
|
49
51
|
);
|
|
50
|
-
expect(normalizeIP("2001:0DB8:ABCD:EF00::1")).toBe(
|
|
52
|
+
expect(normalizeIP("2001:0DB8:ABCD:EF00::1", { ipv6Subnet: 128 })).toBe(
|
|
51
53
|
"2001:0db8:abcd:ef00:0000:0000:0000:0001",
|
|
52
54
|
);
|
|
53
55
|
});
|
|
@@ -55,16 +57,22 @@ describe("IP Normalization", () => {
|
|
|
55
57
|
it("should handle various IPv6 formats consistently", () => {
|
|
56
58
|
// All these represent the same address
|
|
57
59
|
const normalized = "2001:0db8:0000:0000:0000:0000:0000:0001";
|
|
58
|
-
expect(normalizeIP("2001:db8::1")).toBe(normalized);
|
|
59
|
-
expect(normalizeIP("2001:0db8:0:0:0:0:0:1")).toBe(
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
expect(normalizeIP("2001:db8::1", { ipv6Subnet: 128 })).toBe(normalized);
|
|
61
|
+
expect(normalizeIP("2001:0db8:0:0:0:0:0:1", { ipv6Subnet: 128 })).toBe(
|
|
62
|
+
normalized,
|
|
63
|
+
);
|
|
64
|
+
expect(normalizeIP("2001:db8:0::1", { ipv6Subnet: 128 })).toBe(
|
|
65
|
+
normalized,
|
|
66
|
+
);
|
|
67
|
+
expect(normalizeIP("2001:0db8::0:0:0:1", { ipv6Subnet: 128 })).toBe(
|
|
68
|
+
normalized,
|
|
69
|
+
);
|
|
62
70
|
});
|
|
63
71
|
|
|
64
72
|
it("should handle IPv6 with :: at different positions", () => {
|
|
65
|
-
expect(
|
|
66
|
-
"2001:
|
|
67
|
-
);
|
|
73
|
+
expect(
|
|
74
|
+
normalizeIP("2001:db8:85a3::8a2e:370:7334", { ipv6Subnet: 128 }),
|
|
75
|
+
).toBe("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
|
68
76
|
expect(normalizeIP("::ffff:192.0.2.1")).not.toContain("::");
|
|
69
77
|
});
|
|
70
78
|
});
|
|
@@ -131,11 +139,11 @@ describe("IP Normalization", () => {
|
|
|
131
139
|
expect(ip1).toBe(ip2);
|
|
132
140
|
});
|
|
133
141
|
|
|
134
|
-
it("should handle /
|
|
142
|
+
it("should handle /64 subnet by default", () => {
|
|
135
143
|
const ip1 = normalizeIP("2001:db8::1");
|
|
136
|
-
const ip2 = normalizeIP("2001:db8::1", { ipv6Subnet:
|
|
144
|
+
const ip2 = normalizeIP("2001:db8::1", { ipv6Subnet: 64 });
|
|
137
145
|
expect(ip1).toBe(ip2);
|
|
138
|
-
expect(ip1).toBe("2001:0db8:0000:0000:0000:0000:0000:
|
|
146
|
+
expect(ip1).toBe("2001:0db8:0000:0000:0000:0000:0000:0000");
|
|
139
147
|
});
|
|
140
148
|
|
|
141
149
|
it("should not affect IPv4 addresses when ipv6Subnet is set", () => {
|
|
@@ -179,7 +187,9 @@ describe("IP Normalization", () => {
|
|
|
179
187
|
"2001:db8::0:1",
|
|
180
188
|
];
|
|
181
189
|
|
|
182
|
-
const normalized = representations.map((ip) =>
|
|
190
|
+
const normalized = representations.map((ip) =>
|
|
191
|
+
normalizeIP(ip, { ipv6Subnet: 128 }),
|
|
192
|
+
);
|
|
183
193
|
// All should normalize to the same value
|
|
184
194
|
const uniqueValues = new Set(normalized);
|
|
185
195
|
expect(uniqueValues.size).toBe(1);
|
|
@@ -223,19 +233,21 @@ describe("IP Normalization", () => {
|
|
|
223
233
|
describe("Edge Cases", () => {
|
|
224
234
|
it("should handle localhost addresses", () => {
|
|
225
235
|
expect(normalizeIP("127.0.0.1")).toBe("127.0.0.1");
|
|
226
|
-
expect(normalizeIP("::1")).toBe(
|
|
236
|
+
expect(normalizeIP("::1", { ipv6Subnet: 128 })).toBe(
|
|
227
237
|
"0000:0000:0000:0000:0000:0000:0000:0001",
|
|
228
238
|
);
|
|
229
239
|
});
|
|
230
240
|
|
|
231
241
|
it("should handle all-zeros address", () => {
|
|
232
242
|
expect(normalizeIP("0.0.0.0")).toBe("0.0.0.0");
|
|
233
|
-
expect(normalizeIP("::")).toBe(
|
|
243
|
+
expect(normalizeIP("::", { ipv6Subnet: 128 })).toBe(
|
|
244
|
+
"0000:0000:0000:0000:0000:0000:0000:0000",
|
|
245
|
+
);
|
|
234
246
|
});
|
|
235
247
|
|
|
236
248
|
it("should handle link-local addresses", () => {
|
|
237
249
|
expect(normalizeIP("169.254.0.1")).toBe("169.254.0.1");
|
|
238
|
-
expect(normalizeIP("fe80::1")).toBe(
|
|
250
|
+
expect(normalizeIP("fe80::1", { ipv6Subnet: 128 })).toBe(
|
|
239
251
|
"fe80:0000:0000:0000:0000:0000:0000:0001",
|
|
240
252
|
);
|
|
241
253
|
});
|
package/src/utils/ip.ts
CHANGED
|
@@ -160,7 +160,7 @@ function normalizeIPv6(
|
|
|
160
160
|
*
|
|
161
161
|
* @example
|
|
162
162
|
* normalizeIP("2001:DB8::1")
|
|
163
|
-
* // -> "2001:0db8:0000:0000:0000:0000:0000:
|
|
163
|
+
* // -> "2001:0db8:0000:0000:0000:0000:0000:0000"
|
|
164
164
|
*
|
|
165
165
|
* @example
|
|
166
166
|
* normalizeIP("::ffff:192.0.2.1")
|
|
@@ -192,7 +192,7 @@ export function normalizeIP(
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
// Normalize IPv6
|
|
195
|
-
const subnetPrefix = options.ipv6Subnet ||
|
|
195
|
+
const subnetPrefix = options.ipv6Subnet || 64;
|
|
196
196
|
return normalizeIPv6(ip, subnetPrefix);
|
|
197
197
|
}
|
|
198
198
|
|