summaryrefslogtreecommitdiffstats
path: root/lib/private/request.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/request.php')
-rwxr-xr-xlib/private/request.php73
1 files changed, 31 insertions, 42 deletions
diff --git a/lib/private/request.php b/lib/private/request.php
index 0fd20b3cc1f..14f3bf2cbb7 100755
--- a/lib/private/request.php
+++ b/lib/private/request.php
@@ -25,6 +25,16 @@ class OC_Request {
}
/**
+ * @brief Checks whether a domain is considered as trusted. This is used to prevent Host Header Poisoning.
+ * @param string $host
+ * @return bool
+ */
+ public static function isTrustedDomain($domain) {
+ $trustedList = \OC_Config::getValue('trusted_domains', array(''));
+ return in_array($domain, $trustedList);
+ }
+
+ /**
* @brief Returns the server host
* @returns string the server host
*
@@ -43,21 +53,27 @@ class OC_Request {
$host = trim(array_pop(explode(",", $_SERVER['HTTP_X_FORWARDED_HOST'])));
}
else{
- $host=$_SERVER['HTTP_X_FORWARDED_HOST'];
+ $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
- }
- else{
+ } else {
if (isset($_SERVER['HTTP_HOST'])) {
- return $_SERVER['HTTP_HOST'];
+ $host = $_SERVER['HTTP_HOST'];
}
if (isset($_SERVER['SERVER_NAME'])) {
- return $_SERVER['SERVER_NAME'];
+ $host = $_SERVER['SERVER_NAME'];
}
- return 'localhost';
}
- return $host;
- }
+ // Verify that the host is a trusted domain if the trusted domains
+ // are defined
+ // If no trusted domain is provided the first trusted domain is returned
+ if(self::isTrustedDomain($host) || \OC_Config::getValue('trusted_domains', "") === "") {
+ return $host;
+ } else {
+ $trustedList = \OC_Config::getValue('trusted_domains', array(''));
+ return $trustedList[0];
+ }
+ }
/**
* @brief Returns the server protocol
@@ -71,14 +87,14 @@ class OC_Request {
}
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
- }else{
- if(isset($_SERVER['HTTPS']) and !empty($_SERVER['HTTPS']) and ($_SERVER['HTTPS']!='off')) {
- $proto = 'https';
- }else{
- $proto = 'http';
- }
+ // Verify that the protocol is always HTTP or HTTPS
+ // default to http if an invalid value is provided
+ return $proto === 'https' ? 'https' : 'http';
+ }
+ if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
+ return 'https';
}
- return $proto;
+ return 'http';
}
/**
@@ -180,33 +196,6 @@ class OC_Request {
}
/**
- * @brief Check if this is a no-cache request
- * @return boolean true for no-cache
- */
- static public function isNoCache() {
- if (!isset($_SERVER['HTTP_CACHE_CONTROL'])) {
- return false;
- }
- return $_SERVER['HTTP_CACHE_CONTROL'] == 'no-cache';
- }
-
- /**
- * @brief Check if the requestor understands gzip
- * @return false|string true for gzip encoding supported
- */
- static public function acceptGZip() {
- if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
- return false;
- }
- $HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"];
- if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false )
- return 'x-gzip';
- else if( strpos($HTTP_ACCEPT_ENCODING, 'gzip') !== false )
- return 'gzip';
- return false;
- }
-
- /**
* @brief Check if the requester sent along an mtime
* @return false or an mtime
*/