Get request file and do a security check
760886
def __get_file(self, file):
        
        file_object = None
        if file['name'] in request.files:
            file_object = request.files[file['name']]
            clean_filename = secure_filename(file_object.filename)
            if clean_filename == '':
                return file_object
            if file_object and self.__allowed_extension(
                    clean_filename, file['extensions']):
                return file_object
        elif file['name'] not in request.files and file['required']:
            return file_object
        return file_object
1303942
def get_authinfo(request):
    """"""
    if (("files_iv" not in request.session) or ("files_text" not in request.session) or ("files_key" not in request.COOKIES)):
        return False
    """
        Decrypt the password given the SERVER-side IV, SERVER-side
        ciphertext, and CLIENT-side key.

        See note above on why this is done.
    """

    iv = base64.b64decode(request.session["files_iv"])
    text = base64.b64decode(request.session["files_text"])
    key = base64.b64decode(request.COOKIES["files_key"])

    obj = AES.new(key, AES.MODE_CFB, iv)
    password = obj.decrypt(text)

    username = request.session["filecenter_username"] if "filecenter_username" in request.session else request.user.username

    return {"username": username, "password": password}
1028389
public function check()
	{
		$request = $this->app['request'];
		$getter = new TokenGetter( new Header($request), new  QueryStr($request));
		return $this->auth->check($getter, $this->secretKey);
	}
241132
def get_file(self, secure_data_path, version=None):
        

        query = self._get_file(secure_data_path, version)
        resp = query.headers.copy()
        resp = self._parse_metadata_filename(resp)
        resp['data'] = query.content

        return resp
608575
def stub_request(self, expected_url, filename, status=None, body=None):
        """"""
        self.fake_web = True
        self.faker = get_faker(expected_url, filename, status, body)
694312
protected static function checkSecureFolder()
  {
    if (!is_dir(static::getStorePath())) {
      mkdir(static::getStorePath());
    }
    if (!file_exists(static::getStorePath() . '.htaccess')) {
      $afc = static::getAssetContent('htaccess');
      $f = new File(static::getStorePath() . '.htaccess', true);
      $f->write($afc);
    }
    if (!file_exists(static::getStorePath() . 'read.php')) {
      $afc = static::getAssetContent('read');
      $afc = str_replace('%autoloader%', self::$autoloaderPath, $afc);
      $afc = str_replace('%storepath%', self::$storePath, $afc);
      $f = new File(static::getStorePath() . 'read.php', true);
      $f->write($afc);
    }
  }
204436
def query_file(self, path, fetchall=False, **params):
        """"""

        with self.get_connection() as conn:
            return conn.query_file(path, fetchall, **params)
1194960
function(params, callback) {
                getFileData = {};

                if (params) {
                    if (typeof params.fileId != 'undefined') {
                        getFileData.fileId = params.fileId;
                    }

                    if (typeof params.hashCode == 'string') {
                        getFileData.hashCode = params.hashCode;
                    }

                    if (typeof params.downloadable == 'boolean') {
                        getFileData.downloadable = params.downloadable;
                    }
                }

                httpRequest({
                    url: SERVICE_ADDRESSES.FILESERVER_ADDRESS +
                    SERVICES_PATH.GET_FILE,
                    method: 'GET',
                    data: getFileData
                }, function(result) {
                    if (!result.hasError) {
                        var queryString = '?';
                        for (var i in params) {
                            queryString += i + '=' + params[i] + '&';
                        }
                        queryString = queryString.slice(0, -1);
                        var file = SERVICE_ADDRESSES.FILESERVER_ADDRESS + SERVICES_PATH.GET_FILE + queryString;
                        callback({
                            hasError: result.hasError,
                            result: file
                        });
                    }
                    else {
                        callback({
                            hasError: true
                        });
                    }
                });
            }
308177
def get_protected_page(url, user, pwd, filename):
    
    import requests
    r = requests.get(url, auth=(user, pwd))
    print(r.status_code)
    if r.status_code == 200:
        print('success')
        with open(filename, 'wb') as fd:
            for chunk in r.iter_content(4096):
                fd.write(chunk)
        lg.record_result("Success - downloaded " + url)
    else:
        lg.record_result('network_tools.get_protected_page:Failed to downloaded ' + url + ' (status code = ' + str(r.status_code) + ')')
1092082
def SecurityCheck(self, func, request, *args, **kwargs):
    """"""
    request.user = self.username
    request.token = access_control.ACLToken(
        username="Testing", reason="Just a test")
    return func(request, *args, **kwargs)
349013
protected function checkRequest()
    {
        if (preg_match(CKFINDER_REGEX_INVALID_PATH, $this->_currentFolder->getClientPath())) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
        }

        $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();

        if (is_null($_resourceTypeConfig)) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_TYPE);
        }

        $_clientPath = $this->_currentFolder->getClientPath();
        $_clientPathParts = explode("/", trim($_clientPath, "/"));
        if ($_clientPathParts) {
            foreach ($_clientPathParts as $_part) {
                if ($_resourceTypeConfig->checkIsHiddenFolder($_part)) {
                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
                }
            }
        }

        if (!is_dir($this->_currentFolder->getServerPath())) {
            if ($_clientPath == "/") {
                if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) {
                    /**
                     * @todo handle error
                     */
                }
            }
            else {
                $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
            }
        }
    }
682512
def make_request(method, url, params):
    """"""
    empty = []

    # TODO
    # del params[key]
    # without list
    for key, value in six.iteritems(params):
        if value is None:
            empty.append(key)
    for key in empty:
        del params[key]

    # allow caller to disable automatic following of redirects
    allow_redirects = params.get('allow_redirects', True)

    kwargs = {
        'allow_redirects': allow_redirects,
        'headers': {
            'User-Agent': soundcloud.USER_AGENT
        }
    }
    # options, not params
    if 'verify_ssl' in params:
        if params['verify_ssl'] is False:
            kwargs['verify'] = params['verify_ssl']
        del params['verify_ssl']
    if 'proxies' in params:
        kwargs['proxies'] = params['proxies']
        del params['proxies']
    if 'allow_redirects' in params:
        del params['allow_redirects']

    params = hashconversions.to_params(params)
    files = namespaced_query_string(extract_files_from_dict(params))
    data = namespaced_query_string(remove_files_from_dict(params))

    request_func = getattr(requests, method, None)
    if request_func is None:
        raise TypeError('Unknown method: %s' % (method,))

    if method == 'get':
        kwargs['headers']['Accept'] = 'application/json'
        qs = urlencode(data)
        if '?' in url:
            url_qs = '%s&%s' % (url, qs)
        else:
            url_qs = '%s?%s' % (url, qs)
        result = request_func(url_qs, **kwargs)
    else:
        kwargs['data'] = data
        if files:
            kwargs['files'] = files
        result = request_func(url, **kwargs)

    # if redirects are disabled, don't raise for 301 / 302
    if result.status_code in (301, 302):
        if allow_redirects:
            result.raise_for_status()
    else:
        result.raise_for_status()
    return result
309681
public static function detect()
    {
        $aURL = [];
        // Try to get the request URL
        if(!empty($_SERVER['REQUEST_URI']))
        {
            $_SERVER['REQUEST_URI'] = str_replace(array('"',"'",'<','>'), array('%22','%27','%3C','%3E'), $_SERVER['REQUEST_URI']);
            $aURL = parse_url($_SERVER['REQUEST_URI']);
        }

        // Fill in the empty values
        if(empty($aURL['scheme']))
        {
            if(!empty($_SERVER['HTTP_SCHEME']))
            {
                $aURL['scheme'] = $_SERVER['HTTP_SCHEME'];
            }
            else
            {
                $aURL['scheme'] = ((!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http');
            }
        }

        if(empty($aURL['host']))
        {
            if(!empty($_SERVER['HTTP_X_FORWARDED_HOST']))
            {
                if(strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ':') > 0)
                {
                    list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_X_FORWARDED_HOST']);
                }
                else
                {
                    $aURL['host'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
                }
            }
            elseif(!empty($_SERVER['HTTP_HOST']))
            {
                if(strpos($_SERVER['HTTP_HOST'], ':') > 0)
                {
                    list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_HOST']);
                }
                else
                {
                    $aURL['host'] = $_SERVER['HTTP_HOST'];
                }
            }
            elseif(!empty($_SERVER['SERVER_NAME']))
            {
                $aURL['host'] = $_SERVER['SERVER_NAME'];
            }
            else
            {
                throw new \Jaxon\Exception\URI();
            }
        }

        if(empty($aURL['port']) && !empty($_SERVER['SERVER_PORT']))
        {
            $aURL['port'] = $_SERVER['SERVER_PORT'];
        }

        if(!empty($aURL['path']) && strlen(basename($aURL['path'])) == 0)
        {
            unset($aURL['path']);
        }

        if(empty($aURL['path']))
        {
            if(!empty($_SERVER['PATH_INFO']))
            {
                $sPath = parse_url($_SERVER['PATH_INFO']);
            }
            else
            {
                $sPath = parse_url($_SERVER['PHP_SELF']);
            }
            if(isset($sPath['path']))
            {
                $aURL['path'] = str_replace(array('"',"'",'<','>'), array('%22','%27','%3C','%3E'), $sPath['path']);
            }
            unset($sPath);
        }

        if(empty($aURL['query']) && !empty($_SERVER['QUERY_STRING']))
        {
            $aURL['query'] = $_SERVER['QUERY_STRING'];
        }

        if(!empty($aURL['query']))
        {
            $aURL['query'] = '?'.$aURL['query'];
        }

        // Build the URL: Start with scheme, user and pass
        $sURL = $aURL['scheme'].'://';
        if(!empty($aURL['user']))
        {
            $sURL.= $aURL['user'];
            if(!empty($aURL['pass']))
            {
                $sURL.= ':'.$aURL['pass'];
            }
            $sURL.= '@';
        }

        // Add the host
        $sURL.= $aURL['host'];

        // Add the port if needed
        if(!empty($aURL['port'])
                && (($aURL['scheme'] == 'http' && $aURL['port'] != 80)
                        || ($aURL['scheme'] == 'https' && $aURL['port'] != 443)))
        {
            $sURL.= ':'.$aURL['port'];
        }

        // Add the path and the query string
        $sURL.= $aURL['path'].@$aURL['query'];

        // Clean up
        unset($aURL);

        $aURL = explode("?", $sURL);

        if(1 < count($aURL))
        {
            $aQueries = explode("&", $aURL[1]);

            foreach($aQueries as $sKey => $sQuery)
            {
                if("jxnGenerate" == substr($sQuery, 0, 11))
                    unset($aQueries[$sKey]);
            }

            $sQueries = implode("&", $aQueries);

            $aURL[1] = $sQueries;

            $sURL = implode("?", $aURL);
        }

        return $sURL;
    }
192758
def run_getmy(filename, **kwargs):
    """"""
    assume_yes = kwargs.get("yes_to_all")
    user = getenv("GETGIST_USER")
    getgist = GetGist(user=user, filename=filename, assume_yes=assume_yes)
    getgist.get()
298612
def get_file_content(url, comes_from=None):
    """"""
    match = _scheme_re.search(url)
    if match:
        scheme = match.group(1).lower()
        if (scheme == 'file' and comes_from
            and comes_from.startswith('http')):
            raise InstallationError(
                'Requirements file %s references URL %s, which is local'
                % (comes_from, url))
        if scheme == 'file':
            path = url.split(':', 1)[1]
            path = path.replace('\\', '/')
            match = _url_slash_drive_re.match(path)
            if match:
                path = match.group(1) + ':' + path.split('|', 1)[1]
            path = urllib.unquote(path)
            if path.startswith('/'):
                path = '/' + path.lstrip('/')
            url = path
        else:
            ## FIXME: catch some errors
            resp = urlopen(url)
            return geturl(resp), resp.read()
    try:
        f = open(url)
        content = f.read()
    except IOError:
        e = sys.exc_info()[1]
        raise InstallationError('Could not open requirements file: %s' % str(e))
    else:
        f.close()
    return url, content
928223
def __pre_check(self, requestedUrl):
		'''
		
		'''
		components = urllib.parse.urlsplit(requestedUrl)

		netloc_l = components.netloc.lower()
		if netloc_l in Domain_Constants.SUCURI_GARBAGE_SITE_NETLOCS:
			self.__check_suc_cookie(components)
		elif netloc_l in Domain_Constants.CF_GARBAGE_SITE_NETLOCS:
			self.__check_cf_cookie(components)
		elif components.path == '/sucuri_shit_2':
			self.__check_suc_cookie(components)
		elif components.path == '/sucuri_shit_3':
			self.__check_suc_cookie(components)
		elif components.path == '/cloudflare_under_attack_shit_2':
			self.__check_cf_cookie(components)
		elif components.path == '/cloudflare_under_attack_shit_3':
			self.__check_cf_cookie(components)
812412
def download_file_insecure(url, target):
    """"""
    src = urlopen(url)
    try:
        # Read all the data in one block.
        data = src.read()
    finally:
        src.close()

    # Write all the data in one block to avoid creating a partial file.
    with open(target, "wb") as dst:
        dst.write(data)