GRAYBYTE WORDPRESS FILE MANAGER7982

Server IP : 198.54.121.189 / Your IP : 216.73.216.112
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /home/giriqfky/universaltoursandtravels.co.in/wp-content/plugins/sucuri-scanner/src/
Upload Files :
Current_dir [ Writeable ] Document_root [ Writeable ]

Command :


Current File : /home/giriqfky/universaltoursandtravels.co.in/wp-content/plugins/sucuri-scanner/src//csp.lib.php
<?php
/**
 * Code related to the Content Security Policy (CSP) headers settings.
 *
 * PHP version 5
 *
 * @category   Library
 * @package    Sucuri
 * @subpackage SucuriScanner
 */

if (!defined('SUCURISCAN_INIT') || SUCURISCAN_INIT !== true) {
    if (!headers_sent()) {
        /* Report invalid access if possible. */
        header('HTTP/1.1 403 Forbidden');
    }
    exit(1);
}

/**
 * Content Security Policy (CSP) headers library.
 *
 * This class is responsible for setting the CSP headers based on the user's settings.
 *
 * @category   Library
 * @package    Sucuri
 * @subpackage SucuriScanner
 */
class SucuriScanCSPHeaders extends SucuriScan
{
    /**
     * Basic sanitization for CSP directive values.
     *
     * @param string $input Raw input value.
     *
     * @return string Sanitized value
     */
    public static function sanitize_csp_directive($input)
    {
        // Allow letters, numbers, spaces, hyphens, single quotes, colons, semicolons, slashes, dots, and asterisks
        return preg_replace("/[^a-zA-Z0-9\s\-\'\:;\/\.\*]/", '', $input);
    }

    /**
     * Sets the CSP headers based on the user's settings.
     *
     * @return void
     */
    public function setCSPHeaders()
    {
        if (headers_sent()) {
            // Headers are already sent; nothing to do here.
            return;
        }

        $cspMode = SucuriScanOption::getOption(':headers_csp');
        if ($cspMode === 'disabled') {
            return;
        }

        $cspOptions = SucuriScanOption::getOption(':headers_csp_options');
        if (!is_array($cspOptions)) {
            $cspOptions = array();
        }

        $cspDirectives = array();

        foreach ($cspOptions as $directive => $option) {
            // If the directive is not enforced, skip
            if (!isset($option['enforced']) || !$option['enforced']) {
                continue;
            }

            $value = $this->collectDirectiveValue($option);

            if (empty($value)) {
                continue;
            }

            $normalizedDirective = str_replace('_', '-', $directive);
            $allowedDirective = $this->getValidDirectiveOrFalse($normalizedDirective);

            if (!$allowedDirective) {
                error_log("Invalid CSP directive: $normalizedDirective");
                continue;
            }

            $sanitizedValue = $this->sanitizeDirectiveValue($allowedDirective, $value);

            if (!$sanitizedValue) {
                error_log("Invalid value for CSP directive: $normalizedDirective => $value");
                continue;
            }

            // For upgrade-insecure-requests, there's no trailing value
            if ($allowedDirective === 'upgrade-insecure-requests') {
                $cspDirectives[] = $allowedDirective;
            } else {
                $cspDirectives[] = $allowedDirective . ' ' . $sanitizedValue;
            }
        }

        if (empty($cspDirectives)) {
            return;
        }

        $cspHeaderValue = implode('; ', $cspDirectives);

        // Validate the final CSP header value
        if (preg_match('/^[a-zA-Z0-9\-\'\:;\/\.\*\s]+$/', $cspHeaderValue)) {
            header('Content-Security-Policy-Report-Only: ' . $cspHeaderValue);
            return;
        }

        error_log("Invalid CSP header value: $cspHeaderValue");
    }

    /**
     * Returns a valid CSP directive name if recognized, or false if not recognized.
     *
     * @param string $directive The normalized directive name (e.g. 'child-src').
     *
     * @return string|false
     */
    protected function getValidDirectiveOrFalse($directive)
    {
        $allowedDirectives = array(
            'base-uri',
            'child-src',
            'connect-src',
            'default-src',
            'font-src',
            'form-action',
            'frame-ancestors',
            'frame-src',
            'img-src',
            'manifest-src',
            'media-src',
            'navigate-to',
            'object-src',
            'prefetch-src',
            'report-uri',
            'report-to',
            'require-trusted-types-for',
            'sandbox',
            'script-src',
            'script-src-attr',
            'script-src-elem',
            'style-src',
            'style-src-attr',
            'style-src-elem',
            'trusted-types',
            'upgrade-insecure-requests',
            'worker-src'
        );

        return in_array($directive, $allowedDirectives) ? $directive : false;
    }

    /**
     * Validates and sanitizes the value for a given directive according to CSP rules.
     *
     * @param string $directive The CSP directive (e.g. 'sandbox', 'script-src').
     * @param string $value The raw user input or combined multi_checkbox tokens.
     *
     * @return string|false A sanitized value string if valid, false otherwise.
     */
    protected function sanitizeDirectiveValue($directive, $value)
    {
        if ($directive === 'upgrade-insecure-requests') {
            return $this->sanitizeUpgradeInsecureRequests($value);
        }

        if ($directive === 'sandbox') {
            return $this->sanitizeSandboxTokens($value);
        }

        if ($directive === 'report-uri' || $directive === 'report-to') {
            return $this->sanitizeReportUriOrTo($value);
        }

        return $this->sanitizeSourceListDirective($value);
    }

    /**
     * Handle the upgrade-insecure-requests directive.
     *
     * @param string $value
     *
     * @return string|false
     */
    protected function sanitizeUpgradeInsecureRequests($value)
    {
        $val = trim(self::sanitize_csp_directive($value));

        return ($val === 'upgrade-insecure-requests') ? 'upgrade-insecure-requests' : false;
    }

    /**
     * Handle the sandbox directive, expecting a set of allowed tokens or empty.
     *
     * @param string $value Space-separated tokens (e.g. "allow-downloads allow-forms").
     *
     * @return string
     */
    protected function sanitizeSandboxTokens($value)
    {
        $sandboxTokens = array(
            'allow-downloads',
            'allow-forms',
            'allow-modals',
            'allow-orientation-lock',
            'allow-pointer-lock',
            'allow-popups',
            'allow-popups-to-escape-sandbox',
            'allow-presentation',
            'allow-same-origin',
            'allow-scripts',
            'allow-top-navigation'
        );

        $tokens = preg_split('/\s+/', $value, -1, PREG_SPLIT_NO_EMPTY);
        $finalTokens = array();

        foreach ($tokens as $t) {
            $t = self::sanitize_csp_directive($t);

            if (in_array($t, $sandboxTokens, true)) {
                $finalTokens[] = $t;
            }
        }

        return empty($finalTokens) ? 'sandbox' : implode(' ', $finalTokens);
    }

    /**
     * Handle the report-uri and report-to directives, expecting a valid URL or scheme.
     *
     * @param string $value Raw input value (e.g. "https://example.com/report").
     *
     * @return string|false
     */
    protected function sanitizeReportUriOrTo($value)
    {
        $val = self::sanitize_csp_directive($value);

        if (preg_match('#^(https?:)#i', $val) && filter_var($val, FILTER_VALIDATE_URL)) {
            return $val;
        }

        return false;
    }

    /**
     * Handle generic source-list directives (e.g. default-src, script-src).
     * These can have keywords, schemes, or host sources.
     *
     * @param string $value A space-separated list (e.g. "'self' https://example.com").
     *
     * @return string|false Sanitized list if valid, false if something doesn't match.
     */
    protected function sanitizeSourceListDirective($value)
    {
        $allowedKeywords = array(
            "'self'",
            "'none'",
            "'unsafe-inline'",
            "'unsafe-eval'",
            "'strict-dynamic'",
            "'unsafe-hashed-attributes'",
            "'report-sample'"
        );

        $tokens = preg_split('/\s+/', $value, -1, PREG_SPLIT_NO_EMPTY);
        $finalTokens = array();

        foreach ($tokens as $token) {
            $t = self::sanitize_csp_directive($token);

            if (in_array($t, $allowedKeywords, true) ||
                preg_match('#^(https?:|data:|blob:|mediastream:|filesystem:)#i', $t) ||
                $t === '*' ||
                $this->isValidHostSource($t)) {
                $finalTokens[] = $t;
                continue;
            }

            return false;
        }

        return empty($finalTokens) ? false : implode(' ', $finalTokens);
    }

    /**
     * Checks if a token can be considered a valid host source.
     * A host source can be something like:
     * - example.com
     * - sub.example.com
     * - example.com:8080
     * - *.example.com
     *
     * @param string $source The token to check.
     *
     * @return bool True if valid, false otherwise.
     */
    protected function isValidHostSource($source)
    {
        $pattern = '/^(\*\.)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*(?::[0-9]+)?$/';
        return (bool)preg_match($pattern, $source);
    }

    /**
     * Collects a string representing the directive value:
     * If it's a normal text directive, use 'value' directly;
     * if it's a multi_checkbox directive, gather sub-options that are enforced.
     *
     * @param array $option Directive config array (type, value, options, enforced, etc.).
     *
     * @return string A space-separated list if multi_checkbox, or the text value otherwise.
     */
    protected function collectDirectiveValue($option)
    {
        if (isset($option['type']) && $option['type'] === 'multi_checkbox') {
            if (!isset($option['options']) || !is_array($option['options'])) {
                return '';
            }

            $subTokens = array();

            foreach ($option['options'] as $token => $tokenObj) {
                if ($tokenObj['enforced']) {
                    $subTokens[] = $token;
                }
            }

            return implode(' ', $subTokens);
        }

        if (isset($option['value']) && is_string($option['value'])) {
            return trim($option['value']);
        }

        return '';
    }
}

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
July 01 2025 09:32:24
giriqfky / giriqfky
0755
api.lib.php
52.461 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
auditlogs.lib.php
13.951 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
base.lib.php
27.88 KB
February 12 2025 21:16:24
giriqfky / giriqfky
0644
cache.lib.php
16.152 KB
June 08 2022 20:57:14
giriqfky / giriqfky
0644
cachecontrol.lib.php
9.314 KB
February 12 2025 21:16:24
giriqfky / giriqfky
0644
cli.lib.php
4.798 KB
December 12 2018 04:56:40
giriqfky / giriqfky
0644
command.lib.php
6.192 KB
July 03 2018 22:25:46
giriqfky / giriqfky
0644
cors.lib.php
7.196 KB
January 22 2025 20:27:10
giriqfky / giriqfky
0644
cron.lib.php
1.805 KB
July 01 2022 20:48:54
giriqfky / giriqfky
0644
csp.lib.php
10.026 KB
January 22 2025 20:27:10
giriqfky / giriqfky
0644
event.lib.php
32.171 KB
April 17 2025 21:30:12
giriqfky / giriqfky
0644
fileinfo.lib.php
14.978 KB
February 21 2019 02:10:38
giriqfky / giriqfky
0644
firewall.lib.php
25.744 KB
August 05 2022 12:37:34
giriqfky / giriqfky
0644
fsscanner.lib.php
4.199 KB
May 22 2018 23:44:42
giriqfky / giriqfky
0644
globals.php
8.83 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
hardening.lib.php
18.502 KB
February 12 2025 21:16:24
giriqfky / giriqfky
0644
hook.lib.php
38.228 KB
September 08 2022 20:53:50
giriqfky / giriqfky
0644
index.html
0.037 KB
June 26 2017 22:22:12
giriqfky / giriqfky
0644
installer-skin-legacy.lib.php
1.579 KB
July 26 2021 23:24:36
giriqfky / giriqfky
0644
installer-skin.lib.php
2.352 KB
July 26 2021 23:24:36
giriqfky / giriqfky
0644
integrity.lib.php
28.869 KB
August 26 2024 16:29:56
giriqfky / giriqfky
0644
interface.lib.php
12.518 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
lastlogins-failed.php
14.315 KB
November 26 2019 03:09:50
giriqfky / giriqfky
0644
lastlogins-loggedin.php
7.799 KB
March 21 2024 02:14:38
giriqfky / giriqfky
0644
lastlogins.php
16.158 KB
December 14 2023 02:41:56
giriqfky / giriqfky
0644
mail.lib.php
9.767 KB
August 15 2024 20:16:00
giriqfky / giriqfky
0644
option.lib.php
47.315 KB
January 22 2025 20:27:10
giriqfky / giriqfky
0644
pagehandler.php
11.151 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
request.lib.php
4.396 KB
March 17 2021 19:20:08
giriqfky / giriqfky
0644
settings-alerts.php
26.935 KB
August 15 2024 20:16:00
giriqfky / giriqfky
0644
settings-apiservice.php
6.386 KB
April 13 2023 15:12:38
giriqfky / giriqfky
0644
settings-general.php
22.646 KB
April 12 2023 12:24:48
giriqfky / giriqfky
0644
settings-hardening.php
35.405 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
settings-headers.php
16.343 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
settings-integrity.php
5.374 KB
February 21 2019 02:10:38
giriqfky / giriqfky
0644
settings-posthack.php
21.594 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
settings-scanner.php
9.694 KB
February 18 2020 01:58:10
giriqfky / giriqfky
0644
settings-webinfo.php
5.546 KB
November 26 2019 03:09:50
giriqfky / giriqfky
0644
settings.php
0.925 KB
May 22 2018 23:44:42
giriqfky / giriqfky
0644
sitecheck.lib.php
19.209 KB
December 12 2022 20:45:18
giriqfky / giriqfky
0644
strings.php
49.83 KB
January 22 2025 20:27:10
giriqfky / giriqfky
0644
template.lib.php
18.983 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
vulnerability.lib.php
4.748 KB
April 28 2025 20:34:18
giriqfky / giriqfky
0644
wordpress-recommendations.lib.php
10.9 KB
November 26 2019 03:09:50
giriqfky / giriqfky
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF