Coder Social home page Coder Social logo

epic-stack-with-csrf's Introduction

Epic Stack with CSRF Protection

This is an example of how to integrate the remix-utils package utilities for Cross-Site Request Forgery (CSRF) protection with the Epic Stack. The easiest way to explore the example is to pull up the commit history.

Following the steps laid out in the Remix Utils docs is sufficient for this:

  1. Install remix-utils
  2. Generate the authenticity token in the root.tsx loader (be certain to commit the session to set the cookie)
  3. Wrap the App in the <AuthenticityTokenProvider /> and provide the token
  4. Render a Form with the <AuthenticityTokenInput /> component
  5. Verify in the Action using verifyAuthenticityToken and the session.

epic-stack-with-csrf's People

Contributors

kentcdodds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

epic-stack-with-csrf's Issues

Doc suggestion: verifyAuthenticityToken cannot be used with request if the request body has been accessed

I've just used this example to add csrf to the site I was working on, and tripped over an issue that the verifyAuthenticityToken function needs to be given the response before the body of it has been accessed.

e.g. this doesn't work (it throws due to the request body "having been used"):

	let session = await getSession(request.headers.get('Cookie'))
	const formData = await request.formData()
	await verifyAuthenticityToken(request, session)

This does work:

	let session = await getSession(request.headers.get('Cookie'))
	await verifyAuthenticityToken(request, session)
	const formData = await request.formData()

This also works

	let session = await getSession(request.headers.get('Cookie'))
	const formData = await request.formData()
	await verifyAuthenticityToken(formData, session)

Since I'd been wanting to wrap the verify in a try/catch and send back the contents of the form data in the catch clause's error, I'd defaulted to using the first way only to be very confused when the catch clause was firing (the error object seemed to be empty as a result of misconfiguring winston, so I wasn't getting any useful information from it). It's an unexpected limitation that is really easy to trip over.

(Thank you so much for your work and examples on the Epic Stack!)

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.