Coder Social home page Coder Social logo

Comments (5)

rafaelfranca avatar rafaelfranca commented on June 7, 2024

This is expected behavior to allow applications to cache the form

from rails.

rbclark avatar rbclark commented on June 7, 2024

Do you mind providing a bit more information on this? I'm not sure I understand the connection to caching here since as far as I understand it the token in the form doesn't expire until the session expires, unless you are talking about caching the rendering of the form for multiple users? More importantly it seems like this behavior defeats the purpose of per_form_csrf_tokens since the lack of a per_form_csrf_token falls back to the token that csrf_meta_tags sets in the header.

In my case I don't cache the form so having the ability to force the form authenticity would be beneficial.

from rails.

rbclark avatar rbclark commented on June 7, 2024

After doing a bit more reading I'm convinced this is still an issue. Looking at the ActionView::Helpers::CsrfHelper docs it states that You don’t need to use these tags for regular forms as they generate their own hidden fields.. So the issue I am running into is that I am using regular forms but since I need csrf_meta_tags for a few places then all of the forms in my app end up using csrf_meta_tags instead of only validating against the per_form_csrf_tag.

from rails.

rafaelfranca avatar rafaelfranca commented on June 7, 2024

Yes. I mean caching the same fork for multiple users using techniques like Russian doll caching. It indeed defeats the per_form_csrf tokens, but at the same time this is how the system was build. Per form tokens were added later, and even when they were added we kept checking the global token as well for compatibility issues.

We can't change this without breaking a lot of applications, that is why it isn't an issue. If you don't want the global tokens to make request legit, you can remove the global csrf_meta_tags from the template and only add to the few places you need it.

from rails.

rbclark avatar rbclark commented on June 7, 2024

Thank you for the clarification! The one issue I would run into with removing csrf_meta_tags globally is that I have some pages that have both types of forms on them. Being able to set protect_from_forgery strict: true or something along those lines and then relaxing it for the routes that need it would be immensely useful. Would you consider a PR for such a change? strict would of course default to false to maintain backwards compatibility.

from rails.

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.