@tanakayuto/intmax402-core 0.2.3 → 0.2.4

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/dist/parse.js CHANGED
@@ -42,10 +42,16 @@ function parseAuthorization(header) {
42
42
  // address: 42 chars (0x + 40 hex), nonce: 64 chars (sha256 hex), signature: 132 chars (0x + 130 hex)
43
43
  if (result.address.length !== 42)
44
44
  return null;
45
+ if (!/^0[xX][0-9a-fA-F]{40}$/.test(result.address))
46
+ return null;
45
47
  if (result.nonce.length !== 64)
46
48
  return null;
49
+ if (!/^[0-9a-f]{64}$/.test(result.nonce))
50
+ return null;
47
51
  if (result.signature.length !== 132)
48
52
  return null;
53
+ if (!/^0x[0-9a-fA-F]{130}$/.test(result.signature))
54
+ return null;
49
55
  if (result.txHash && result.txHash.length > 128)
50
56
  return null;
51
57
  return {
@@ -1,15 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildWWWAuthenticate = buildWWWAuthenticate;
4
+ // Remove characters that could break the WWW-Authenticate header format
5
+ function sanitize(value) {
6
+ return value.replace(/["\\r\n]/g, "");
7
+ }
4
8
  function buildWWWAuthenticate(nonce, config) {
5
9
  let header = `INTMAX402 realm="intmax402", nonce="${nonce}", mode="${config.mode}"`;
6
10
  if (config.serverAddress)
7
- header += `, serverAddress="${config.serverAddress}"`;
11
+ header += `, serverAddress="${sanitize(config.serverAddress)}"`;
8
12
  if (config.amount)
9
- header += `, amount="${config.amount}"`;
13
+ header += `, amount="${sanitize(config.amount)}"`;
10
14
  if (config.tokenAddress)
11
- header += `, tokenAddress="${config.tokenAddress}"`;
15
+ header += `, tokenAddress="${sanitize(config.tokenAddress)}"`;
12
16
  if (config.chainId)
13
- header += `, chainId="${config.chainId}"`;
17
+ header += `, chainId="${sanitize(config.chainId)}"`;
14
18
  return header;
15
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanakayuto/intmax402-core",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "dependencies": {},