Skip to content

Commit 8905ece

Browse files
committed
fix(missingModelDownload): reject mirror URLs with query or fragment
1 parent c352eec commit 8905ece

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/platform/missingModel/missingModelDownload.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,24 @@ describe('resolveHuggingFaceUrl', () => {
788788
expect(consoleWarn).toHaveBeenCalled()
789789
})
790790

791+
it('ignores a mirror with a query component', () => {
792+
mockHuggingFaceMirror.value = 'https://hf-mirror.com?token=abc'
793+
const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => {})
794+
expect(
795+
resolveHuggingFaceUrl('https://huggingface.co/org/model/resolve/main/x')
796+
).toBe('https://huggingface.co/org/model/resolve/main/x')
797+
expect(consoleWarn).toHaveBeenCalled()
798+
})
799+
800+
it('ignores a mirror with a fragment component', () => {
801+
mockHuggingFaceMirror.value = 'https://hf-mirror.com#section'
802+
const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => {})
803+
expect(
804+
resolveHuggingFaceUrl('https://huggingface.co/org/model/resolve/main/x')
805+
).toBe('https://huggingface.co/org/model/resolve/main/x')
806+
expect(consoleWarn).toHaveBeenCalled()
807+
})
808+
791809
it('leaves non-HuggingFace URLs untouched', () => {
792810
mockHuggingFaceMirror.value = 'https://hf-mirror.com'
793811
expect(

src/platform/missingModel/missingModelDownload.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ export const HUGGINGFACE_MIRROR_SETTING_ID =
4646
* users behind networks blocking `huggingface.co` can still use the
4747
* "Download All missing models" button. Empty/missing setting returns
4848
* the URL unchanged. Non-HuggingFace URLs are returned unchanged.
49-
* Mirrors that are not absolute http(s) URLs are ignored and warned
50-
* about, to avoid producing broken download URLs.
49+
* Mirrors that are not absolute http(s) URLs, or that carry a query
50+
* or fragment component, are ignored and warned about, to avoid
51+
* producing broken download URLs.
5152
*/
5253
export function resolveHuggingFaceUrl(url: string): string {
5354
const mirror = useSettingStore()
@@ -64,6 +65,12 @@ export function resolveHuggingFaceUrl(url: string): string {
6465
)
6566
return url
6667
}
68+
if (parsed.search || parsed.hash) {
69+
console.warn(
70+
`[missingModelDownload] Ignoring ${HUGGINGFACE_MIRROR_SETTING_ID}: mirror must not include a query or fragment`
71+
)
72+
return url
73+
}
6774
return url.replace('https://huggingface.co', mirror)
6875
} catch {
6976
console.warn(

0 commit comments

Comments
 (0)