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

CSRF Trusted Origins #2909

Closed
sixcolors opened this issue Mar 9, 2024 · 2 comments
Closed

CSRF Trusted Origins #2909

sixcolors opened this issue Mar 9, 2024 · 2 comments

Comments

@sixcolors
Copy link
Member

A possible solution that maintains best practice for CSRF protection while addressing some users issue where they have multilple origins that they consider trusted, could be to mirror https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-CSRF_TRUSTED_ORIGINS

Originally posted by @sixcolors in #2904 (review)

@sixcolors
Copy link
Member Author

sixcolors commented Mar 10, 2024

One of the users, @sebytza23, faced a challenge with hosting both the backend and the client on the same server while enforcing HTTPS using Apache2 and Virtualmin for the front end. The issue arose because the user couldn’t use the same port (443) for the Apache2 client and the backend. To help, I suggested using Apache as a reverse proxy for the backend and provided specific configurations for the Apache module, along with ProxyPass directives. Additionally, I informed the user about the ongoing addition of TrustedOrigins to the CSRF middleware in gofiber.

For reference, for anyone else with a similar setup:

Enable Apache Modules:

sudo a2enmod proxy
sudo a2enmod proxy_http

Configure ProxyPass:

Edit your Apache configuration file. This could be the default configuration file located at /etc/apache2/sites-available/000-default.conf or a custom configuration file. Add the ProxyPass directive to forward requests to your API.

<VirtualHost *:443>
    ServerName your-domain.com

    # ... other configuration settings ...

    ProxyPass /api http://localhost:3000/
    ProxyPassReverse /api http://localhost:3000/
# Forward client's IP address
    RequestHeader set X-Forwarded-For %{REMOTE_ADDR}
    RequestHeader set X-Real-IP %{REMOTE_ADDR}
    RequestHeader set X-Forwarded-Proto "https"
</VirtualHost>

Restart Apache:

sudo systemctl restart apache2

@ReneWerner87 ReneWerner87 linked a pull request Mar 10, 2024 that will close this issue
7 tasks
@ReneWerner87 ReneWerner87 added this to v3 Mar 11, 2024
@ReneWerner87 ReneWerner87 added this to the v3 milestone Mar 11, 2024
@ReneWerner87
Copy link
Member

solved by #2910

@github-project-automation github-project-automation bot moved this to Done in v3 Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants