Giter Site home page Giter Site logo

Comments (6)

stongo avatar stongo commented on August 13, 2024

Firstly, if you are only accessing a route server-side, CSRF protection is not necessary, as it is a client/browser vulnerability. However if the route is also accessed by a browser, here's how to make it work
In Crumb's default mode, when POSTing a JSON payload include the crumb as {"crumb": "crumbValue"} and the header cookie: crumb=crumbValue
See https://github.com/hapijs/crumb/blob/master/test/index.js#L106 for example
You can also set the crumb plugin option restful: true and then send the crumb along in a HTTP header called X-CSRF-Token along with the cookie header
Additionally the Crumb plugin options has a skip property which allows you to provide a function to skip Crumb validation, which would be an option as well.
Let me know if you need any further assistance

from crumb.

rutaihwa avatar rutaihwa commented on August 13, 2024

Thanks, I have tried the crumb's default mode, it works as anticipated.

If I were to set restful: true will the server still be able protect against
the POSTs which are not API calls?
Or is it possible to set restful: true for a API connection and leave default for the other?

from crumb.

stongo avatar stongo commented on August 13, 2024

the form submissions would require some processing to add the X-CSRF-Token header when restful: true - a raw post from browser would fail
as far as I know, restful has to be true or false.
you might be better off on using the skip option for such things

from crumb.

rutaihwa avatar rutaihwa commented on August 13, 2024

@stongo crumb works like a charm, I have tried few things and I found the easier way is to register crumb a particular connection, say www server with its options and register crumb for api server with restful options.
Do you know issues that could create?.

from crumb.

stongo avatar stongo commented on August 13, 2024

@rutaihwa that's brilliant! I would say you are all good with that setup

from crumb.

lock avatar lock commented on August 13, 2024

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

from crumb.

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.