Skip to content

Commit 1f67e8d

Browse files
committed
Prevent logging of potentially sensitive data in url validator
1 parent 85be24d commit 1f67e8d

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/validators.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ const isFQDN = (input: string) => {
1616

1717
// "best effort" regex-based IP address check
1818
// If you want a more exhaustive check, create your own custom validator
19-
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}$/
20-
const ipv6Regex = /^(([0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|([0-9a-f]{1,4}:)+:([0-9a-f]{1,4}:)*[0-9a-f]{1,4}|([0-9a-f]{1,4}:)*::([0-9a-f]{1,4}:)*[0-9a-f]{0,4}|::|(([0-9a-f]{1,4}:){1,6}|:):((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]))(%[0-9a-z.\-:]+)?$/i
19+
const ipv4Regex =
20+
/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}$/
21+
const ipv6Regex =
22+
/^(([0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|([0-9a-f]{1,4}:)+:([0-9a-f]{1,4}:)*[0-9a-f]{1,4}|([0-9a-f]{1,4}:)*::([0-9a-f]{1,4}:)*[0-9a-f]{0,4}|::|(([0-9a-f]{1,4}:){1,6}|:):((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]))(%[0-9a-z.\-:]+)?$/i
2123

2224
const isIP = (input: string) => {
2325
if (!input.length) return false
@@ -90,8 +92,9 @@ export const url = makeValidator<string>((x: string) => {
9092
try {
9193
new URL(x)
9294
return x
93-
} catch (e) {
94-
throw new EnvError(`Invalid url: "${x}"`)
95+
} catch {
96+
// Not logging the url value as it could contain sensitive data
97+
throw new EnvError(`Invalid url`)
9598
}
9699
})
97100

0 commit comments

Comments
 (0)