@mcp-z/oauth 1.0.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 +21 -0
- package/README.md +71 -0
- package/dist/cjs/account-utils.d.cts +107 -0
- package/dist/cjs/account-utils.d.ts +107 -0
- package/dist/cjs/account-utils.js +481 -0
- package/dist/cjs/account-utils.js.map +1 -0
- package/dist/cjs/index.d.cts +19 -0
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.js +149 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/jwt-auth.d.cts +53 -0
- package/dist/cjs/jwt-auth.d.ts +53 -0
- package/dist/cjs/jwt-auth.js +417 -0
- package/dist/cjs/jwt-auth.js.map +1 -0
- package/dist/cjs/key-utils.d.cts +131 -0
- package/dist/cjs/key-utils.d.ts +131 -0
- package/dist/cjs/key-utils.js +421 -0
- package/dist/cjs/key-utils.js.map +1 -0
- package/dist/cjs/lib/account-server/index.d.cts +45 -0
- package/dist/cjs/lib/account-server/index.d.ts +45 -0
- package/dist/cjs/lib/account-server/index.js +67 -0
- package/dist/cjs/lib/account-server/index.js.map +1 -0
- package/dist/cjs/lib/account-server/loopback.d.cts +22 -0
- package/dist/cjs/lib/account-server/loopback.d.ts +22 -0
- package/dist/cjs/lib/account-server/loopback.js +778 -0
- package/dist/cjs/lib/account-server/loopback.js.map +1 -0
- package/dist/cjs/lib/account-server/me.d.cts +23 -0
- package/dist/cjs/lib/account-server/me.d.ts +23 -0
- package/dist/cjs/lib/account-server/me.js +412 -0
- package/dist/cjs/lib/account-server/me.js.map +1 -0
- package/dist/cjs/lib/account-server/shared-utils.d.cts +6 -0
- package/dist/cjs/lib/account-server/shared-utils.d.ts +6 -0
- package/dist/cjs/lib/account-server/shared-utils.js +235 -0
- package/dist/cjs/lib/account-server/shared-utils.js.map +1 -0
- package/dist/cjs/lib/account-server/stateless.d.cts +20 -0
- package/dist/cjs/lib/account-server/stateless.d.ts +20 -0
- package/dist/cjs/lib/account-server/stateless.js +32 -0
- package/dist/cjs/lib/account-server/stateless.js.map +1 -0
- package/dist/cjs/lib/account-server/types.d.cts +32 -0
- package/dist/cjs/lib/account-server/types.d.ts +32 -0
- package/dist/cjs/lib/account-server/types.js +7 -0
- package/dist/cjs/lib/account-server/types.js.map +1 -0
- package/dist/cjs/lib/dcr-types.d.cts +126 -0
- package/dist/cjs/lib/dcr-types.d.ts +126 -0
- package/dist/cjs/lib/dcr-types.js +12 -0
- package/dist/cjs/lib/dcr-types.js.map +1 -0
- package/dist/cjs/lib/rfc-metadata-types.d.cts +46 -0
- package/dist/cjs/lib/rfc-metadata-types.d.ts +46 -0
- package/dist/cjs/lib/rfc-metadata-types.js +8 -0
- package/dist/cjs/lib/rfc-metadata-types.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pkce.d.cts +36 -0
- package/dist/cjs/pkce.d.ts +36 -0
- package/dist/cjs/pkce.js +25 -0
- package/dist/cjs/pkce.js.map +1 -0
- package/dist/cjs/sanitizer.d.cts +37 -0
- package/dist/cjs/sanitizer.d.ts +37 -0
- package/dist/cjs/sanitizer.js +407 -0
- package/dist/cjs/sanitizer.js.map +1 -0
- package/dist/cjs/schemas/index.d.cts +36 -0
- package/dist/cjs/schemas/index.d.ts +36 -0
- package/dist/cjs/schemas/index.js +28 -0
- package/dist/cjs/schemas/index.js.map +1 -0
- package/dist/cjs/session-auth.d.cts +79 -0
- package/dist/cjs/session-auth.d.ts +79 -0
- package/dist/cjs/session-auth.js +354 -0
- package/dist/cjs/session-auth.js.map +1 -0
- package/dist/cjs/templates.d.cts +18 -0
- package/dist/cjs/templates.d.ts +18 -0
- package/dist/cjs/templates.js +38 -0
- package/dist/cjs/templates.js.map +1 -0
- package/dist/cjs/types.d.cts +343 -0
- package/dist/cjs/types.d.ts +343 -0
- package/dist/cjs/types.js +210 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/account-utils.d.ts +107 -0
- package/dist/esm/account-utils.js +179 -0
- package/dist/esm/account-utils.js.map +1 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/jwt-auth.d.ts +53 -0
- package/dist/esm/jwt-auth.js +164 -0
- package/dist/esm/jwt-auth.js.map +1 -0
- package/dist/esm/key-utils.d.ts +131 -0
- package/dist/esm/key-utils.js +143 -0
- package/dist/esm/key-utils.js.map +1 -0
- package/dist/esm/lib/account-server/index.d.ts +45 -0
- package/dist/esm/lib/account-server/index.js +41 -0
- package/dist/esm/lib/account-server/index.js.map +1 -0
- package/dist/esm/lib/account-server/loopback.d.ts +22 -0
- package/dist/esm/lib/account-server/loopback.js +372 -0
- package/dist/esm/lib/account-server/loopback.js.map +1 -0
- package/dist/esm/lib/account-server/me.d.ts +23 -0
- package/dist/esm/lib/account-server/me.js +170 -0
- package/dist/esm/lib/account-server/me.js.map +1 -0
- package/dist/esm/lib/account-server/shared-utils.d.ts +6 -0
- package/dist/esm/lib/account-server/shared-utils.js +24 -0
- package/dist/esm/lib/account-server/shared-utils.js.map +1 -0
- package/dist/esm/lib/account-server/stateless.d.ts +20 -0
- package/dist/esm/lib/account-server/stateless.js +25 -0
- package/dist/esm/lib/account-server/stateless.js.map +1 -0
- package/dist/esm/lib/account-server/types.d.ts +32 -0
- package/dist/esm/lib/account-server/types.js +6 -0
- package/dist/esm/lib/account-server/types.js.map +1 -0
- package/dist/esm/lib/dcr-types.d.ts +126 -0
- package/dist/esm/lib/dcr-types.js +13 -0
- package/dist/esm/lib/dcr-types.js.map +1 -0
- package/dist/esm/lib/rfc-metadata-types.d.ts +46 -0
- package/dist/esm/lib/rfc-metadata-types.js +7 -0
- package/dist/esm/lib/rfc-metadata-types.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/pkce.d.ts +36 -0
- package/dist/esm/pkce.js +33 -0
- package/dist/esm/pkce.js.map +1 -0
- package/dist/esm/sanitizer.d.ts +37 -0
- package/dist/esm/sanitizer.js +256 -0
- package/dist/esm/sanitizer.js.map +1 -0
- package/dist/esm/schemas/index.d.ts +36 -0
- package/dist/esm/schemas/index.js +19 -0
- package/dist/esm/schemas/index.js.map +1 -0
- package/dist/esm/session-auth.d.ts +79 -0
- package/dist/esm/session-auth.js +141 -0
- package/dist/esm/session-auth.js.map +1 -0
- package/dist/esm/templates.d.ts +18 -0
- package/dist/esm/templates.js +132 -0
- package/dist/esm/templates.js.map +1 -0
- package/dist/esm/types.d.ts +343 -0
- package/dist/esm/types.js +34 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get sanitizeData () {
|
|
13
|
+
return sanitizeData;
|
|
14
|
+
},
|
|
15
|
+
get sanitizeForLogging () {
|
|
16
|
+
return sanitizeForLogging;
|
|
17
|
+
},
|
|
18
|
+
get sanitizeForLoggingFormatter () {
|
|
19
|
+
return sanitizeForLoggingFormatter;
|
|
20
|
+
},
|
|
21
|
+
get sanitizeLogMessage () {
|
|
22
|
+
return sanitizeLogMessage;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
function _array_like_to_array(arr, len) {
|
|
26
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
27
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
28
|
+
return arr2;
|
|
29
|
+
}
|
|
30
|
+
function _array_with_holes(arr) {
|
|
31
|
+
if (Array.isArray(arr)) return arr;
|
|
32
|
+
}
|
|
33
|
+
function _define_property(obj, key, value) {
|
|
34
|
+
if (key in obj) {
|
|
35
|
+
Object.defineProperty(obj, key, {
|
|
36
|
+
value: value,
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
obj[key] = value;
|
|
43
|
+
}
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
function _iterable_to_array_limit(arr, i) {
|
|
47
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
48
|
+
if (_i == null) return;
|
|
49
|
+
var _arr = [];
|
|
50
|
+
var _n = true;
|
|
51
|
+
var _d = false;
|
|
52
|
+
var _s, _e;
|
|
53
|
+
try {
|
|
54
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
55
|
+
_arr.push(_s.value);
|
|
56
|
+
if (i && _arr.length === i) break;
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
_d = true;
|
|
60
|
+
_e = err;
|
|
61
|
+
} finally{
|
|
62
|
+
try {
|
|
63
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
64
|
+
} finally{
|
|
65
|
+
if (_d) throw _e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return _arr;
|
|
69
|
+
}
|
|
70
|
+
function _non_iterable_rest() {
|
|
71
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
72
|
+
}
|
|
73
|
+
function _object_spread(target) {
|
|
74
|
+
for(var i = 1; i < arguments.length; i++){
|
|
75
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
76
|
+
var ownKeys = Object.keys(source);
|
|
77
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
78
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
79
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
ownKeys.forEach(function(key) {
|
|
83
|
+
_define_property(target, key, source[key]);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return target;
|
|
87
|
+
}
|
|
88
|
+
function ownKeys(object, enumerableOnly) {
|
|
89
|
+
var keys = Object.keys(object);
|
|
90
|
+
if (Object.getOwnPropertySymbols) {
|
|
91
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
92
|
+
if (enumerableOnly) {
|
|
93
|
+
symbols = symbols.filter(function(sym) {
|
|
94
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
keys.push.apply(keys, symbols);
|
|
98
|
+
}
|
|
99
|
+
return keys;
|
|
100
|
+
}
|
|
101
|
+
function _object_spread_props(target, source) {
|
|
102
|
+
source = source != null ? source : {};
|
|
103
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
104
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
105
|
+
} else {
|
|
106
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
107
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return target;
|
|
111
|
+
}
|
|
112
|
+
function _sliced_to_array(arr, i) {
|
|
113
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
114
|
+
}
|
|
115
|
+
function _type_of(obj) {
|
|
116
|
+
"@swc/helpers - typeof";
|
|
117
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
118
|
+
}
|
|
119
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
120
|
+
if (!o) return;
|
|
121
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
122
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
123
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
124
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
125
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Data sanitization utilities for secure logging.
|
|
129
|
+
* Redacts sensitive OAuth tokens, API keys, and credentials from log output.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* sanitizeData({ accountId: 'test@example.com', access_token: 'secret_token_value' })
|
|
134
|
+
* // { accountId: 'test@example.com', access_token: 'secr****alue' }
|
|
135
|
+
*
|
|
136
|
+
* sanitizeForLogging('Processing token', { token: 'secret_value' })
|
|
137
|
+
* // { message: 'Processing token', meta: { token: 'secr****alue' } }
|
|
138
|
+
* ```
|
|
139
|
+
*/ /** Regex patterns for sensitive data that should be redacted from logs */ var SENSITIVE_PATTERNS = [
|
|
140
|
+
// OAuth tokens, codes, and secrets
|
|
141
|
+
/access_token['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
142
|
+
/(access_token_[a-zA-Z0-9_]+)/gi,
|
|
143
|
+
/refresh_token['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
144
|
+
/client_secret['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
145
|
+
/id_token['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
146
|
+
/\bcode['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
147
|
+
/\bstate['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
148
|
+
/code_verifier['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
149
|
+
/code_challenge['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
150
|
+
/codeVerifier['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
151
|
+
/codeChallenge['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
152
|
+
/device_code['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
153
|
+
/user_code['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
154
|
+
/verification_uri['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
155
|
+
/verification_uri_complete['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
156
|
+
// Provider credentials and identifiers
|
|
157
|
+
/app_secret['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
158
|
+
/appSecret['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
159
|
+
/tenant_id['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
160
|
+
/tenantId['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
161
|
+
/client_id['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
162
|
+
/clientId['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
163
|
+
/app_id['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
164
|
+
/appId['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
165
|
+
/redirect_uri['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
166
|
+
/redirectUri['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
167
|
+
/subscription_key['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
168
|
+
/subscriptionKey['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
169
|
+
// Security secrets and keys
|
|
170
|
+
/webhook_secret['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
171
|
+
/webhookSecret['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
172
|
+
/signing_secret['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
173
|
+
/signingSecret['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
174
|
+
/encryption_key['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
175
|
+
/encryptionKey['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
176
|
+
/private_key['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
177
|
+
/privateKey['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
178
|
+
/certificate['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
179
|
+
/cert['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
180
|
+
// Authorization headers
|
|
181
|
+
/Authorization['":\s]*['"]\s*Bearer\s+([^'"]+)['"]/gi,
|
|
182
|
+
/authorization['":\s]*['"]\s*Bearer\s+([^'"]+)['"]/gi,
|
|
183
|
+
/Bearer\s+([A-Za-z0-9+/=\-_.]+)/gi,
|
|
184
|
+
/Authorization:\s*Bearer\s+([A-Za-z0-9+/=\-_.]+)/gi,
|
|
185
|
+
/[A-Z_]+_(SECRET|KEY|TOKEN|PASSWORD)['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
186
|
+
// Session and CSRF tokens
|
|
187
|
+
/\bnonce['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
188
|
+
/session[_-]?id['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
189
|
+
/csrf[_-]?token['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
190
|
+
// Other sensitive patterns
|
|
191
|
+
/"email"\s*:\s*"([^@"]{1,64}@[^."]{1,63}\.[a-z]{2,6})"/gi,
|
|
192
|
+
/api[_-]?key['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
193
|
+
/password['":\s]*['"]\s*([^'"]+)['"]/gi,
|
|
194
|
+
/\b(ey[A-Za-z0-9+/=]+\.[A-Za-z0-9+/=]+\.[A-Za-z0-9+/=\-_]+)/g,
|
|
195
|
+
// Base64 secrets (split into length ranges for practical matching)
|
|
196
|
+
/\b([A-Za-z0-9+/]{60,200}={0,2})\b/g,
|
|
197
|
+
/\b([A-Za-z0-9+/]{201,1000}={0,2})\b/g,
|
|
198
|
+
/\b([A-Za-z0-9+/]{1001,5000}={0,2})\b/g,
|
|
199
|
+
// Connection identifiers
|
|
200
|
+
/connection[_-]?id['":\s]*['"]\s*([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})['"]/gi
|
|
201
|
+
];
|
|
202
|
+
/** Field names that should be redacted when found as object keys */ var SENSITIVE_FIELDS = new Set([
|
|
203
|
+
'access_token',
|
|
204
|
+
'accessToken',
|
|
205
|
+
'refresh_token',
|
|
206
|
+
'refreshToken',
|
|
207
|
+
'client_secret',
|
|
208
|
+
'clientSecret',
|
|
209
|
+
'id_token',
|
|
210
|
+
'idToken',
|
|
211
|
+
'code',
|
|
212
|
+
'authorization_code',
|
|
213
|
+
'authorizationCode',
|
|
214
|
+
'device_code',
|
|
215
|
+
'deviceCode',
|
|
216
|
+
'user_code',
|
|
217
|
+
'userCode',
|
|
218
|
+
'verification_uri',
|
|
219
|
+
'verificationUri',
|
|
220
|
+
'verification_uri_complete',
|
|
221
|
+
'verificationUriComplete',
|
|
222
|
+
'client_id',
|
|
223
|
+
'clientId',
|
|
224
|
+
'app_id',
|
|
225
|
+
'appId',
|
|
226
|
+
'app_secret',
|
|
227
|
+
'appSecret',
|
|
228
|
+
'tenant_id',
|
|
229
|
+
'tenantId',
|
|
230
|
+
'bot_id',
|
|
231
|
+
'botId',
|
|
232
|
+
'workspace_id',
|
|
233
|
+
'workspaceId',
|
|
234
|
+
'organization_id',
|
|
235
|
+
'organizationId',
|
|
236
|
+
'redirect_uri',
|
|
237
|
+
'redirectUri',
|
|
238
|
+
'audience',
|
|
239
|
+
'realm',
|
|
240
|
+
'domain',
|
|
241
|
+
'webhook_secret',
|
|
242
|
+
'webhookSecret',
|
|
243
|
+
'signing_secret',
|
|
244
|
+
'signingSecret',
|
|
245
|
+
'subscription_key',
|
|
246
|
+
'subscriptionKey',
|
|
247
|
+
'encryption_key',
|
|
248
|
+
'encryptionKey',
|
|
249
|
+
'private_key',
|
|
250
|
+
'privateKey',
|
|
251
|
+
'certificate',
|
|
252
|
+
'cert',
|
|
253
|
+
'stripe-signature',
|
|
254
|
+
'x-hub-signature',
|
|
255
|
+
'x-hub-signature-256',
|
|
256
|
+
'x-slack-signature',
|
|
257
|
+
'x-mcp-z-webhook-secret',
|
|
258
|
+
'password',
|
|
259
|
+
'secret',
|
|
260
|
+
'token',
|
|
261
|
+
'authorization',
|
|
262
|
+
'credential',
|
|
263
|
+
'auth',
|
|
264
|
+
'verifier',
|
|
265
|
+
'challenge',
|
|
266
|
+
'code_verifier',
|
|
267
|
+
'codeVerifier',
|
|
268
|
+
'code_challenge',
|
|
269
|
+
'codeChallenge',
|
|
270
|
+
'nonce',
|
|
271
|
+
'session_id',
|
|
272
|
+
'sessionId',
|
|
273
|
+
'csrf_token',
|
|
274
|
+
'csrfToken',
|
|
275
|
+
'api_key',
|
|
276
|
+
'apiKey',
|
|
277
|
+
'state',
|
|
278
|
+
'connection_id',
|
|
279
|
+
'connectionId',
|
|
280
|
+
'gmail_connection_id',
|
|
281
|
+
'gmailConnectionId'
|
|
282
|
+
]);
|
|
283
|
+
function isAlreadySanitized(value) {
|
|
284
|
+
return value.includes('****') || value.includes('[REDACTED]') || value === '[REDACTED]';
|
|
285
|
+
}
|
|
286
|
+
function redactValue(value) {
|
|
287
|
+
if (isAlreadySanitized(value)) {
|
|
288
|
+
return value;
|
|
289
|
+
}
|
|
290
|
+
if (value.length <= 8) {
|
|
291
|
+
return '*'.repeat(value.length);
|
|
292
|
+
}
|
|
293
|
+
// Show first 4 and last 4 characters
|
|
294
|
+
return "".concat(value.substring(0, 4), "****").concat(value.substring(value.length - 4));
|
|
295
|
+
}
|
|
296
|
+
function sanitizeData(data) {
|
|
297
|
+
if (typeof data === 'string') {
|
|
298
|
+
if (isAlreadySanitized(data)) {
|
|
299
|
+
return data;
|
|
300
|
+
}
|
|
301
|
+
var sanitized = data;
|
|
302
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
303
|
+
try {
|
|
304
|
+
for(var _iterator = SENSITIVE_PATTERNS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
305
|
+
var pattern = _step.value;
|
|
306
|
+
sanitized = sanitized.replace(pattern, function(match, captured) {
|
|
307
|
+
if (typeof captured === 'string') {
|
|
308
|
+
var redacted = redactValue(captured);
|
|
309
|
+
return match.replace(captured, redacted);
|
|
310
|
+
}
|
|
311
|
+
return match;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
} catch (err) {
|
|
315
|
+
_didIteratorError = true;
|
|
316
|
+
_iteratorError = err;
|
|
317
|
+
} finally{
|
|
318
|
+
try {
|
|
319
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
320
|
+
_iterator.return();
|
|
321
|
+
}
|
|
322
|
+
} finally{
|
|
323
|
+
if (_didIteratorError) {
|
|
324
|
+
throw _iteratorError;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return sanitized;
|
|
329
|
+
}
|
|
330
|
+
if (Array.isArray(data)) {
|
|
331
|
+
return data.map(sanitizeData);
|
|
332
|
+
}
|
|
333
|
+
if (data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === 'object') {
|
|
334
|
+
var sanitized1 = {};
|
|
335
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
336
|
+
try {
|
|
337
|
+
for(var _iterator1 = Object.entries(data)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
338
|
+
var _step_value = _sliced_to_array(_step1.value, 2), key = _step_value[0], value = _step_value[1];
|
|
339
|
+
var lowerKey = key.toLowerCase();
|
|
340
|
+
if (SENSITIVE_FIELDS.has(lowerKey) || SENSITIVE_FIELDS.has(key)) {
|
|
341
|
+
if (typeof value === 'string') {
|
|
342
|
+
sanitized1[key] = redactValue(value);
|
|
343
|
+
} else {
|
|
344
|
+
sanitized1[key] = '[REDACTED]';
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
sanitized1[key] = sanitizeData(value);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
} catch (err) {
|
|
351
|
+
_didIteratorError1 = true;
|
|
352
|
+
_iteratorError1 = err;
|
|
353
|
+
} finally{
|
|
354
|
+
try {
|
|
355
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
356
|
+
_iterator1.return();
|
|
357
|
+
}
|
|
358
|
+
} finally{
|
|
359
|
+
if (_didIteratorError1) {
|
|
360
|
+
throw _iteratorError1;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return sanitized1;
|
|
365
|
+
}
|
|
366
|
+
return data;
|
|
367
|
+
}
|
|
368
|
+
function sanitizeLogMessage(message) {
|
|
369
|
+
var maxLength = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 50000;
|
|
370
|
+
if (typeof message !== 'string') {
|
|
371
|
+
return String(message);
|
|
372
|
+
}
|
|
373
|
+
// Truncation protection - prevent log poisoning via huge payloads
|
|
374
|
+
var processedMessage = message;
|
|
375
|
+
if (processedMessage.length > maxLength) {
|
|
376
|
+
processedMessage = "".concat(processedMessage.substring(0, maxLength), " [TRUNCATED]");
|
|
377
|
+
}
|
|
378
|
+
return processedMessage.normalize('NFKC').replace(/\r\n|\r|\n/g, ' ').replace(/\t/g, ' ')// biome-ignore lint/suspicious/noControlCharactersInRegex: Security sanitization requires control character removal
|
|
379
|
+
.replace(/[\x00-\x1F\x7F-\x9F]/g, '').replace(/[\u200B-\u200D\uFEFF]/g, '') // Zero-width chars used for obfuscation
|
|
380
|
+
.trim();
|
|
381
|
+
}
|
|
382
|
+
function sanitizeForLogging(message, meta) {
|
|
383
|
+
var enableDataSanitization = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
|
|
384
|
+
var cleanMessage = sanitizeLogMessage(message);
|
|
385
|
+
if (!enableDataSanitization) {
|
|
386
|
+
return {
|
|
387
|
+
message: cleanMessage,
|
|
388
|
+
meta: meta || {}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
message: sanitizeData(cleanMessage),
|
|
393
|
+
meta: sanitizeData(meta || {})
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function sanitizeForLoggingFormatter() {
|
|
397
|
+
return {
|
|
398
|
+
log: function(obj) {
|
|
399
|
+
var message = obj.msg || obj.message || '';
|
|
400
|
+
var _sanitizeForLogging = sanitizeForLogging(message, obj), clean = _sanitizeForLogging.message, meta = _sanitizeForLogging.meta;
|
|
401
|
+
return _object_spread_props(_object_spread({}, meta), {
|
|
402
|
+
msg: clean
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/sanitizer.ts"],"sourcesContent":["/**\n * Data sanitization utilities for secure logging.\n * Redacts sensitive OAuth tokens, API keys, and credentials from log output.\n *\n * @example\n * ```typescript\n * sanitizeData({ accountId: 'test@example.com', access_token: 'secret_token_value' })\n * // { accountId: 'test@example.com', access_token: 'secr****alue' }\n *\n * sanitizeForLogging('Processing token', { token: 'secret_value' })\n * // { message: 'Processing token', meta: { token: 'secr****alue' } }\n * ```\n */\n\n/** Regex patterns for sensitive data that should be redacted from logs */\nconst SENSITIVE_PATTERNS = [\n // OAuth tokens, codes, and secrets\n /access_token['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /(access_token_[a-zA-Z0-9_]+)/gi,\n /refresh_token['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /client_secret['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /id_token['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /\\bcode['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /\\bstate['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /code_verifier['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /code_challenge['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /codeVerifier['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /codeChallenge['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /device_code['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /user_code['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /verification_uri['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /verification_uri_complete['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n\n // Provider credentials and identifiers\n /app_secret['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /appSecret['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /tenant_id['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /tenantId['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /client_id['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /clientId['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /app_id['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /appId['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /redirect_uri['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /redirectUri['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /subscription_key['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /subscriptionKey['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n\n // Security secrets and keys\n /webhook_secret['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /webhookSecret['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /signing_secret['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /signingSecret['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /encryption_key['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /encryptionKey['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /private_key['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /privateKey['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /certificate['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /cert['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n\n // Authorization headers\n /Authorization['\":\\s]*['\"]\\s*Bearer\\s+([^'\"]+)['\"]/gi,\n /authorization['\":\\s]*['\"]\\s*Bearer\\s+([^'\"]+)['\"]/gi,\n /Bearer\\s+([A-Za-z0-9+/=\\-_.]+)/gi,\n /Authorization:\\s*Bearer\\s+([A-Za-z0-9+/=\\-_.]+)/gi,\n /[A-Z_]+_(SECRET|KEY|TOKEN|PASSWORD)['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n\n // Session and CSRF tokens\n /\\bnonce['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /session[_-]?id['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /csrf[_-]?token['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n\n // Other sensitive patterns\n /\"email\"\\s*:\\s*\"([^@\"]{1,64}@[^.\"]{1,63}\\.[a-z]{2,6})\"/gi,\n /api[_-]?key['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /password['\":\\s]*['\"]\\s*([^'\"]+)['\"]/gi,\n /\\b(ey[A-Za-z0-9+/=]+\\.[A-Za-z0-9+/=]+\\.[A-Za-z0-9+/=\\-_]+)/g,\n\n // Base64 secrets (split into length ranges for practical matching)\n /\\b([A-Za-z0-9+/]{60,200}={0,2})\\b/g,\n /\\b([A-Za-z0-9+/]{201,1000}={0,2})\\b/g,\n /\\b([A-Za-z0-9+/]{1001,5000}={0,2})\\b/g,\n\n // Connection identifiers\n /connection[_-]?id['\":\\s]*['\"]\\s*([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})['\"]/gi,\n];\n\n/** Field names that should be redacted when found as object keys */\nconst SENSITIVE_FIELDS = new Set([\n 'access_token',\n 'accessToken',\n 'refresh_token',\n 'refreshToken',\n 'client_secret',\n 'clientSecret',\n 'id_token',\n 'idToken',\n 'code',\n 'authorization_code',\n 'authorizationCode',\n 'device_code',\n 'deviceCode',\n 'user_code',\n 'userCode',\n 'verification_uri',\n 'verificationUri',\n 'verification_uri_complete',\n 'verificationUriComplete',\n 'client_id',\n 'clientId',\n 'app_id',\n 'appId',\n 'app_secret',\n 'appSecret',\n 'tenant_id',\n 'tenantId',\n 'bot_id',\n 'botId',\n 'workspace_id',\n 'workspaceId',\n 'organization_id',\n 'organizationId',\n 'redirect_uri',\n 'redirectUri',\n 'audience',\n 'realm',\n 'domain',\n 'webhook_secret',\n 'webhookSecret',\n 'signing_secret',\n 'signingSecret',\n 'subscription_key',\n 'subscriptionKey',\n 'encryption_key',\n 'encryptionKey',\n 'private_key',\n 'privateKey',\n 'certificate',\n 'cert',\n 'stripe-signature',\n 'x-hub-signature',\n 'x-hub-signature-256',\n 'x-slack-signature',\n 'x-mcp-z-webhook-secret',\n 'password',\n 'secret',\n 'token',\n 'authorization',\n 'credential',\n 'auth',\n 'verifier',\n 'challenge',\n 'code_verifier',\n 'codeVerifier',\n 'code_challenge',\n 'codeChallenge',\n 'nonce',\n 'session_id',\n 'sessionId',\n 'csrf_token',\n 'csrfToken',\n 'api_key',\n 'apiKey',\n 'state',\n 'connection_id',\n 'connectionId',\n 'gmail_connection_id',\n 'gmailConnectionId',\n]);\n\nfunction isAlreadySanitized(value: string): boolean {\n return value.includes('****') || value.includes('[REDACTED]') || value === '[REDACTED]';\n}\n\nfunction redactValue(value: string): string {\n if (isAlreadySanitized(value)) {\n return value;\n }\n\n if (value.length <= 8) {\n return '*'.repeat(value.length);\n }\n\n // Show first 4 and last 4 characters\n return `${value.substring(0, 4)}****${value.substring(value.length - 4)}`;\n}\n\nexport function sanitizeData(data: unknown): unknown {\n if (typeof data === 'string') {\n if (isAlreadySanitized(data)) {\n return data;\n }\n\n let sanitized = data;\n for (const pattern of SENSITIVE_PATTERNS) {\n sanitized = sanitized.replace(pattern, (match, captured) => {\n if (typeof captured === 'string') {\n const redacted = redactValue(captured);\n return match.replace(captured, redacted);\n }\n return match;\n });\n }\n\n return sanitized;\n }\n\n if (Array.isArray(data)) {\n return data.map(sanitizeData);\n }\n\n if (data && typeof data === 'object') {\n const sanitized: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(data)) {\n const lowerKey = key.toLowerCase();\n\n if (SENSITIVE_FIELDS.has(lowerKey) || SENSITIVE_FIELDS.has(key)) {\n if (typeof value === 'string') {\n sanitized[key] = redactValue(value);\n } else {\n sanitized[key] = '[REDACTED]';\n }\n } else {\n sanitized[key] = sanitizeData(value);\n }\n }\n\n return sanitized;\n }\n\n return data;\n}\n\n/**\n * Prevent log injection attacks by escaping control characters\n * SECURITY: Critical for preventing CRLF injection (OWASP A03)\n */\nexport function sanitizeLogMessage(message: string, maxLength = 50000): string {\n if (typeof message !== 'string') {\n return String(message);\n }\n\n // Truncation protection - prevent log poisoning via huge payloads\n let processedMessage = message;\n if (processedMessage.length > maxLength) {\n processedMessage = `${processedMessage.substring(0, maxLength)} [TRUNCATED]`;\n }\n\n return (\n processedMessage\n .normalize('NFKC')\n .replace(/\\r\\n|\\r|\\n/g, ' ')\n .replace(/\\t/g, ' ')\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Security sanitization requires control character removal\n .replace(/[\\x00-\\x1F\\x7F-\\x9F]/g, '')\n .replace(/[\\u200B-\\u200D\\uFEFF]/g, '') // Zero-width chars used for obfuscation\n .trim()\n );\n}\n\n/**\n * Sanitize log message and metadata for safe logging\n * Applies both CRLF protection and sensitive data redaction\n *\n * @param message - The log message to sanitize\n * @param meta - Optional metadata object to sanitize\n * @param enableDataSanitization - Whether to apply sensitive data redaction (default: true)\n * @returns Sanitized message and metadata ready for logging\n */\nexport function sanitizeForLogging(message: string, meta?: Record<string, unknown>, enableDataSanitization = true): { message: string; meta: Record<string, unknown> } {\n const cleanMessage = sanitizeLogMessage(message);\n\n if (!enableDataSanitization) {\n return {\n message: cleanMessage,\n meta: meta || {},\n };\n }\n\n return {\n message: sanitizeData(cleanMessage) as string,\n meta: sanitizeData(meta || {}) as Record<string, unknown>,\n };\n}\n\nexport function sanitizeForLoggingFormatter() {\n return {\n log: (obj) => {\n const message = (obj.msg || obj.message || '') as string;\n const { message: clean, meta } = sanitizeForLogging(message, obj as Record<string, unknown>);\n return { ...meta, msg: clean };\n },\n };\n}\n"],"names":["sanitizeData","sanitizeForLogging","sanitizeForLoggingFormatter","sanitizeLogMessage","SENSITIVE_PATTERNS","SENSITIVE_FIELDS","Set","isAlreadySanitized","value","includes","redactValue","length","repeat","substring","data","sanitized","pattern","replace","match","captured","redacted","Array","isArray","map","Object","entries","key","lowerKey","toLowerCase","has","message","maxLength","String","processedMessage","normalize","trim","meta","enableDataSanitization","cleanMessage","log","obj","msg","clean"],"mappings":";;;;;;;;;;;QA0LgBA;eAAAA;;QAmFAC;eAAAA;;QAgBAC;eAAAA;;QAhDAC;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA7OhB;;;;;;;;;;;;CAYC,GAED,wEAAwE,GACxE,IAAMC,qBAAqB;IACzB,mCAAmC;IACnC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAEA,uCAAuC;IACvC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAEA,4BAA4B;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAEA,wBAAwB;IACxB;IACA;IACA;IACA;IACA;IAEA,0BAA0B;IAC1B;IACA;IACA;IAEA,2BAA2B;IAC3B;IACA;IACA;IACA;IAEA,mEAAmE;IACnE;IACA;IACA;IAEA,yBAAyB;IACzB;CACD;AAED,kEAAkE,GAClE,IAAMC,mBAAmB,IAAIC,IAAI;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,SAASC,mBAAmBC,KAAa;IACvC,OAAOA,MAAMC,QAAQ,CAAC,WAAWD,MAAMC,QAAQ,CAAC,iBAAiBD,UAAU;AAC7E;AAEA,SAASE,YAAYF,KAAa;IAChC,IAAID,mBAAmBC,QAAQ;QAC7B,OAAOA;IACT;IAEA,IAAIA,MAAMG,MAAM,IAAI,GAAG;QACrB,OAAO,IAAIC,MAAM,CAACJ,MAAMG,MAAM;IAChC;IAEA,qCAAqC;IACrC,OAAO,AAAC,GAA8BH,OAA5BA,MAAMK,SAAS,CAAC,GAAG,IAAG,QAAwC,OAAlCL,MAAMK,SAAS,CAACL,MAAMG,MAAM,GAAG;AACvE;AAEO,SAASX,aAAac,IAAa;IACxC,IAAI,OAAOA,SAAS,UAAU;QAC5B,IAAIP,mBAAmBO,OAAO;YAC5B,OAAOA;QACT;QAEA,IAAIC,YAAYD;YACX,kCAAA,2BAAA;;YAAL,QAAK,YAAiBV,uCAAjB,SAAA,6BAAA,QAAA,yBAAA,iCAAqC;gBAArC,IAAMY,UAAN;gBACHD,YAAYA,UAAUE,OAAO,CAACD,SAAS,SAACE,OAAOC;oBAC7C,IAAI,OAAOA,aAAa,UAAU;wBAChC,IAAMC,WAAWV,YAAYS;wBAC7B,OAAOD,MAAMD,OAAO,CAACE,UAAUC;oBACjC;oBACA,OAAOF;gBACT;YACF;;YARK;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;0BAAA;;;;QAUL,OAAOH;IACT;IAEA,IAAIM,MAAMC,OAAO,CAACR,OAAO;QACvB,OAAOA,KAAKS,GAAG,CAACvB;IAClB;IAEA,IAAIc,QAAQ,CAAA,OAAOA,qCAAP,SAAOA,KAAG,MAAM,UAAU;QACpC,IAAMC,aAAqC,CAAC;YAEvC,mCAAA,4BAAA;;YAAL,QAAK,aAAsBS,OAAOC,OAAO,CAACX,0BAArC,UAAA,8BAAA,SAAA,0BAAA,kCAA4C;gBAA5C,mCAAA,kBAAOY,sBAAKlB;gBACf,IAAMmB,WAAWD,IAAIE,WAAW;gBAEhC,IAAIvB,iBAAiBwB,GAAG,CAACF,aAAatB,iBAAiBwB,GAAG,CAACH,MAAM;oBAC/D,IAAI,OAAOlB,UAAU,UAAU;wBAC7BO,UAAS,CAACW,IAAI,GAAGhB,YAAYF;oBAC/B,OAAO;wBACLO,UAAS,CAACW,IAAI,GAAG;oBACnB;gBACF,OAAO;oBACLX,UAAS,CAACW,IAAI,GAAG1B,aAAaQ;gBAChC;YACF;;YAZK;YAAA;;;qBAAA,8BAAA;oBAAA;;;oBAAA;0BAAA;;;;QAcL,OAAOO;IACT;IAEA,OAAOD;AACT;AAMO,SAASX,mBAAmB2B,OAAe;QAAEC,YAAAA,iEAAY;IAC9D,IAAI,OAAOD,YAAY,UAAU;QAC/B,OAAOE,OAAOF;IAChB;IAEA,kEAAkE;IAClE,IAAIG,mBAAmBH;IACvB,IAAIG,iBAAiBtB,MAAM,GAAGoB,WAAW;QACvCE,mBAAmB,AAAC,GAA2C,OAAzCA,iBAAiBpB,SAAS,CAAC,GAAGkB,YAAW;IACjE;IAEA,OACEE,iBACGC,SAAS,CAAC,QACVjB,OAAO,CAAC,eAAe,KACvBA,OAAO,CAAC,OAAO,IAChB,oHAAoH;KACnHA,OAAO,CAAC,yBAAyB,IACjCA,OAAO,CAAC,0BAA0B,IAAI,wCAAwC;KAC9EkB,IAAI;AAEX;AAWO,SAASlC,mBAAmB6B,OAAe,EAAEM,IAA8B;QAAEC,yBAAAA,iEAAyB;IAC3G,IAAMC,eAAenC,mBAAmB2B;IAExC,IAAI,CAACO,wBAAwB;QAC3B,OAAO;YACLP,SAASQ;YACTF,MAAMA,QAAQ,CAAC;QACjB;IACF;IAEA,OAAO;QACLN,SAAS9B,aAAasC;QACtBF,MAAMpC,aAAaoC,QAAQ,CAAC;IAC9B;AACF;AAEO,SAASlC;IACd,OAAO;QACLqC,KAAK,SAACC;YACJ,IAAMV,UAAWU,IAAIC,GAAG,IAAID,IAAIV,OAAO,IAAI;YAC3C,IAAiC7B,sBAAAA,mBAAmB6B,SAASU,MAArDV,AAASY,QAAgBzC,oBAAzB6B,SAAgBM,OAASnC,oBAATmC;YACxB,OAAO,wCAAKA;gBAAMK,KAAKC;;QACzB;IACF;AACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth-specific schemas and response builders
|
|
3
|
+
*
|
|
4
|
+
* Provider-agnostic schemas and utilities for building OAuth auth_required responses.
|
|
5
|
+
* Individual OAuth packages (oauth-google, oauth-microsoft) wrap these with provider-specific defaults.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export type { z };
|
|
9
|
+
/**
|
|
10
|
+
* Authentication required response type
|
|
11
|
+
*/
|
|
12
|
+
export interface AuthRequired {
|
|
13
|
+
type: 'auth_required';
|
|
14
|
+
provider: string;
|
|
15
|
+
message: string;
|
|
16
|
+
url: string;
|
|
17
|
+
flow?: string;
|
|
18
|
+
instructions: string;
|
|
19
|
+
user_code?: string;
|
|
20
|
+
expires_in?: number;
|
|
21
|
+
accountId?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Zod schema for auth_required responses
|
|
25
|
+
*/
|
|
26
|
+
export declare const AuthRequiredSchema: z.ZodObject<{
|
|
27
|
+
type: z.ZodLiteral<"auth_required">;
|
|
28
|
+
provider: z.ZodString;
|
|
29
|
+
message: z.ZodString;
|
|
30
|
+
url: z.ZodString;
|
|
31
|
+
flow: z.ZodOptional<z.ZodString>;
|
|
32
|
+
instructions: z.ZodString;
|
|
33
|
+
user_code: z.ZodOptional<z.ZodString>;
|
|
34
|
+
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth-specific schemas and response builders
|
|
3
|
+
*
|
|
4
|
+
* Provider-agnostic schemas and utilities for building OAuth auth_required responses.
|
|
5
|
+
* Individual OAuth packages (oauth-google, oauth-microsoft) wrap these with provider-specific defaults.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export type { z };
|
|
9
|
+
/**
|
|
10
|
+
* Authentication required response type
|
|
11
|
+
*/
|
|
12
|
+
export interface AuthRequired {
|
|
13
|
+
type: 'auth_required';
|
|
14
|
+
provider: string;
|
|
15
|
+
message: string;
|
|
16
|
+
url: string;
|
|
17
|
+
flow?: string;
|
|
18
|
+
instructions: string;
|
|
19
|
+
user_code?: string;
|
|
20
|
+
expires_in?: number;
|
|
21
|
+
accountId?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Zod schema for auth_required responses
|
|
25
|
+
*/
|
|
26
|
+
export declare const AuthRequiredSchema: z.ZodObject<{
|
|
27
|
+
type: z.ZodLiteral<"auth_required">;
|
|
28
|
+
provider: z.ZodString;
|
|
29
|
+
message: z.ZodString;
|
|
30
|
+
url: z.ZodString;
|
|
31
|
+
flow: z.ZodOptional<z.ZodString>;
|
|
32
|
+
instructions: z.ZodString;
|
|
33
|
+
user_code: z.ZodOptional<z.ZodString>;
|
|
34
|
+
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth-specific schemas and response builders
|
|
3
|
+
*
|
|
4
|
+
* Provider-agnostic schemas and utilities for building OAuth auth_required responses.
|
|
5
|
+
* Individual OAuth packages (oauth-google, oauth-microsoft) wrap these with provider-specific defaults.
|
|
6
|
+
*/ "use strict";
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(exports, "AuthRequiredSchema", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return AuthRequiredSchema;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
var _zod = require("zod");
|
|
17
|
+
var AuthRequiredSchema = _zod.z.object({
|
|
18
|
+
type: _zod.z.literal('auth_required'),
|
|
19
|
+
provider: _zod.z.string().describe('OAuth provider name (e.g., "google", "microsoft")'),
|
|
20
|
+
message: _zod.z.string().describe('Human-readable message explaining why auth is needed'),
|
|
21
|
+
url: _zod.z.string().url().describe('Authentication URL to open in browser'),
|
|
22
|
+
flow: _zod.z.string().optional().describe('Authentication flow type (e.g., "auth_url", "device_code")'),
|
|
23
|
+
instructions: _zod.z.string().describe('Clear instructions for the user'),
|
|
24
|
+
user_code: _zod.z.string().optional().describe('Code user must enter at verification URL (device flows only)'),
|
|
25
|
+
expires_in: _zod.z.number().optional().describe('Seconds until code expires (device flows only)'),
|
|
26
|
+
accountId: _zod.z.string().optional().describe('Account identifier (email) that requires authentication')
|
|
27
|
+
}).describe('Authentication required with clear actionable instructions for user');
|
|
28
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/schemas/index.ts"],"sourcesContent":["/**\n * OAuth-specific schemas and response builders\n *\n * Provider-agnostic schemas and utilities for building OAuth auth_required responses.\n * Individual OAuth packages (oauth-google, oauth-microsoft) wrap these with provider-specific defaults.\n */\n\nimport { z } from 'zod';\n\n// Re-export z for use in middleware (MCP requires zod)\nexport type { z };\n\n/**\n * Authentication required response type\n */\nexport interface AuthRequired {\n type: 'auth_required';\n provider: string;\n message: string;\n url: string;\n flow?: string;\n instructions: string;\n user_code?: string;\n expires_in?: number;\n accountId?: string;\n}\n\n/**\n * Zod schema for auth_required responses\n */\nexport const AuthRequiredSchema = z\n .object({\n type: z.literal('auth_required'),\n provider: z.string().describe('OAuth provider name (e.g., \"google\", \"microsoft\")'),\n message: z.string().describe('Human-readable message explaining why auth is needed'),\n url: z.string().url().describe('Authentication URL to open in browser'),\n flow: z.string().optional().describe('Authentication flow type (e.g., \"auth_url\", \"device_code\")'),\n instructions: z.string().describe('Clear instructions for the user'),\n user_code: z.string().optional().describe('Code user must enter at verification URL (device flows only)'),\n expires_in: z.number().optional().describe('Seconds until code expires (device flows only)'),\n accountId: z.string().optional().describe('Account identifier (email) that requires authentication'),\n })\n .describe('Authentication required with clear actionable instructions for user');\n"],"names":["AuthRequiredSchema","z","object","type","literal","provider","string","describe","message","url","flow","optional","instructions","user_code","expires_in","number","accountId"],"mappings":"AAAA;;;;;CAKC;;;;+BAyBYA;;;eAAAA;;;mBAvBK;AAuBX,IAAMA,qBAAqBC,MAAC,CAChCC,MAAM,CAAC;IACNC,MAAMF,MAAC,CAACG,OAAO,CAAC;IAChBC,UAAUJ,MAAC,CAACK,MAAM,GAAGC,QAAQ,CAAC;IAC9BC,SAASP,MAAC,CAACK,MAAM,GAAGC,QAAQ,CAAC;IAC7BE,KAAKR,MAAC,CAACK,MAAM,GAAGG,GAAG,GAAGF,QAAQ,CAAC;IAC/BG,MAAMT,MAAC,CAACK,MAAM,GAAGK,QAAQ,GAAGJ,QAAQ,CAAC;IACrCK,cAAcX,MAAC,CAACK,MAAM,GAAGC,QAAQ,CAAC;IAClCM,WAAWZ,MAAC,CAACK,MAAM,GAAGK,QAAQ,GAAGJ,QAAQ,CAAC;IAC1CO,YAAYb,MAAC,CAACc,MAAM,GAAGJ,QAAQ,GAAGJ,QAAQ,CAAC;IAC3CS,WAAWf,MAAC,CAACK,MAAM,GAAGK,QAAQ,GAAGJ,QAAQ,CAAC;AAC5C,GACCA,QAAQ,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-based user authentication for multi-tenant deployments
|
|
3
|
+
*
|
|
4
|
+
* Extracts user ID from HTTP session cookies with HMAC signature verification.
|
|
5
|
+
* Compatible with Express/Connect session middleware patterns.
|
|
6
|
+
*/
|
|
7
|
+
import type { SessionUserAuthConfig, UserAuthProvider } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Session-based user authentication provider
|
|
10
|
+
*
|
|
11
|
+
* Verifies signed session cookies and extracts user IDs.
|
|
12
|
+
* Use for multi-tenant deployments where users authenticate via web sessions.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Multi-tenant server setup with session-based user authentication
|
|
17
|
+
* const userAuth = new SessionUserAuth({
|
|
18
|
+
* sessionSecret: process.env.SESSION_SECRET!,
|
|
19
|
+
* cookieName: 'app_session',
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Create OAuth adapters with session-based user identification
|
|
23
|
+
* const oauthAdapters = await createOAuthAdapters(
|
|
24
|
+
* config.transport,
|
|
25
|
+
* {
|
|
26
|
+
* service: 'gmail',
|
|
27
|
+
* clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
28
|
+
* clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
29
|
+
* scope: GOOGLE_SCOPE,
|
|
30
|
+
* auth: 'loopback-oauth',
|
|
31
|
+
* headless: false,
|
|
32
|
+
* redirectUri: undefined,
|
|
33
|
+
* },
|
|
34
|
+
* {
|
|
35
|
+
* logger,
|
|
36
|
+
* tokenStore,
|
|
37
|
+
* userAuth, // Session-based user identification for multi-tenant deployments
|
|
38
|
+
* }
|
|
39
|
+
* );
|
|
40
|
+
*
|
|
41
|
+
* // Use auth middleware with tools
|
|
42
|
+
* const { middleware: authMiddleware } = oauthAdapters;
|
|
43
|
+
* const tools = toolFactories.map(f => f()).map(authMiddleware.withToolAuth);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class SessionUserAuth implements UserAuthProvider {
|
|
47
|
+
private readonly secret;
|
|
48
|
+
private readonly cookieName;
|
|
49
|
+
private readonly algorithm;
|
|
50
|
+
constructor(config: SessionUserAuthConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Extract and verify user ID from session cookie
|
|
53
|
+
*
|
|
54
|
+
* @param req - HTTP request object with cookie header
|
|
55
|
+
* @returns User ID from verified session
|
|
56
|
+
* @throws Error if session missing, invalid, or expired
|
|
57
|
+
*/
|
|
58
|
+
getUserId(req: unknown): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Parse cookie from header string
|
|
61
|
+
*/
|
|
62
|
+
private parseCookie;
|
|
63
|
+
/**
|
|
64
|
+
* Generate HMAC signature for session data
|
|
65
|
+
*/
|
|
66
|
+
private sign;
|
|
67
|
+
/**
|
|
68
|
+
* Constant-time string comparison to prevent timing attacks
|
|
69
|
+
*/
|
|
70
|
+
private constantTimeCompare;
|
|
71
|
+
/**
|
|
72
|
+
* Helper for creating session cookies (for testing/integration)
|
|
73
|
+
*
|
|
74
|
+
* @param userId - User ID to encode in session
|
|
75
|
+
* @param expiresInMs - Optional expiration time in milliseconds from now
|
|
76
|
+
* @returns Signed session cookie value
|
|
77
|
+
*/
|
|
78
|
+
createSessionCookie(userId: string, expiresInMs?: number): string;
|
|
79
|
+
}
|