Skip to content

Commit 4564518

Browse files
authored
fix: enforce relative url resolving (#230)
1 parent b05b720 commit 4564518

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/runtime/server/api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { basename } from 'pathe'
22
import { getIcons } from '@iconify/utils'
33
import { consola } from 'consola'
44
import { useAppConfig, defineCachedEventHandler } from 'nitropack/runtime'
5+
import { createError } from 'h3'
56
import type { NuxtIconRuntimeOptions } from '../../schema-types'
67
import { collections } from '#nuxt-icon-server-bundle'
78

@@ -21,7 +22,7 @@ export default defineCachedEventHandler(async (ctx) => {
2122
: null
2223

2324
const apiEndPoint = options.iconifyApiEndpoint || DEFAULT_ENDPOINT
24-
const apiUrl = new URL(basename(url), apiEndPoint)
25+
const apiUrl = new URL('./' + basename(url), apiEndPoint)
2526
const icons = apiUrl.searchParams.get('icons')?.split(',')
2627

2728
if (collection) {
@@ -47,6 +48,9 @@ export default defineCachedEventHandler(async (ctx) => {
4748

4849
if (options.fallbackToApi) {
4950
consola.debug(`[Icon] fetching ${(icons || []).map(i => '`' + collectionName + ':' + i + '`').join(',')} from iconify api`)
51+
if (apiUrl.host !== new URL(apiEndPoint).host) {
52+
return createError({ status: 400, message: 'Invalid icon request' })
53+
}
5054
const data = await $fetch(apiUrl.href)
5155
return data
5256
}

0 commit comments

Comments
 (0)