Skip to content

Commit

Permalink
fix: ignore *.ipv4 address in cert (vitejs#19416)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Feb 13, 2025
1 parent 0f058a9 commit 973283b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/vite/src/node/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ describe('extractHostnamesFromSubjectAltName', () => {
['DNS:localhost, DNS:foo.localhost', ['localhost', 'foo.localhost']],
['DNS:*.localhost', ['vite.localhost']],
['DNS:[::1]', []], // [::1] is skipped
['DNS:*.192.168.0.152, DNS:192.168.0.152', ['192.168.0.152']], // *.192.168.0.152 is skipped
['othername:"foo,bar", DNS:localhost', ['localhost']], // handle quoted correctly
] as const

Expand Down
10 changes: 8 additions & 2 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'node:fs'
import os from 'node:os'
import net from 'node:net'
import path from 'node:path'
import { exec } from 'node:child_process'
import crypto from 'node:crypto'
Expand Down Expand Up @@ -1083,8 +1084,13 @@ export function extractHostnamesFromSubjectAltName(
}
remaining = remaining.slice(/* for , */ 1).trimStart()

// [::1] might be included but skip it as it's already included as a local address
if (name === 'DNS' && value !== '[::1]') {
if (
name === 'DNS' &&
// [::1] might be included but skip it as it's already included as a local address
value !== '[::1]' &&
// skip *.IPv4 addresses, which is invalid
!(value.startsWith('*.') && net.isIPv4(value.slice(2)))
) {
hostnames.push(value.replace('*', 'vite'))
}
}
Expand Down

0 comments on commit 973283b

Please sign in to comment.