Skip to content

Commit

Permalink
fix: enforce relative url resolving (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Aug 3, 2024
1 parent b05b720 commit 4564518
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/runtime/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { basename } from 'pathe'
import { getIcons } from '@iconify/utils'
import { consola } from 'consola'
import { useAppConfig, defineCachedEventHandler } from 'nitropack/runtime'
import { createError } from 'h3'
import type { NuxtIconRuntimeOptions } from '../../schema-types'
import { collections } from '#nuxt-icon-server-bundle'

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

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

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

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

0 comments on commit 4564518

Please sign in to comment.