Skip to content

Commit 01bd68d

Browse files
authored
Merge pull request #288 from easyops-cn/steve/fix-version
fix: refine version in search page
2 parents 5c934cd + 6d091b7 commit 01bd68d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docusaurus-search-local/src/client/theme/SearchBar/fetchIndexes.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ export async function legacyFetchIndexes(
3838
searchContext: string
3939
): Promise<IndexesData> {
4040
if (process.env.NODE_ENV === "production") {
41+
const url = `${baseUrl}${searchIndexUrl.replace(
42+
"{dir}",
43+
searchContext ? `-${searchContext.replace(/\//g, "-")}` : ""
44+
)}`;
45+
46+
// Catch potential attacks.
47+
const fullUrl = new URL(url, location.origin);
48+
if (fullUrl.origin !== location.origin) {
49+
throw new Error("Unexpected version url");
50+
}
51+
4152
const json = (await (
42-
await fetch(
43-
`${baseUrl}${searchIndexUrl.replace(
44-
"{dir}",
45-
searchContext ? `-${searchContext.replace(/\//g, "-")}` : ""
46-
)}`
47-
)
53+
await fetch(url)
4854
).json()) as SerializedIndex[];
4955

5056
const wrappedIndexes: WrappedIndex[] = json.map(

0 commit comments

Comments
 (0)