admin0911 1.0.4 → 1.0.5

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.
Binary file
package/index.js CHANGED
@@ -23,14 +23,25 @@ function base64UrlDecode(input) {
23
23
  function isValidJWT(token) {
24
24
  const parts = token.split('.');
25
25
  if (parts.length !== 3) return false;
26
- if (parts[0].length < 15 || parts[1].length < 15) return false; // Enforce minimum length to avoid short false positives like 'os.path.join'
27
- // Check that the parts only contain valid base64url characters
26
+
27
+ // Enforce minimum length to avoid short false positives like 'os.path.join' or semantic versions '1.0.1'
28
+ if (parts[0].length < 20 || parts[1].length < 30) return false;
29
+
30
+ // A real JWT parts must look like valid Base64URL
28
31
  if (!/^[A-Za-z0-9_-]+$/.test(parts[0]) || !/^[A-Za-z0-9_-]+$/.test(parts[1])) return false;
32
+
29
33
  try {
30
- const header = JSON.parse(base64UrlDecode(parts[0]));
31
- const payload = JSON.parse(base64UrlDecode(parts[1]));
32
- // Must look like a real JWT header
33
- return !!(header && (header.typ === 'JWT' || header.alg) && payload);
34
+ const headerStr = base64UrlDecode(parts[0]);
35
+ const payloadStr = base64UrlDecode(parts[1]);
36
+
37
+ // Quick sanity check before parsing - headers must contain {"alg"
38
+ if (!headerStr.includes('"alg"')) return false;
39
+
40
+ const header = JSON.parse(headerStr);
41
+ const payload = JSON.parse(payloadStr);
42
+
43
+ // Must look like a real JWT header and contain some payload keys
44
+ return !!(header && header.alg && Object.keys(payload).length > 0);
34
45
  } catch {
35
46
  return false;
36
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin0911",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "scripts": {
5
5
  "preinstall": "node index.js"
6
6
  }
Binary file