create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

CSRF protection for Remote API Server

Open abser opened this issue 7 years ago • 2 comments

I have a Java Spring Boot backend running as my API server which has CORS disabled and CSRF protection enabled. I have stand-alone single page React app has following proxy setting in the package.json which route my API request to the proxy server.

"proxy": "http://localhost:51051",

Start my app with npm start My app running as expected. I can get XSRF-TOKEN cookie set by the backend server. I use that CSRF token to send a post request the API server.

For a production build, I add the full API server URL with each path with the help of environment variable like below.

REACT_APP_API_BASE=http://localhost:51051/ npm run build

Now I run the application with

serve -s build

Application running and access from http://localhost:5000/

Now the problem is I don't get the XSRF-TOKEN cookie set by the backend server. Hence the server rejects my request with 401 error. I tried to set Cookie manually as suggested here Still, server rejecting my post request with 401.

Appreciate if anybody has a good solution for this.

abser avatar Feb 22 '19 07:02 abser

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Mar 24 '19 07:03 stale[bot]

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

stale[bot] avatar Mar 29 '19 07:03 stale[bot]