Handle CSRF validation and view injection.
765008
public function call() {
		if ( !isset( $_SESSION[self::PARAM] ) ) {
			$_SESSION[self::PARAM] = sha1( session_id() . microtime() );
		}

		$token = $_SESSION[self::PARAM];
		$method = $this->app->request()->getMethod();

		if ( in_array( $method, [ 'POST', 'PUT', 'DELETE' ] ) ) {
			$requestToken = $this->app->request()->post( self::PARAM );
			if ( $token !== $requestToken ) {
				$this->app->log->error( 'Missing or invalid CSRF token', [
					'got' => $requestToken,
					'expected' => $token,
				] );
				$this->app->render( 'csrf.html', [], 400 );
				return;
			}
		}

		$this->app->view()->replace( [
			'csrf_param' => self::PARAM,
			'csrf_token' => $token,
		] );

		$this->next->call();
	}
1016496
def form_valid(self, form):
        """"""
        auth_login(self.request, form.get_user())
        return HttpResponseRedirect(self.get_success_url())
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);
    }
91798
def validate_on_submit(self):
        

        # validate form
        valid = FlaskWtf.validate_on_submit(self)

        # return in case no schema or not submitted
        if not self._schema or not self.is_submitted():
            return valid

        # validate data with schema if got one and form was submitted
        data = dict()
        for field in self._fields:
            data[field] = self._fields[field].data

        result = self.schema.process(data, context=self._force_context)
        self.set_errors(result)

        # set filtered data back to form
        for field in data:
            self._fields[field].data = data[field]

        return valid and not bool(self.errors)
622715
def handle_submit(self):
        
        form = self.request.form
        # Selected AR UIDs
        uids = form.get("uids")
        container_mapping = self.get_container_mapping()
        for uid in uids:
            src_pos = container_mapping[uid]
            self.context.addDuplicateAnalyses(src_pos)
        redirect_url = "{}/{}".format(
            api.get_url(self.context), "manage_results")
        self.request.response.redirect(redirect_url)
150431
def clean(self):
        
        super().clean()

        # At least a poster (user) or a session key must be associated with
        # the post.
        if self.poster is None and self.anonymous_key is None:
            raise ValidationError(
                _('A user id or an anonymous key must be associated with a post.'),
            )
        if self.poster and self.anonymous_key:
            raise ValidationError(
                _('A user id or an anonymous key must be associated with a post, but not both.'),
            )

        if self.anonymous_key and not self.username:
            raise ValidationError(_('A username must be specified if the poster is anonymous'))
410013
public function handle(ServerRequestInterface $request)
    {
        if (services()->has('csrfProtection')) {
            if (hash_equals(input()->server('REQUEST_METHOD'), 'POST')) {
                if ( ! services()->get('csrfProtection')->verify()) {
                    output()->sendError(403, [
                        'message' => language()->getLine('403_INVALID_CSRF'),
                    ]);
                }
            }
        }
    }
543658
def on_post(self, req, resp, **kwargs):
        """"""
        validated = self.require_validated(req)

        return super().on_post(
            req, resp,
            handler=partial(self._create, validated=validated),
            **kwargs
        )
42347
protected function _handleUnauthenticatedAccess()
    {
        header("HTTP/1.0 401 Unauthorized");
        $renderer = new TwigRenderer();
        $output = $renderer->render('unauth.tmpl', array());
        $result = array("code"=>"401","message" => $output);
        echo parent::encodeData($result);
        exit;

    }
957690
protected function handleCreateView()
    {
        $input = $this->getCommandInput();
        $resources = Resource::fromFile($input->resourceFile, $input->languageFileName);

        if ($this->metRequirements($resources)) {
            $this->info('Crafting views...');

            foreach ($this->getOnlyViews() as $view) {
                $this->call($this->getViewCommand($view), $input->getArrguments());
            }
        }
    }
366454
public function validateCsrf()
    {
        $tokenService = $this->getServiceLocator()->get(TokenService::SERVICE_ID);

        $tokenName = $tokenService->getTokenName();
        $token = $this->getRequestParameter($tokenName);

        if ( $tokenService->checkToken($token) ) {
            $tokenService->revokeToken($token);
            $newToken = $tokenService->createToken();
            $this->setCookie($tokenName, $newToken, null, '/');
            return true;
        }

        \common_Logger::w('Csrf validation failed');
        throw new \common_exception_Unauthorized();
    }
1025587
public function endForm(): void
    {
        $useCsrf = (isset($this->formOptions['use_csrf'])) ?
            filter_var($this->formOptions['use_csrf'], FILTER_VALIDATE_BOOLEAN)
            : true;

        $tokenField = ($useCsrf) ? HtmlTag::createElement('input')
            ->set('id', 'csrf_token')
            ->set('name', 'csrf_token')
            ->set('type', 'hidden')
            ->set('value', $this->generateCsrfToken())
            : '';

        echo $tokenField . '</form>';
    }
766561
function handleHashChange_() {
  cssTranspiler.getCssWithVars(getUrlCssVars()).then(updatedStyles => {
    iframeManager.setStyle(updatedStyles);
  }).catch(error => {
    // Don't set the styles, log the error
    console.error(error);
  });
}
172633
def spammer_view(request):
    """"""

    # Permits use of CSRF middleware
    context = RequestContext(request, {})
    template = Template("")

    response = HttpResponse(template.render(context))
    # Sets a cookie with a 10 years lifetime, accessible only via HTTP:
    response.set_cookie(COOKIE_KEY, value=COOKIE_SPAM, httponly=True,
                        expires=datetime.now()+timedelta(days=3650))
    
    if DJANGOSPAM_LOG:
        log("BLOCK RESPONSE", request.method, request.path_info,
            request.META.get("HTTP_USER_AGENT", "undefined"))

    return response
962406
public function finishView(FormView $view, FormInterface $form, array $options)
    {
        if ($options['csrf_protection'] && !$view->parent && $options['compound']) {
            $factory = $form->getConfig()->getFormFactory();
            $tokenId = $options['csrf_token_id'] ?: ($form->getName() ?: \get_class($form->getConfig()->getType()->getInnerType()));
            $data = (string) $options['csrf_token_manager']->getToken($tokenId);

            $csrfForm = $factory->createNamed($options['csrf_field_name'], 'Symfony\Component\Form\Extension\Core\Type\HiddenType', $data, [
                'block_prefix' => 'csrf_token',
                'mapped' => false,
            ]);

            $view->children[$options['csrf_field_name']] = $csrfForm->createView($view);
        }
    }
486725
public function onInvalidControl() {
		$auth=$this->_getAuthController();
		if(URequest::isAjax()){
			$this->jquery->get($auth->_getBaseRoute()."/noAccess/".implode(".", Startup::$urlParts),$auth->_getBodySelector(),["historize"=>false]);	
			echo $this->jquery->compile($this->view);
		}else{
			parent::initialize();
			$auth->noAccess(Startup::$urlParts);
			parent::finalize();
		}
		exit();
	}
1348152
def handle_exception(self, exc):
        """"""
        if isinstance(
            exc, (rest_exceptions.NotAuthenticated,
                  rest_exceptions.AuthenticationFailed)) and self.HANDLE_UNAUTHENTICATED:
            return HttpResponseRedirect('{}?next={}'.format(
                reverse('users:login'),
                self.request.get_full_path()))

        if isinstance(exc, Http404):
            raise Http404()

        if isinstance(exc, rest_exceptions.PermissionDenied):
            raise django_exceptions.PermissionDenied()

        return super().handle_exception(exc)