heimdall-sdk 0.1.0 → 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alessandro Amormino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,49 @@
1
1
  function shouldIgnore(url, patterns) {
2
2
  return patterns.some(p => typeof p === 'string' ? url.includes(p) : p.test(url));
3
3
  }
4
+ const SENSITIVE_URL_PARAMS = new Set([
5
+ 'access_token', 'token', 'api_key', 'apikey', 'secret', 'key',
6
+ 'auth', 'password', 'pass', 'pwd', 'client_secret', 'private_key',
7
+ 'api_secret', 'api_token', 'client_id',
8
+ ]);
9
+ const SENSITIVE_HEADERS = new Set([
10
+ 'authorization', 'x-api-key', 'x-auth-token', 'x-access-token',
11
+ 'x-secret', 'x-secret-key', 'x-token', 'x-auth', 'cookie',
12
+ 'x-api-secret', 'x-private-key',
13
+ ]);
14
+ const TOKEN_PATTERNS = [
15
+ /^eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/, // JWT
16
+ /^(sk|pk)\.[A-Za-z0-9._-]{20,}/, // Mapbox
17
+ /^[a-f0-9]{32,}$/, // hex API key
18
+ /^[A-Za-z0-9+/]{40,}={0,2}$/, // base64
19
+ ];
20
+ function looksLikeToken(value) {
21
+ return TOKEN_PATTERNS.some(p => p.test(value));
22
+ }
23
+ function scanForSecrets(url, headers) {
24
+ const warnings = [];
25
+ let safeUrl = url;
26
+ try {
27
+ const parsed = new URL(url);
28
+ parsed.searchParams.forEach((value, key) => {
29
+ if (SENSITIVE_URL_PARAMS.has(key.toLowerCase()) || looksLikeToken(value)) {
30
+ warnings.push(`Exposed secret in URL parameter "${key}"`);
31
+ parsed.searchParams.set(key, '[REDACTED]');
32
+ }
33
+ });
34
+ if (warnings.length > 0)
35
+ safeUrl = parsed.toString();
36
+ }
37
+ catch { /* relative URL */ }
38
+ const safeHeaders = { ...headers };
39
+ for (const [key, value] of Object.entries(headers)) {
40
+ if (SENSITIVE_HEADERS.has(key.toLowerCase()) || looksLikeToken(value)) {
41
+ warnings.push(`Exposed secret in header "${key}"`);
42
+ safeHeaders[key] = '[REDACTED]';
43
+ }
44
+ }
45
+ return { url: safeUrl, requestHeaders: safeHeaders, warnings };
46
+ }
4
47
  function sendLog(collectorUrl, payload) {
5
48
  // Use the original fetch before we patch it
6
49
  const f = window.__heimdall_fetch;
@@ -37,7 +80,8 @@ export function patchFetch(config) {
37
80
  requestBodyParsed = String(requestBody);
38
81
  }
39
82
  }
40
- const requestHeaders = Object.fromEntries(new Headers(init?.headers ?? (input instanceof Request ? input.headers : {})).entries());
83
+ const rawHeaders = Object.fromEntries(new Headers(init?.headers ?? (input instanceof Request ? input.headers : {})).entries());
84
+ const scanned = scanForSecrets(url, rawHeaders);
41
85
  const start = performance.now();
42
86
  let response;
43
87
  try {
@@ -46,11 +90,12 @@ export function patchFetch(config) {
46
90
  catch (err) {
47
91
  sendLog(config.collectorUrl, {
48
92
  method,
49
- url,
93
+ url: scanned.url,
50
94
  error: String(err),
51
95
  duration_ms: Math.round(performance.now() - start),
52
- request_headers: requestHeaders,
96
+ request_headers: scanned.requestHeaders,
53
97
  request_body: requestBodyParsed,
98
+ security_warnings: scanned.warnings.length ? scanned.warnings : undefined,
54
99
  project: config.project ?? 'default',
55
100
  timestamp: new Date().toISOString(),
56
101
  });
@@ -72,13 +117,14 @@ export function patchFetch(config) {
72
117
  const responseHeaders = Object.fromEntries(response.headers.entries());
73
118
  sendLog(config.collectorUrl, {
74
119
  method,
75
- url,
120
+ url: scanned.url,
76
121
  status_code: response.status,
77
122
  duration_ms: duration,
78
- request_headers: requestHeaders,
123
+ request_headers: scanned.requestHeaders,
79
124
  request_body: requestBodyParsed,
80
125
  response_headers: responseHeaders,
81
126
  response_body: responseBody,
127
+ security_warnings: scanned.warnings.length ? scanned.warnings : undefined,
82
128
  project: config.project ?? 'default',
83
129
  timestamp: new Date().toISOString(),
84
130
  });
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "heimdall-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Heimdall SDK — zero-config API logger for React",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "license": "MIT",
8
9
  "files": ["dist"],
9
10
  "scripts": {
10
11
  "build": "tsc",