Commit c038c120 authored by Patrick Schmalstig's avatar Patrick Schmalstig
Browse files

Implemented MANTIS-6008 (Convert _url_to_filename to using a base64 salted sha256)

parent 73bdcbd6
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -234,6 +234,8 @@ function _build_keep_post_fields(array $exclude = [], bool $force_everything = f
 */
function _url_to_filename(string $url_full) : string
{
    // We don't need this anymore since we are hashing
    /*
    $bad_chars = ['!', '/', '\\', '?', '*', '<', '>', '|', '"', ':', '%', '!', ';', '~', ' '];
    $new_name = $url_full;
    foreach ($bad_chars as $bad_char) {
@@ -243,12 +245,17 @@ function _url_to_filename(string $url_full) : string
        }
        $new_name = str_replace($bad_char, $good_char, $new_name);
    }
    */

    require_code('crypt');
    $_new_name = hash_hmac('sha256', $url_full, get_site_salt(), true);
    $new_name = str_replace(['+','/','='], ['-','_',''], base64_encode($_new_name));

    if (strpos($new_name, '.') === false) {
        return md5($new_name);
    if (strpos($new_name, '.') !== false) {
        $new_name .= '.' . get_file_extension($url_full);
    }

    return md5($new_name) . '.' . get_file_extension($new_name);
    return $new_name;
}

/**