Giter Site home page Giter Site logo

Comments (9)

jirikuncar avatar jirikuncar commented on August 16, 2024

The default form validation stopped working: https://github.com/inveniosoftware/invenio-oauthclient/blob/master/invenio_oauthclient/utils.py#L117

from invenio-oauthclient.

jirikuncar avatar jirikuncar commented on August 16, 2024

It looks like Flask-WTF>=0.14 has some issues with CSRF validation.

pip install Flask-WTF==0.13

from invenio-oauthclient.

switowski avatar switowski commented on August 16, 2024

Latest version of Flask-WTF (0.14.2) seems to have this issue fixed (tested with @egabancho on cdslabs-qa), so we can close it.

from invenio-oauthclient.

egabancho avatar egabancho commented on August 16, 2024

I think this issue is still valid, we didn't tested properly as the error only happens at first login.
Indeed the only version of Flask-WTF that seems to be working is 0.13.1.

cc @pamfilos @ioannistsanaktsidis

from invenio-oauthclient.

tobiashuste avatar tobiashuste commented on August 16, 2024

I wanted to let you know, that I still experienced problems with CSRF validation in combination with the invenio-userprofiles module.
For the RegistrationForm which did not include invenio-userprofiles everything worked as expected. With invenio-userprofiles enabled, form validation stopped working again. (I used the create_csrf_disabled_registrationform()-function from invenio-oauthclient.)

The problem was, that in the subform created by invenio-userprofiles CSRF-validation was still active. After deleting the csrf_token in the subform and also setting csrf-validation to false, the form validation succeeded.

My current solution is to disable csrf-validation as follows for Flask-WTF>=0.14 for a given form:

def disable_csrf(form):
  form.meta.csrf = False
  if 'csrf_token' in form:
    del form.csrf_token
    for f in form:
      if isinstance(f, FormField):
        disable_csrf(f.form)

I wanted to let you know my experience just in case the same situation is valid for invenio-oauthclient.

from invenio-oauthclient.

miltalex avatar miltalex commented on August 16, 2024

I tried to replicate the issue, using Flask-WTF (0.14.2) and invenio-userprofiles(1.0.0b1) and after testing it (with @ntarocco) , create_csrf_disabled_registrationform() seems to working as expected.

from invenio-oauthclient.

lnielsen avatar lnielsen commented on August 16, 2024

@tobiasfrust Can you check if you have all the latest releases of packages and see if you are still experiencing the issue. If you still have the issue, further information on exactly how to replicate it would help us a lot in trying to fix it for good.

from invenio-oauthclient.

tobiashuste avatar tobiashuste commented on August 16, 2024

I just tried to replicate the issue by providing some tests with WTF_CSRF_ENABLED=True. You can see my code changes in this commit.

I just ran the tests with Travis and you can see the result e.g. here. As you can see, form validation fails with the currently used method. I also printed the form to the console, and there was a csrf_token in the userprofiles subform, which is the reason for failing validation I guess.
The output of the print statements is shown here.

In your oauth_register-function your call form.validate(). If I did not miss anything in my tests, the user registration should not succeed because of form.validate()=False. So, there should only be a problem on the very first sign-in.

I also added a second test, which uses an updated way of disabling csrf (https://github.com/tobiasfrust/invenio-oauthclient/blob/21c1189679ce4be89c5ed2dd7db2a53452aa385c/invenio_oauthclient/utils.py#L238-L268). With these changes, form validation succeeds.

If you need further information or if I missed anything, just let me know.

from invenio-oauthclient.

miltalex avatar miltalex commented on August 16, 2024

@tobiasfrust Thank you for the information, we managed to reproduce the issue through the tests and will try to fix it.

from invenio-oauthclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.