@mokoenterprises/mokomysql-mcp 2.7.0 → 2.7.3
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/secrets.d.ts.map +1 -1
- package/dist/secrets.js +53 -21
- package/dist/secrets.js.map +1 -1
- package/package.json +1 -1
- package/source/secrets.ts +57 -20
package/dist/secrets.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../source/secrets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../source/secrets.ts"],"names":[],"mappings":"AAkLA;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAenE"}
|
package/dist/secrets.js
CHANGED
|
@@ -46,14 +46,29 @@ function selectFragment(json, fragment) {
|
|
|
46
46
|
}
|
|
47
47
|
/** Fields, in priority order, auto-extracted from a bare JSON token file. */
|
|
48
48
|
const JSON_SECRET_FIELDS = ['token', 'password', 'api_key', 'apiKey', 'key', 'access_token'];
|
|
49
|
+
/**
|
|
50
|
+
* Google credential `type` values (service-account / user / workload-identity).
|
|
51
|
+
* A Google credential JSON is NEVER a usable secret here — a MySQL password is not a
|
|
52
|
+
* Google credential, and a private key must never be sent as one — so a bare `file:`
|
|
53
|
+
* ref pointing at one is refused loudly rather than leaked as the raw blob (MokoCLI #1043).
|
|
54
|
+
*/
|
|
55
|
+
const GOOGLE_TYPES = new Set([
|
|
56
|
+
'service_account',
|
|
57
|
+
'authorized_user',
|
|
58
|
+
'external_account',
|
|
59
|
+
'impersonated_service_account',
|
|
60
|
+
]);
|
|
49
61
|
/**
|
|
50
62
|
* Resolve a single config string.
|
|
51
|
-
* - "file:<path>" -> the trimmed contents of <path>. If those contents
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
63
|
+
* - "file:<path>" -> the trimmed contents of <path>. If those contents are a
|
|
64
|
+
* JSON object, the #1043 detection ladder applies: a Google
|
|
65
|
+
* credential JSON is refused (never used as a secret); else the
|
|
66
|
+
* first present string field among
|
|
67
|
+
* token/password/api_key/apiKey/key/access_token is returned
|
|
68
|
+
* (fleet JSON token files, e.g. ~/.ssh/mysql/*.json with the
|
|
69
|
+
* password under `.token`); a JSON object with no recognized
|
|
70
|
+
* field is refused (never leaked as a raw blob). Content that
|
|
71
|
+
* is not JSON falls through to the raw trimmed value, so plain
|
|
57
72
|
* password files keep working.
|
|
58
73
|
* - "file:<path>#<field>" -> the <field> string from the JSON in <path>
|
|
59
74
|
* (back-compat with the legacy `file:X.json#token`
|
|
@@ -106,26 +121,43 @@ async function resolveRef(value) {
|
|
|
106
121
|
}
|
|
107
122
|
else {
|
|
108
123
|
out = raw.replace(/\r?\n+$/, '');
|
|
109
|
-
// Fleet JSON token files (~/.ssh/mysql/*.json): if a bare `file:` ref points
|
|
110
|
-
//
|
|
111
|
-
//
|
|
124
|
+
// Fleet JSON token files (~/.ssh/mysql/*.json): if a bare `file:` ref points at a
|
|
125
|
+
// JSON object, apply the #1043 detection ladder. A value that does not parse as
|
|
126
|
+
// JSON (a plain password that happens to start with '{') falls through to the raw
|
|
127
|
+
// trimmed content, preserving prior behavior for plain password files.
|
|
112
128
|
const s = out.trim();
|
|
113
129
|
if (s.startsWith('{')) {
|
|
130
|
+
let json;
|
|
114
131
|
try {
|
|
115
|
-
|
|
116
|
-
if (json && typeof json === 'object' && !Array.isArray(json)) {
|
|
117
|
-
const rec = json;
|
|
118
|
-
for (const field of JSON_SECRET_FIELDS) {
|
|
119
|
-
const v = rec[field];
|
|
120
|
-
if (typeof v === 'string' && v.trim() !== '') {
|
|
121
|
-
out = v.trim();
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
132
|
+
json = JSON.parse(s);
|
|
126
133
|
}
|
|
127
134
|
catch {
|
|
128
|
-
// Not JSON —
|
|
135
|
+
json = undefined; // Not JSON — keep the raw trimmed content below.
|
|
136
|
+
}
|
|
137
|
+
if (json && typeof json === 'object' && !Array.isArray(json)) {
|
|
138
|
+
const rec = json;
|
|
139
|
+
// Google credential JSON is never a usable secret here — refuse loudly and
|
|
140
|
+
// never send a private key as the password (#1043).
|
|
141
|
+
const gtype = typeof rec.type === 'string' ? rec.type : '';
|
|
142
|
+
if (GOOGLE_TYPES.has(gtype) || (typeof rec.refresh_token === 'string' && typeof rec.token_uri === 'string')) {
|
|
143
|
+
throw new Error(`Secret file "${path}" (referenced as "${value}") is a Google ${gtype || 'OAuth token-cache'} JSON credential, which cannot be used as a secret here; refusing (a private key must never be used as a password).`);
|
|
144
|
+
}
|
|
145
|
+
// GitHub/OAuth-style and fleet JSON token files: take the first present
|
|
146
|
+
// string field among token/password/api_key/apiKey/key/access_token.
|
|
147
|
+
let picked;
|
|
148
|
+
for (const field of JSON_SECRET_FIELDS) {
|
|
149
|
+
const v = rec[field];
|
|
150
|
+
if (typeof v === 'string' && v.trim() !== '') {
|
|
151
|
+
picked = v.trim();
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (picked === undefined) {
|
|
156
|
+
// A recognized JSON object with no known secret field: do NOT fall through
|
|
157
|
+
// to the raw blob (that would send the whole JSON as the secret) (#1043).
|
|
158
|
+
throw new Error(`Secret file "${path}" (referenced as "${value}") is a JSON object with no recognized secret field (${JSON_SECRET_FIELDS.join('/')}); refusing to use the raw JSON as a secret.`);
|
|
159
|
+
}
|
|
160
|
+
out = picked;
|
|
129
161
|
}
|
|
130
162
|
}
|
|
131
163
|
}
|
package/dist/secrets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../source/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE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AI,OAAO,CAAC,KAAK,QAAQ;gBAAE,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC;iBACnD,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ;gBAAE,MAAM,iBAAiB,CAAC,CAAC,CAAC,CAAC;QACjE,CAAC;IACF,CAAC;AACF,CAAC"}
|
package/package.json
CHANGED
package/source/secrets.ts
CHANGED
|
@@ -49,14 +49,30 @@ function selectFragment(json: unknown, fragment: string): unknown {
|
|
|
49
49
|
/** Fields, in priority order, auto-extracted from a bare JSON token file. */
|
|
50
50
|
const JSON_SECRET_FIELDS = ['token', 'password', 'api_key', 'apiKey', 'key', 'access_token'] as const;
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Google credential `type` values (service-account / user / workload-identity).
|
|
54
|
+
* A Google credential JSON is NEVER a usable secret here — a MySQL password is not a
|
|
55
|
+
* Google credential, and a private key must never be sent as one — so a bare `file:`
|
|
56
|
+
* ref pointing at one is refused loudly rather than leaked as the raw blob (MokoCLI #1043).
|
|
57
|
+
*/
|
|
58
|
+
const GOOGLE_TYPES = new Set([
|
|
59
|
+
'service_account',
|
|
60
|
+
'authorized_user',
|
|
61
|
+
'external_account',
|
|
62
|
+
'impersonated_service_account',
|
|
63
|
+
]);
|
|
64
|
+
|
|
52
65
|
/**
|
|
53
66
|
* Resolve a single config string.
|
|
54
|
-
* - "file:<path>" -> the trimmed contents of <path>. If those contents
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
67
|
+
* - "file:<path>" -> the trimmed contents of <path>. If those contents are a
|
|
68
|
+
* JSON object, the #1043 detection ladder applies: a Google
|
|
69
|
+
* credential JSON is refused (never used as a secret); else the
|
|
70
|
+
* first present string field among
|
|
71
|
+
* token/password/api_key/apiKey/key/access_token is returned
|
|
72
|
+
* (fleet JSON token files, e.g. ~/.ssh/mysql/*.json with the
|
|
73
|
+
* password under `.token`); a JSON object with no recognized
|
|
74
|
+
* field is refused (never leaked as a raw blob). Content that
|
|
75
|
+
* is not JSON falls through to the raw trimmed value, so plain
|
|
60
76
|
* password files keep working.
|
|
61
77
|
* - "file:<path>#<field>" -> the <field> string from the JSON in <path>
|
|
62
78
|
* (back-compat with the legacy `file:X.json#token`
|
|
@@ -109,25 +125,46 @@ async function resolveRef(value: string): Promise<string> {
|
|
|
109
125
|
out = picked.replace(/\r?\n+$/, '');
|
|
110
126
|
} else {
|
|
111
127
|
out = raw.replace(/\r?\n+$/, '');
|
|
112
|
-
// Fleet JSON token files (~/.ssh/mysql/*.json): if a bare `file:` ref points
|
|
113
|
-
//
|
|
114
|
-
//
|
|
128
|
+
// Fleet JSON token files (~/.ssh/mysql/*.json): if a bare `file:` ref points at a
|
|
129
|
+
// JSON object, apply the #1043 detection ladder. A value that does not parse as
|
|
130
|
+
// JSON (a plain password that happens to start with '{') falls through to the raw
|
|
131
|
+
// trimmed content, preserving prior behavior for plain password files.
|
|
115
132
|
const s = out.trim();
|
|
116
133
|
if (s.startsWith('{')) {
|
|
134
|
+
let json: unknown;
|
|
117
135
|
try {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
json = JSON.parse(s);
|
|
137
|
+
} catch {
|
|
138
|
+
json = undefined; // Not JSON — keep the raw trimmed content below.
|
|
139
|
+
}
|
|
140
|
+
if (json && typeof json === 'object' && !Array.isArray(json)) {
|
|
141
|
+
const rec = json as Record<string, unknown>;
|
|
142
|
+
// Google credential JSON is never a usable secret here — refuse loudly and
|
|
143
|
+
// never send a private key as the password (#1043).
|
|
144
|
+
const gtype = typeof rec.type === 'string' ? rec.type : '';
|
|
145
|
+
if (GOOGLE_TYPES.has(gtype) || (typeof rec.refresh_token === 'string' && typeof rec.token_uri === 'string')) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Secret file "${path}" (referenced as "${value}") is a Google ${gtype || 'OAuth token-cache'} JSON credential, which cannot be used as a secret here; refusing (a private key must never be used as a password).`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
// GitHub/OAuth-style and fleet JSON token files: take the first present
|
|
151
|
+
// string field among token/password/api_key/apiKey/key/access_token.
|
|
152
|
+
let picked: string | undefined;
|
|
153
|
+
for (const field of JSON_SECRET_FIELDS) {
|
|
154
|
+
const v = rec[field];
|
|
155
|
+
if (typeof v === 'string' && v.trim() !== '') {
|
|
156
|
+
picked = v.trim();
|
|
157
|
+
break;
|
|
127
158
|
}
|
|
128
159
|
}
|
|
129
|
-
|
|
130
|
-
|
|
160
|
+
if (picked === undefined) {
|
|
161
|
+
// A recognized JSON object with no known secret field: do NOT fall through
|
|
162
|
+
// to the raw blob (that would send the whole JSON as the secret) (#1043).
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Secret file "${path}" (referenced as "${value}") is a JSON object with no recognized secret field (${JSON_SECRET_FIELDS.join('/')}); refusing to use the raw JSON as a secret.`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
out = picked;
|
|
131
168
|
}
|
|
132
169
|
}
|
|
133
170
|
}
|