Improved link validation and sanatization, in order to mitigate CVE-2025-56200 from validator.js NPM package.
This commit is contained in:
parent
6bab5b4723
commit
06f552a9ec
9 changed files with 38 additions and 19 deletions
|
|
@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
//NPM Imports
|
||||
//const url = require("node:url");
|
||||
const validator = require('validator');//No express here, so regular validator it is!
|
||||
const {sanitizeUrl} = require("@braintree/sanitize-url");
|
||||
|
||||
//local import
|
||||
const iaUtil = require('./internetArchiveUtils');
|
||||
|
|
@ -96,12 +97,15 @@ module.exports.refreshRawLink = async function(mediaObj){
|
|||
* Still this has some improvements like url pre-checks and the fact that it's handled serverside, recuing possibility of bad requests.
|
||||
* Some of the regex expressions for certain services have also been improved, such as youtube, and the fore.st-unique archive.org
|
||||
*
|
||||
* @param {String} url - URL to determine media type of
|
||||
* @param {String} dirtyURL - URL to determine media type of
|
||||
* @returns {Object} containing URL type and clipped ID string
|
||||
*/
|
||||
module.exports.getMediaType = async function(url){
|
||||
module.exports.getMediaType = async function(dirtyURL){
|
||||
//Sanatize our URL
|
||||
const url = sanitizeUrl(dirtyURL);
|
||||
|
||||
//Check if we have a valid url, encode it on the fly in case it's too humie-friendly
|
||||
if(!validator.isURL(encodeURI(url))){
|
||||
if(!validator.isURL(encodeURI(url,{require_valid_protocol: true}))){
|
||||
//If not toss the fucker out
|
||||
return {
|
||||
type: null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue