csrf-invalid when using cloudfront https

Technical Support
  • I'm trying to get my nodebb setup working with SSL using AWS's certificate manager. To do this I'm using AWS Cloudfront. Everything is working wonderfully up until I go to set my site URL in the config.json

    As soon as I change the url from http://forum.example.com to https://forum.example.com I get csrf-invalid errors when trying to login.

    here is my config.json:

    {
        "url": "https://forum.example.com",
        "secret": "MYSECRET",
        "database": "redis",
        "redis": {
            "host": "aws.redis.url",
            "port": "6379",
            "password": "",
            "database": "0"
        }
    }
    

    Here is my nginx configuration:

    server {
        listen 80;
        server_name forum.example.com;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://io_nodes;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    
    upstream io_nodes {
        ip_hash;
        server 127.0.0.1:4567;
        server 127.0.0.1:4568;
    }
    
    

    As you can see I have proxy_set_header X-Forwarded-Proto $scheme; as suggested here https://blog.nodebb.org/nodebb-v1-1-0-release/

    What am I missing in my configuration to get this working?

  • Anyone have any advice?

  • Does it matter that your Nginx configuration only defines http (listen 80) and not https (443) yet in your config.json you are saying your forum url is "url": "https://forum.example.com", ?

  • @rod Cloudfront is requesting on port 80. Would do 443 but I don't have access to the raw ssl certificates because I'm using AWS's certificate manager for free wildcard certs.


Suggested Topics


  • Using jQuery in widgets

    Unsolved Technical Support
    0 Votes
    11 Posts
    137 Views

    @baris @julian found a much simpler way to do this

    <script> if (!window.jQuery) { window.addEventListener('load', function() { $(document).ready(function() { $("#resolved").appendTo('[data-index="1"]:first-of-type'); }) }) } else { $(document).ready(function() { $("#resolved").appendTo('[data-index="1"]:first-of-type'); }) } </script>
  • 0 Votes
    2 Posts
    214 Views

    I set the domain name in the CDN to https://xxx.yyy This points to the address provided by the CDN to me.
    For some special reasons, my server is a dynamic IP address, so my CDN back-to-source domain name is
    https://cdn.yyy which points to the server where nodebb is deployed.

    Since my CDN does not support websocket, I have the following configuration in config.json

    "socket.io": { "origins": "*:*", "transports": ["polling"] }, "url": "https://xxx.yyy",

    I have the following configuration in nginx.conf
    server_name xxx.yyy cdn.yyy;

    When I upload a profile picture, I can find the error in the chrome console

    Failed to load resource: the server responded with a status of 400 () socket.io.js:7 POST https://xxx.yyy/socket.io/?EIO=3&transport=polling&t=NCtuzk2&sid=3Ud1Gzokb0tf8jODAAAC 400 o.create @ nodebb.min.js?v=r00khbol8e4:1 o @ nodebb.min.js?v=r00khbol8e4:1 r.request @ nodebb.min.js?v=r00khbol8e4:1 r.doWrite @ nodebb.min.js?v=r00khbol8e4:1 (anonymous) @ nodebb.min.js?v=r00khbol8e4:1 (anonymous) @ nodebb.min.js?v=r00khbol8e4:1 r @ nodebb.min.js?v=r00khbol8e4:1 (anonymous) @ nodebb.min.js?v=r00khbol8e4:1 (anonymous) @ nodebb.min.js?v=r00khbol8e4:1 t.encodePacket @ nodebb.min.js?v=r00khbol8e4:1 o @ nodebb.min.js?v=r00khbol8e4:1 o @ nodebb.min.js?v=r00khbol8e4:1 c @ nodebb.min.js?v=r00khbol8e4:1 t.encodePayload @ nodebb.min.js?v=r00khbol8e4:1 i.write @ nodebb.min.js?v=r00khbol8e4:1 e @ nodebb.min.js?v=r00khbol8e4:1 i.doClose @ nodebb.min.js?v=r00khbol8e4:1 i.close @ nodebb.min.js?v=r00khbol8e4:1 i.onClose @ nodebb.min.js?v=r00khbol8e4:1 i.onError @ nodebb.min.js?v=r00khbol8e4:1 (anonymous) @ nodebb.min.js?v=r00khbol8e4:1 i.emit @ nodebb.min.js?v=r00khbol8e4:1 i.onError @ nodebb.min.js?v=r00khbol8e4:1 (anonymous) @ nodebb.min.js?v=r00khbol8e4:1 i.emit @ nodebb.min.js?v=r00khbol8e4:1 o.onError @ nodebb.min.js?v=r00khbol8e4:1 (anonymous) @ nodebb.min.js?v=r00khbol8e4:1 setTimeout (async) hasXDR.t.onreadystatechange @ nodebb.min.js?v=r00khbol8e4:1

    0c1101c1-5d4f-4dc7-9e56-c9a2df3e005d-image.png e137037c-7780-4b2b-a774-2486c8522693-image.png

    When I upload pictures in the post, I can find the error in the chrome console

    Failed to load resource: the server responded with a status of 400 () /socket.io/?EIO=3&transport=polling&t=NCtuzk2&sid=3Ud1Gzokb0tf8jODAAAC:1 Failed to load resource: the server responded with a status of 400 () /socket.io/?EIO=3&transport=polling&t=NCtv4FE&sid=MZuuQLlpnXxI4yPOAAAC:1 Failed to load resource: the server responded with a status of 400 () /socket.io/?EIO=3&transport=polling&t=NCtv4Jf&sid=MZuuQLlpnXxI4yPOAAAC:1 Failed to load resource: the server responded with a status of 400 () /socket.io/?EIO=3&transport=polling&t=NCtvjAz&sid=Hy92qn1n-0XFzAGzAAAA:1 Failed to load resource: the server responded with a status of 400 () /api/post/upload:1 Failed to load resource: the server responded with a status of 500 ()

    fa8c17ad-2d34-4583-b4ef-703ba683712e-image.png

    Please help me, thanks!

  • What URL to Use for SSO

    Technical Support
    0 Votes
    3 Posts
    1k Views

    I'm not for sure, but it could be https://community.mysite.com?loggedin

  • 0 Votes
    1 Posts
    871 Views

    Is it possible to use NodeBB as an OAuth2 provider? I searched for the answer to this, but all I found were lots of topics on connecting to other providers.

  • 0 Votes
    9 Posts
    4k Views

    That's awesome news from CloudFlare! 🙂