@usegraft/mdx-safety 0.2.0 → 1.0.0-beta.1
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/README.md +1 -1
- package/dist/index.js +13 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,4 +38,4 @@ This refuses _executable_ constructs. It is not a general HTML sanitiser. If you
|
|
|
38
38
|
|
|
39
39
|
---
|
|
40
40
|
|
|
41
|
-
MIT. [Repository](https://github.com/AndersonDesign1/graft) · [Changelog](https://github.com/AndersonDesign1/graft/blob/
|
|
41
|
+
MIT. [Repository](https://github.com/AndersonDesign1/graft) · [Changelog](https://github.com/AndersonDesign1/graft/blob/main/packages/mdx-safety/CHANGELOG.md) · [Security policy](https://github.com/AndersonDesign1/graft/blob/main/SECURITY.md)
|
package/dist/index.js
CHANGED
|
@@ -91,9 +91,20 @@ function findExecutableMdx(source) {
|
|
|
91
91
|
return found;
|
|
92
92
|
}
|
|
93
93
|
function assertSafeMdx(source, options = {}) {
|
|
94
|
-
const found = findExecutableMdx(source);
|
|
95
|
-
if (found.length === 0) return;
|
|
96
94
|
const where = options.label ? ` in ${options.label}` : "";
|
|
95
|
+
let found;
|
|
96
|
+
try {
|
|
97
|
+
found = findExecutableMdx(source);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (!(error instanceof UncheckableMdxError)) throw error;
|
|
100
|
+
throw new GraftError({
|
|
101
|
+
code: "INPUT_VALIDATION_FAILED",
|
|
102
|
+
message: `MDX could not be parsed${where}, so it cannot be checked for executable source \u2014 ${error.message}`,
|
|
103
|
+
fix: "Fix the MDX syntax and retry. Source the checker cannot read is refused rather than accepted, because the renderer's parser is not this one and the gap between them is exactly where executable source would sit.",
|
|
104
|
+
details: { label: options.label, reason: error.message }
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (found.length === 0) return;
|
|
97
108
|
const listed = found.slice(0, 5).map((node) => {
|
|
98
109
|
const line = node.line === void 0 ? "" : ` (line ${node.line})`;
|
|
99
110
|
const snippet = node.snippet === void 0 ? "" : `: ${node.snippet}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usegraft/mdx-safety",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "Refuse executable MDX before it is stored or rendered. MDX is code, and rendering evaluates it on the server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@usegraft/contracts": "0.
|
|
39
|
+
"@usegraft/contracts": "1.0.0-beta.1",
|
|
40
40
|
"remark-gfm": "^4.0.1",
|
|
41
41
|
"remark-mdx": "^3.1.1",
|
|
42
42
|
"remark-parse": "^11.0.0",
|