adds csrf info to non-GET requests of whitelisted IPs
427449
def add_csrf_info env
        env[CSRF_TOKEN] = env[SESSION][:_csrf_token] = SecureRandom.base64(32).to_s if env[METHOD] != 'GET' and whitelisted?(env)
      end
969029
function (options) {
    var ignore = options.ignore || [],
        csrf = csurf(options),
        always = {OPTIONS: 1, GET: 1, HEAD: 1};

    return function (req, res, next) {
      if (always[req.method]) {
        return csrf(req, res, next);
      } else {
        var url = parse(req.url);
        var skipCSRF = false;
        ignore.forEach(function(matcher) {
          if (typeof matcher === 'string') {
            if (matcher === url.pathname) {
              skipCSRF = true;
            }
          } else {
            // regular expression matcher
            if (url.pathname.match(matcher)) {
              skipCSRF = true;
            }
          }
        });

        if (skipCSRF) {
          next();
        } else {
          return csrf(req, res, next);
        }
      }
    };
  }
1004305
def _HandleApi(self, request):
    """"""
    # Checks CSRF token. CSRF token cookie is updated when homepage is visited
    # or via GetPendingUserNotificationsCount API call.
    ValidateCSRFTokenOrRaise(request)

    response = http_api.RenderHttpResponse(request)

    # GetPendingUserNotificationsCount is an API method that is meant
    # to be invoked very often (every 10 seconds). So it's ideal
    # for updating the CSRF token.
    # We should also store the CSRF token if it wasn't yet stored at all.
    if (("csrftoken" not in request.cookies) or response.headers.get(
        "X-API-Method", "") == "GetPendingUserNotificationsCount"):
      StoreCSRFCookie(request.user, response)

    return response
1126174
protected function securityHandler()
    {
        $routeInfo = Lb::app()->getRouteInfo();

        // Input Filter
        Security::inputFilter();

        // IP Filter
        Security::ipFilter($routeInfo['controller'], $routeInfo['action']);

        // Csrf Token Validation
        Security::validCsrfToken($routeInfo['controller'], $routeInfo['action']);

        // CORS
        Security::cors($routeInfo['controller'], $routeInfo['action']);

        // X-Frame-Options
        Security::x_frame_options($routeInfo['controller'], $routeInfo['action']);

        // X-XSS-Protection
        Security::x_xss_protection($routeInfo['controller'], $routeInfo['action']);
    }
371711
def list_floating_ip_actions(self, ip_addr):
        
        if self.api_version == 2:
            json = self.request('/floating_ips/' + ip_addr + '/actions')
            return json['actions']
        else:
            raise DoError(v2_api_required_str)
1267554
private function addCSRFTokenField()
    {
        $this->nonceValue = $this->createNonce();
        $nonce = new FormField(FormField::TYPE_HIDDEN);
        $nonce
            ->setName('nonce')
            ->setValue($this->createNonce())
            ->setValidationCallback(
                function ($value) {
                    if (function_exists('wp_verify_nonce')) {
                        if (!wp_verify_nonce($value, $this->nonceKey)) {
                            throw new \Exception('Unauthorized request');
                        }
                    } // Use own csrf token
                    else {
                        if (!isset($_SESSION['csrf_tokens'][$value])) {
                            throw new \Exception('Unauthorized request');
                        } else {
                            unset($_SESSION['csrf_tokens'][$value]);
                        }
                    }

                    return false;
                }
            )
            ->setMandatory(true);
        $key = 'nonce';

        $this->addField($key, $nonce);
    }
523491
def format_private_ip_address(result):
    '''
    
    '''
    from collections import OrderedDict
    # Only display parameters that have content
    order_dict = OrderedDict()
    if result.ip_address is not None:
        order_dict['ipAddress'] = result.ip_address
    if result.subnet_resource_id is not None:
        order_dict['subnetResourceId'] = result.subnet_resource_id

    return order_dict
259225
def salt_token_tool():
    '''
    
    '''
    x_auth = cherrypy.request.headers.get('X-Auth-Token', None)

    # X-Auth-Token header trumps session cookie
    if x_auth:
        cherrypy.request.cookie['session_id'] = x_auth
1029354
protected function securityHandler()
    {
        $routeInfo = $this->route_info;

        // Input Filter
        Security::inputFilter($this->request->getQueryParams());
        Security::inputFilter($this->request->getBodyParams());

        // IP Filter
        Security::ipFilter($routeInfo['controller'], $routeInfo['action'], $this->request);

        // Csrf Token Validation
        Security::validCsrfToken($routeInfo['controller'], $routeInfo['action'], $this->request, $this->response);

        // CORS
        Security::cors($routeInfo['controller'], $routeInfo['action'], $this->response);

        // X-Frame-Options
        Security::x_frame_options($routeInfo['controller'], $routeInfo['action'], $this->response);

        // X-XSS-Protection
        Security::x_xss_protection($routeInfo['controller'], $routeInfo['action'], $this->response);
    }
440720
def add_ip_address_list(list_name):
    '''
    

    '''
    payload = {"jsonrpc": "2.0",
               "id": "ID0",
               "method": "add_policy_ip_addresses_list",
               "params": [{"list_name": list_name}]}

    response = __proxy__['bluecoat_sslv.call'](payload, True)

    return _validate_change_result(response)
1243603
def _force_https(self):
        

        if self.session_cookie_secure:
            if not self.app.debug:
                self.app.config['SESSION_COOKIE_SECURE'] = True

        criteria = [
            self.app.debug,
            flask.request.is_secure,
            flask.request.headers.get('X-Forwarded-Proto', 'http') == 'https',
        ]

        local_options = self._get_local_options()

        if local_options['force_https'] and not any(criteria):
            if flask.request.url.startswith('http://'):
                url = flask.request.url.replace('http://', 'https://', 1)
                code = 302
                if self.force_https_permanent:
                    code = 301
                r = flask.redirect(url, code=code)
                return r
799158
def block_before(self):
        
        # To avoid unnecessary database queries, ignore the IP check for
        # requests for static files
        if request.path.startswith(url_for('static', filename='')):
            return

        # Some static files might be served from the root path (e.g.
        # favicon.ico, robots.txt, etc.). Ignore the IP check for most
        # common extensions of those files.
        ignored_extensions = ('ico', 'png', 'txt', 'xml')
        if request.path.rsplit('.', 1)[-1] in ignored_extensions:
            return

        ips = request.headers.getlist('X-Forwarded-For')
        if not ips:
            return

        # If the X-Forwarded-For header contains multiple comma-separated
        # IP addresses, we're only interested in the last one.
        ip = ips[0].strip()
        if ip[-1] == ',':
            ip = ip[:-1]
        ip = ip.rsplit(',', 1)[-1].strip()

        if self.matches_ip(ip):
            if self.logger is not None:
                self.logger.info("IPBlock: matched {}, {}".format(ip, self.block_msg))
            if self.blocking_enabled:
                return 'IP Blocked', 200
521106
def list(self, subid, params=None):
        ''' 
        '''
        params = update_params(params, {'SUBID': subid})
        return self.request('/v1/server/list_ipv4', params, 'GET')
85673
def _unapply_xheaders(self) -> None:
        
        self.remote_ip = self._orig_remote_ip
        self.protocol = self._orig_protocol
663154
def _get_ip_address(self, request):
        
        ipaddr = request.META.get("HTTP_X_FORWARDED_FOR", None)
        if ipaddr:
            # X_FORWARDED_FOR returns client1, proxy1, proxy2,...
            return ipaddr.split(",")[0].strip()
        return request.META.get("REMOTE_ADDR", "")
774894
def create_private_ip(linode_id):
    
    '''
    kwargs = {'LinodeID': linode_id}
    result = _query('linode', 'ip.addprivate', args=kwargs)

    return _clean_data(result)
1036027
def csrf_protect_all_post_and_cross_origin_requests():
    """"""
    success = None

    if is_cross_origin(request):
        logger.warning("Received cross origin request. Aborting")
        abort(403)
    if request.method in ["POST", "PUT"]:
        token = session.get("csrf_token")
        if token == request.form.get("csrf_token"):
            return success

        elif token == request.environ.get("HTTP_X_CSRFTOKEN"):
            return success

        else:
            logger.warning("Received invalid csrf token. Aborting")
            abort(403)