Update the input dict with CSRF disabled depending on WTF-Form version.

    From Flask-WTF 0.14.0, `csrf_enabled` param has been deprecated in favor of
    `meta={csrf: True/False}`.
324495
def _update_with_csrf_disabled(d=None):
    
    if d is None:
        d = {}

    import flask_wtf
    from pkg_resources import parse_version
    supports_meta = parse_version(flask_wtf.__version__) >= parse_version(
        "0.14.0")
    if supports_meta:
        d.setdefault('meta', {})
        d['meta'].update({'csrf': False})
    else:
        d['csrf_enabled'] = False
    return d
977228
def update_filter_dict(d, user, status):
    
    if user is not None:
        if not user.id:
            return None
        d['user'] = user
    if status is not None:
        d['status'] = status
1248991
def update_request(self, request, form):
        """"""
        forms_key = '%s_forms' % self.flow_type

        # Use ordered forms dict in case _formNode wants to fetch the first defined.
        flow_dict = OrderedDict()
        try:
            flow_dict = request.sitegate[forms_key]
        except AttributeError:
            request.sitegate = {}
        except KeyError:
            pass

        flow_dict[self.get_flow_name()] = form
        request.sitegate[forms_key] = flow_dict
667432
def csrf_protect(f):
    """"""

    @wraps(f)
    def wrapper(*args, **kwargs):
        token = session.get("csrf_token", None)
        if token is None or token != request.environ.get("HTTP_X_CSRFTOKEN"):
            logger.warning("Received invalid csrf token. Aborting")
            abort(403)
        # call original request handler
        return f(*args, **kwargs)

    return wrapper
163614
def form(self, obj=None, form=None, name=None, template=None, var_name=None, validate_on_submit=True,\
        exit_on_failure=True, csrf_enabled=None):
        
        if not form or isinstance(form, str):
            if not name and isinstance(form, str):
                name = form
            if not name:
                name = request.endpoint.rsplit('.', 1)[1] if '.' in request.endpoint else request.endpoint
            if name not in self.forms:
                raise NoFormError("Cannot find form '%s'" % name)
            form = self.forms[name]
        if inspect.isclass(form):
            if isinstance(obj, dict):
                obj = DictObject(obj)
            if csrf_enabled is None:
                csrf_enabled = self.options["csrf_enabled"]
            form = form(obj=obj, meta={'csrf': csrf_enabled})

        current_context.data.form = form
        yield form

        if validate_on_submit and request.method == "POST":
            self.validate(form, exit_on_failure=exit_on_failure)
818573
public function csrfFixupNeeded() {
        $result = false;
        $isEnterprise = false; // ce
        if (method_exists('Mage', 'getEdition')) {
            if (Mage::getEdition() === Mage::EDITION_ENTERPRISE) {
                $isEnterprise = true;
            }
        } else {
            if (Mage::getConfig()->getModuleConfig('Enterprise_Enterprise')) {
                $isEnterprise = true;
            }
        }
        if ($isEnterprise) {
            if (version_compare(Mage::getVersion(), '1.13', '>=')) {
                $result = true;
            }
        } else {
            if (version_compare(Mage::getVersion(), '1.8', '>=')) {
                $result = true;
            }
        }
        return $result;
    }
242111
def disabled(name):
    '''
    
    '''
    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': ''}

    stat = __salt__['rdp.status']()

    if stat:
        if __opts__['test']:
            ret['result'] = None
            ret['comment'] = 'RDP will be disabled'
            return ret

        ret['result'] = __salt__['rdp.disable']()
        ret['changes'] = {'RDP was disabled': True}
        return ret

    ret['comment'] = 'RDP is disabled'
    return ret
579330
def validate(self, form_cls, obj=None):
        ''''''
        if 'application/json' not in request.headers.get('Content-Type'):
            errors = {'Content-Type': 'expecting application/json'}
            self.abort(400, errors=errors)
        form = form_cls.from_json(request.json, obj=obj, instance=obj,
                                  csrf_enabled=False)
        if not form.validate():
            self.abort(400, errors=form.errors)
        return form
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>';
    }
162180
def password_change(self, request):
        
        from django.contrib.auth.views import password_change
        url = reverse('admin:cms_password_change_done')
        defaults = {
            'post_change_redirect': url,
            'template_name': 'cms/password_change_form.html',
        }
        if self.password_change_template is not None:
            defaults['template_name'] = self.password_change_template
        return password_change(request, **defaults)
335949
async def createcsrf(self, csrfarg = '_csrf'):
        
        await self.sessionstart()
        if not csrfarg in self.session.vars:
            self.session.vars[csrfarg] = uuid.uuid4().hex
1276477
def edit(self, sha, force=github.GithubObject.NotSet):
        
        assert isinstance(sha, (str, unicode)), sha
        assert force is github.GithubObject.NotSet or isinstance(force, bool), force
        post_parameters = {
            "sha": sha,
        }
        if force is not github.GithubObject.NotSet:
            post_parameters["force"] = force
        headers, data = self._requester.requestJsonAndCheck(
            "PATCH",
            self.url,
            input=post_parameters
        )
        self._useAttributes(data)
1185863
function noncifyTag({ name, block: { nodes } }) {
      if (name === 'form' && csrfInputValueExpression) {
        nodes.unshift({
          type: 'Conditional',
          test: csrfInputValueExpression,
          consequent: {
            type: 'Block',
            nodes: [
              {
                type: 'Tag',
                name: 'input',
                selfClosing: false,
                block: {
                  type: 'Block',
                  nodes: [],
                },
                attrs: [
                  {
                    name: 'name',
                    val: stringify(csrfInputName),
                    mustEscape: true,
                  },
                  {
                    name: 'type',
                    val: '\'hidden\'',
                    mustEscape: true,
                  },
                  {
                    name: 'value',
                    val: csrfInputValueExpression,
                    mustEscape: true,
                  },
                ],
                attributeBlocks: [],
                isInline: false,
              },
            ],
          },
          alternate: null,
        });
      }
    }
1075122
def get_xeditable_form_kwargs(self):
        
        kwargs = {
            'model': self.get_queryset().model,
        }
        if self.request.method in ('POST', 'PUT'):
            kwargs.update({
                'data': self.request.POST,
            })
        return kwargs
204048
def set_meta(request):
    
    context_extras = {}
    if not request.is_ajax() and hasattr(request, 'upy_context') and request.upy_context['PAGE']:
        context_extras['PAGE'] = request.upy_context['PAGE']
        context_extras['NODE'] = request.upy_context['NODE']
    return context_extras
1330005
def selfmodify(self, **params):
        
        self._check_auth(must_admin=False)
        is_admin = self._check_admin()
        sess = cherrypy.session
        user = sess.get(SESSION_KEY, None)
        if self.auth_mode == 'none':
            return self.temp['error.tmpl'].render(
                is_admin=is_admin,
                alert='warning',
                message="Not accessible with authentication disabled."
                )
        if cherrypy.request.method.upper() == 'POST':
            params = self._parse_params(params)
            self._selfmodify(params)
            self._add_notification(
                "Self modification done"
            )
        user_attrs = self._get_user(user)

        try:
            if user_attrs == {}:
                return self.temp['error.tmpl'].render(
                    is_admin=is_admin,
                    alert='warning',
                    message="User doesn't exist"
                    )

            form = self.temp['form.tmpl'].render(
                attributes=self.attributes.get_selfattributes(),
                values=user_attrs,
                modify=True,
                autofill=False
                )
            return self.temp['selfmodify.tmpl'].render(
                form=form,
                is_admin=is_admin,
                notifications=self._empty_notification(),
                )
        except NameError:
            raise TemplateRenderError(
                    exceptions.text_error_template().render()
                    )
365184
def masked_authenticity_token(session, form_options: {}) # :doc:
        action, method = form_options.values_at(:action, :method)

        raw_token = if per_form_csrf_tokens && action && method
          action_path = normalize_action_path(action)
          per_form_csrf_token(session, action_path, method)
        else
          real_csrf_token(session)
        end

        one_time_pad = SecureRandom.random_bytes(AUTHENTICITY_TOKEN_LENGTH)
        encrypted_csrf_token = xor_byte_strings(one_time_pad, raw_token)
        masked_token = one_time_pad + encrypted_csrf_token
        Base64.strict_encode64(masked_token)
      end