Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare Pages/NextJS bug #80

Open
isaacrowntree opened this issue Nov 1, 2024 · 6 comments
Open

Cloudflare Pages/NextJS bug #80

isaacrowntree opened this issue Nov 1, 2024 · 6 comments

Comments

@isaacrowntree
Copy link

isaacrowntree commented Nov 1, 2024

Because of the way the csrfMiddleware interacts with the ReadableStream in the request it throws an error that the 'ReadableStream' has already been parsed.

The specific error: TypeError: This ReadableStream is disturbed (has already been read from), and cannot be used as a body.

I'm going to have to roll my own csrfProtect function which does a clone of the ReadableStream in order to avoid disturbing it in order to avoid this error at least until you can come with an alternative.

@isaacrowntree isaacrowntree changed the title Cloudflare Pages bug Cloudflare Pages/NextJS bug Nov 1, 2024
@amorey
Copy link
Member

amorey commented Nov 1, 2024

Can you give more details on how you're configuring and using Edge-CSRF? The tests are run in the miniflare environment and this error hasn't shown up so far.

@amorey
Copy link
Member

amorey commented Nov 20, 2024

@isaacrowntree Do you have any updates on this? Were you able to fix the issue with ReadableStream?

amorey added a commit that referenced this issue Nov 21, 2024
* Modifies getTokenString(), clones request before reading it
* Add next15-cloudflare-pages example

Fixes #80
@amorey
Copy link
Member

amorey commented Nov 21, 2024

I tried cloning the request using .clone() before sending it to the body parser but that didn't work:
https://github.com/kubetail-org/edge-csrf/tree/2.5.3-cloudflare

@Gbuomprisco
Copy link

I am hitting the same issue; I think it's worth creating an issue in https://github.com/cloudflare/next-on-pages/issues since I don't think this package is doing anything wrong now

@amorey
Copy link
Member

amorey commented Dec 12, 2024

@Gbuomprisco Done. Thanks for the suggestion! cloudflare/next-on-pages#920

@Gbuomprisco
Copy link

Thank you, appreciate it 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants