Skip to content

Commit

Permalink
⚠️ Solve security problems #84
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed May 2, 2024
1 parent 25968fc commit 04f1a73
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions source/utils/miscUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,12 @@ const currencyFormatter = (number, digits) => {
* is a valid URL, and `false` otherwise.
*/
const validateURL = (string) => {
const pattern = new RegExp(
'^' + // Start of the line
'(https?:\\/\\/)?' + // Protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // Domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // Port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // Query string
'(\\#[-a-z\\d_]*)?' + // Fragment locator
'$', // End of the line.
'i'
)

return !!pattern.test(string)
try {
const newURL = new URL(string)
return newURL.protocol === 'http:' || newURL.protocol === 'https:'
} catch (error) {
return false
}
}

/**
Expand Down

0 comments on commit 04f1a73

Please sign in to comment.