Ignore:
Timestamp:
Mar 6, 2019 9:18:39 PM (5 years ago)
Author:
anonymous
Message:

Strip unsafe characters from HTTP_HOST

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r667 r670  
    13771377
    13781378    if (!isset($urls[$url])) {
    1379         if (!preg_match('|https?://[\w.]+/|', $url)) {
     1379        if (!preg_match('!^https?://!i', $url)) {
    13801380            // If we can't find a domain we assume the URL is local (i.e. "/my/url/path/" or "../img/file.jpg").
    13811381            $urls[$url] = true;
    13821382        } else {
    1383             $urls[$url] = preg_match('|https?://[\w.]*' . preg_quote(getenv('HTTP_HOST'), '|') . '|i', $url);
     1383            $urls[$url] = preg_match('!^https?://' . preg_quote(getenv('HTTP_HOST'), '!') . '!i', $url);
    13841384        }
    13851385    }
     
    14051405function absoluteMe()
    14061406{
    1407     return sprintf('%s://%s%s', (getenv('HTTPS') ? 'https' : 'http'), getenv('HTTP_HOST'), getenv('REQUEST_URI'));
     1407    $safe_http_host = preg_replace('/[^a-z\d.-]/', '', getenv('HTTP_HOST'));
     1408    return sprintf('%s://%s%s', (getenv('HTTPS') ? 'https' : 'http'), $safe_http_host, getenv('REQUEST_URI'));
    14081409}
    14091410
Note: See TracChangeset for help on using the changeset viewer.