@mintlify/common 1.0.658 → 1.0.660
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/asyncapi/checkForExternalRefs.d.ts +11 -0
- package/dist/asyncapi/checkForExternalRefs.js +67 -0
- package/dist/asyncapi/validateAsyncApi.js +3 -0
- package/dist/divisions/generatePathToHiddenDict.d.ts +10 -0
- package/dist/divisions/generatePathToHiddenDict.js +53 -0
- package/dist/divisions/index.d.ts +1 -0
- package/dist/divisions/index.js +1 -0
- package/dist/openapi/validate.js +9 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class ExternalRefError extends Error {
|
|
2
|
+
readonly refs: Array<{
|
|
3
|
+
path: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}>;
|
|
6
|
+
constructor(message: string, refs: Array<{
|
|
7
|
+
path: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}>);
|
|
10
|
+
}
|
|
11
|
+
export declare function checkForExternalRefs(input: unknown): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import yaml from 'js-yaml';
|
|
2
|
+
export class ExternalRefError extends Error {
|
|
3
|
+
constructor(message, refs) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.refs = refs;
|
|
6
|
+
this.name = 'ExternalRefError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function tryParse(value) {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(value);
|
|
12
|
+
}
|
|
13
|
+
catch (_a) {
|
|
14
|
+
try {
|
|
15
|
+
const result = yaml.load(value);
|
|
16
|
+
return typeof result === 'object' ? result : null;
|
|
17
|
+
}
|
|
18
|
+
catch (_b) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function validateParseable(input) {
|
|
24
|
+
try {
|
|
25
|
+
JSON.parse(input);
|
|
26
|
+
}
|
|
27
|
+
catch (_a) {
|
|
28
|
+
yaml.load(input);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function findExternalRefs(input, path = '', refs = [], visited = new WeakSet()) {
|
|
32
|
+
if (typeof input === 'string') {
|
|
33
|
+
const parsed = tryParse(input);
|
|
34
|
+
if (parsed)
|
|
35
|
+
findExternalRefs(parsed, path, refs, visited);
|
|
36
|
+
return refs;
|
|
37
|
+
}
|
|
38
|
+
if (!input || typeof input !== 'object' || visited.has(input))
|
|
39
|
+
return refs;
|
|
40
|
+
visited.add(input);
|
|
41
|
+
if (Array.isArray(input)) {
|
|
42
|
+
input.forEach((item, i) => findExternalRefs(item, `${path}[${i}]`, refs, visited));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
for (const [key, value] of Object.entries(input)) {
|
|
46
|
+
const newPath = path ? `${path}.${key}` : key;
|
|
47
|
+
if (key === '$ref' && typeof value === 'string' && !value.startsWith('#')) {
|
|
48
|
+
refs.push({ path: newPath, value });
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
findExternalRefs(value, newPath, refs, visited);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return refs;
|
|
56
|
+
}
|
|
57
|
+
export function checkForExternalRefs(input) {
|
|
58
|
+
if (input == null || (typeof input !== 'string' && typeof input !== 'object'))
|
|
59
|
+
return;
|
|
60
|
+
if (typeof input === 'string')
|
|
61
|
+
validateParseable(input);
|
|
62
|
+
const refs = findExternalRefs(input);
|
|
63
|
+
if (refs.length > 0) {
|
|
64
|
+
const details = refs.map((r) => ` - ${r.path}: ${r.value}`).join('\n');
|
|
65
|
+
throw new ExternalRefError(`External $ref references are not allowed. Found ${refs.length} external reference(s):\n${details}`, refs);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -8,9 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Parser } from '@asyncapi/parser';
|
|
11
|
+
import { checkForExternalRefs } from './checkForExternalRefs.js';
|
|
11
12
|
export function validateAsyncApi(str) {
|
|
12
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
14
|
try {
|
|
15
|
+
// Throws error if external $ref is found
|
|
16
|
+
checkForExternalRefs(str);
|
|
14
17
|
const parser = new Parser();
|
|
15
18
|
const { document, diagnostics } = yield parser.parse(str);
|
|
16
19
|
if (diagnostics.length > 0) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DecoratedNavigationConfig } from '@mintlify/validation';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a map from page paths to their hidden status based on navigation hierarchy.
|
|
4
|
+
* A page is hidden if:
|
|
5
|
+
* - It has noindex: true in its frontmatter, OR
|
|
6
|
+
* - Any parent group/division has hidden: true
|
|
7
|
+
* Assumes page hrefs in navWithPageContext have a leading / but config page paths do not.
|
|
8
|
+
* Outputted dictionary will NOT have a leading / in the dictionary keys.
|
|
9
|
+
*/
|
|
10
|
+
export declare function generatePathToHiddenDict(decoratedNav: DecoratedNavigationConfig): Map<string, boolean>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { divisions } from '@mintlify/validation';
|
|
2
|
+
import { isPage } from '../navigation/isPage.js';
|
|
3
|
+
import { optionallyRemoveLeadingSlash } from '../optionallyRemoveLeadingSlash.js';
|
|
4
|
+
/**
|
|
5
|
+
* Generates a map from page paths to their hidden status based on navigation hierarchy.
|
|
6
|
+
* A page is hidden if:
|
|
7
|
+
* - It has noindex: true in its frontmatter, OR
|
|
8
|
+
* - Any parent group/division has hidden: true
|
|
9
|
+
* Assumes page hrefs in navWithPageContext have a leading / but config page paths do not.
|
|
10
|
+
* Outputted dictionary will NOT have a leading / in the dictionary keys.
|
|
11
|
+
*/
|
|
12
|
+
export function generatePathToHiddenDict(decoratedNav) {
|
|
13
|
+
const pathToHiddenDict = new Map();
|
|
14
|
+
generatePathToHiddenDictRecursive(pathToHiddenDict, decoratedNav, false);
|
|
15
|
+
return pathToHiddenDict;
|
|
16
|
+
}
|
|
17
|
+
function generatePathToHiddenDictRecursive(pathToHiddenDict, nav, parentHidden) {
|
|
18
|
+
if (typeof nav !== 'object')
|
|
19
|
+
return;
|
|
20
|
+
// Determine the effective hidden status for this level (from group/tab hidden property)
|
|
21
|
+
const effectiveHidden = 'hidden' in nav && typeof nav.hidden === 'boolean' ? nav.hidden : parentHidden;
|
|
22
|
+
if (isPage(nav)) {
|
|
23
|
+
const key = optionallyRemoveLeadingSlash(nav.href);
|
|
24
|
+
// A page is hidden if parent has hidden: true OR page has noindex: true in frontmatter
|
|
25
|
+
const pageNoindex = 'noindex' in nav && nav.noindex === true;
|
|
26
|
+
const isHidden = effectiveHidden || pageNoindex;
|
|
27
|
+
// Only add hidden pages to the dictionary (more efficient)
|
|
28
|
+
// We keep the first value encountered to handle duplicate paths
|
|
29
|
+
if (isHidden && !pathToHiddenDict.has(key)) {
|
|
30
|
+
pathToHiddenDict.set(key, true);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if ('pages' in nav) {
|
|
34
|
+
if ('root' in nav && typeof nav.root === 'object') {
|
|
35
|
+
generatePathToHiddenDictRecursive(pathToHiddenDict, nav.root, effectiveHidden);
|
|
36
|
+
}
|
|
37
|
+
for (const page of nav.pages) {
|
|
38
|
+
if (typeof page === 'object') {
|
|
39
|
+
generatePathToHiddenDictRecursive(pathToHiddenDict, page, effectiveHidden);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const key of ['groups', ...divisions]) {
|
|
44
|
+
if (key in nav) {
|
|
45
|
+
const items = nav[key];
|
|
46
|
+
if (Array.isArray(items)) {
|
|
47
|
+
for (const item of items) {
|
|
48
|
+
generatePathToHiddenDictRecursive(pathToHiddenDict, item, effectiveHidden);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/divisions/index.js
CHANGED
package/dist/openapi/validate.js
CHANGED
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { validate as scalarValidate } from '@mintlify/openapi-parser';
|
|
11
|
+
import { checkForExternalRefs } from '../asyncapi/checkForExternalRefs.js';
|
|
11
12
|
export const validate = (document) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
13
|
const result = yield safeValidate(document);
|
|
13
14
|
if ('errorMessage' in result) {
|
|
@@ -16,6 +17,14 @@ export const validate = (document) => __awaiter(void 0, void 0, void 0, function
|
|
|
16
17
|
return result;
|
|
17
18
|
});
|
|
18
19
|
export const safeValidate = (document) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
// Check for external $ref references before parsing to prevent SSRF
|
|
21
|
+
try {
|
|
22
|
+
checkForExternalRefs(document);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
26
|
+
return { errors: [{ message: errorMessage }], valid: false, errorMessage };
|
|
27
|
+
}
|
|
19
28
|
const result = yield scalarValidate(document);
|
|
20
29
|
const { errors, schema, valid, version } = result;
|
|
21
30
|
if (version === '2.0')
|