@mintlify/common 1.0.1136 → 1.0.1138
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.
|
@@ -3,4 +3,8 @@ import type { Root } from 'mdast';
|
|
|
3
3
|
export declare function isStringSafe(value: string): boolean;
|
|
4
4
|
export declare function filterStyleProperties(estree: Program): Program | null;
|
|
5
5
|
export declare function rebuildStyleValue(properties: Property[]): string;
|
|
6
|
+
export declare const MAX_PURE_DATA_DEPTH = 32;
|
|
7
|
+
export declare function isPureDataExpression(value: unknown, depth?: number): boolean;
|
|
8
|
+
export declare function isPureDataProgram(estree: Program): boolean;
|
|
9
|
+
export declare function isUnsafeDataAttributeName(name: string): boolean;
|
|
6
10
|
export declare function remarkMdxRemoveJs(): (tree: Root) => void;
|
|
@@ -211,6 +211,76 @@ export function rebuildStyleValue(properties) {
|
|
|
211
211
|
});
|
|
212
212
|
return `{ ${parts.join(', ')} }`;
|
|
213
213
|
}
|
|
214
|
+
function isJsxLikeNode(value) {
|
|
215
|
+
return (typeof value === 'object' && value !== null && 'type' in value && typeof value.type === 'string');
|
|
216
|
+
}
|
|
217
|
+
const UNSAFE_OBJECT_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
218
|
+
export const MAX_PURE_DATA_DEPTH = 32;
|
|
219
|
+
function isPureDataLiteral(node) {
|
|
220
|
+
if (node.type !== 'Literal' || 'regex' in node || 'bigint' in node)
|
|
221
|
+
return false;
|
|
222
|
+
const value = node.value;
|
|
223
|
+
return (value === null ||
|
|
224
|
+
typeof value === 'string' ||
|
|
225
|
+
typeof value === 'number' ||
|
|
226
|
+
typeof value === 'boolean');
|
|
227
|
+
}
|
|
228
|
+
function pureDataObjectKey(node) {
|
|
229
|
+
if (!isJsxLikeNode(node))
|
|
230
|
+
return null;
|
|
231
|
+
if (node.type === 'Identifier' && typeof node.name === 'string')
|
|
232
|
+
return node.name;
|
|
233
|
+
if (node.type === 'Literal' && (typeof node.value === 'string' || typeof node.value === 'number'))
|
|
234
|
+
return String(node.value);
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
function isPureDataProperty(value, depth) {
|
|
238
|
+
if (!isJsxLikeNode(value) || value.type !== 'Property')
|
|
239
|
+
return false;
|
|
240
|
+
if (value.kind !== 'init' ||
|
|
241
|
+
value.method === true ||
|
|
242
|
+
value.computed === true ||
|
|
243
|
+
value.shorthand === true)
|
|
244
|
+
return false;
|
|
245
|
+
const key = pureDataObjectKey(value.key);
|
|
246
|
+
if (key === null || UNSAFE_OBJECT_KEYS.has(key))
|
|
247
|
+
return false;
|
|
248
|
+
return isPureDataExpression(value.value, depth);
|
|
249
|
+
}
|
|
250
|
+
export function isPureDataExpression(value, depth = 0) {
|
|
251
|
+
if (!isJsxLikeNode(value))
|
|
252
|
+
return false;
|
|
253
|
+
if (isPureDataLiteral(value))
|
|
254
|
+
return true;
|
|
255
|
+
if (value.type === 'UnaryExpression') {
|
|
256
|
+
return (value.operator === '-' &&
|
|
257
|
+
isJsxLikeNode(value.argument) &&
|
|
258
|
+
value.argument.type === 'Literal' &&
|
|
259
|
+
typeof value.argument.value === 'number');
|
|
260
|
+
}
|
|
261
|
+
if (value.type === 'TemplateLiteral') {
|
|
262
|
+
return (Array.isArray(value.expressions) &&
|
|
263
|
+
value.expressions.length === 0 &&
|
|
264
|
+
Array.isArray(value.quasis));
|
|
265
|
+
}
|
|
266
|
+
if (depth >= MAX_PURE_DATA_DEPTH)
|
|
267
|
+
return false;
|
|
268
|
+
if (value.type === 'ArrayExpression') {
|
|
269
|
+
return (Array.isArray(value.elements) &&
|
|
270
|
+
value.elements.every((element) => isPureDataExpression(element, depth + 1)));
|
|
271
|
+
}
|
|
272
|
+
if (value.type === 'ObjectExpression') {
|
|
273
|
+
return (Array.isArray(value.properties) &&
|
|
274
|
+
value.properties.every((property) => isPureDataProperty(property, depth + 1)));
|
|
275
|
+
}
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
export function isPureDataProgram(estree) {
|
|
279
|
+
const stmt = estree.body[0];
|
|
280
|
+
if (estree.body.length !== 1 || (stmt === null || stmt === void 0 ? void 0 : stmt.type) !== 'ExpressionStatement')
|
|
281
|
+
return false;
|
|
282
|
+
return isPureDataExpression(stmt.expression);
|
|
283
|
+
}
|
|
214
284
|
function isPrimitiveLiteralExpression(node) {
|
|
215
285
|
if (node.type === 'Literal')
|
|
216
286
|
return true;
|
|
@@ -230,9 +300,7 @@ function isSafeJsxAttributeValue(value) {
|
|
|
230
300
|
return true;
|
|
231
301
|
if (node.type !== 'JSXExpressionContainer')
|
|
232
302
|
return false;
|
|
233
|
-
|
|
234
|
-
return false;
|
|
235
|
-
return isPrimitiveLiteralExpression(node.expression);
|
|
303
|
+
return isPureDataExpression(node.expression);
|
|
236
304
|
}
|
|
237
305
|
const DANGEROUS_ELEMENT_NAMES = new Set(['script', 'style', 'iframe', 'meta']);
|
|
238
306
|
function isSafeJsxElementName(name) {
|
|
@@ -246,6 +314,9 @@ function isSafeJsxElementName(name) {
|
|
|
246
314
|
return false;
|
|
247
315
|
return !DANGEROUS_ELEMENT_NAMES.has(elementName.toLowerCase());
|
|
248
316
|
}
|
|
317
|
+
export function isUnsafeDataAttributeName(name) {
|
|
318
|
+
return name === 'dangerouslySetInnerHTML' || /^on[A-Z]/.test(name);
|
|
319
|
+
}
|
|
249
320
|
function isEventHandlerAttribute(attributeNode) {
|
|
250
321
|
const name = attributeNode.name;
|
|
251
322
|
if (typeof name !== 'object' || name == null)
|
|
@@ -253,7 +324,7 @@ function isEventHandlerAttribute(attributeNode) {
|
|
|
253
324
|
const nameNode = name;
|
|
254
325
|
if (typeof nameNode.name !== 'string')
|
|
255
326
|
return false;
|
|
256
|
-
return
|
|
327
|
+
return isUnsafeDataAttributeName(nameNode.name);
|
|
257
328
|
}
|
|
258
329
|
function isSafeStaticJsxNode(node) {
|
|
259
330
|
if (node.type === 'JSXText')
|
|
@@ -463,14 +534,6 @@ function buildStubEsmNode(names) {
|
|
|
463
534
|
},
|
|
464
535
|
};
|
|
465
536
|
}
|
|
466
|
-
function isArrayOfStringLiterals(estree) {
|
|
467
|
-
const stmt = estree.body[0];
|
|
468
|
-
if (estree.body.length !== 1 || (stmt === null || stmt === void 0 ? void 0 : stmt.type) !== 'ExpressionStatement')
|
|
469
|
-
return false;
|
|
470
|
-
if (stmt.expression.type !== 'ArrayExpression')
|
|
471
|
-
return false;
|
|
472
|
-
return stmt.expression.elements.every((el) => (el === null || el === void 0 ? void 0 : el.type) === 'Literal' && typeof el.value === 'string');
|
|
473
|
-
}
|
|
474
537
|
export function remarkMdxRemoveJs() {
|
|
475
538
|
return (tree) => {
|
|
476
539
|
remove(tree, ['mdxTextExpression', 'mdxFlowExpression']);
|
|
@@ -505,7 +568,9 @@ export function remarkMdxRemoveJs() {
|
|
|
505
568
|
stubbedNamesMap.set(ident, { name: ident, isFunction: false });
|
|
506
569
|
return attr;
|
|
507
570
|
}
|
|
508
|
-
if ((
|
|
571
|
+
if (!isUnsafeDataAttributeName(attr.name) &&
|
|
572
|
+
((_b = attr.value.data) === null || _b === void 0 ? void 0 : _b.estree) &&
|
|
573
|
+
isPureDataProgram(attr.value.data.estree))
|
|
509
574
|
return attr;
|
|
510
575
|
if (isSafeStaticJsx((_c = attr.value.data) === null || _c === void 0 ? void 0 : _c.estree))
|
|
511
576
|
return attr;
|