Invalid CSRF on dev install

Moved Solved Tips
  • I wanted to create a DEV instance of sudonix, so went ahead and registered, installed NodeBB, then recovered the database.

    All good - apart from the fact that I consistently got the dreaded csrf invalid message… 😠

    Here’s the log extract

    2022-03-21T14:15:25.859Z [4571/91294] - info: Initializing NodeBB v1.19.5
    2022-03-21T14:15:27.761Z [4571/91294] - info: [] Restricting access to origin:*
    2022-03-21T14:15:27.858Z [4571/91294] - warn: [plugins] "@nodebb/nodebb-plugin-user-level" is active but not installed.
    (node:91294) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
    (Use `node --trace-warnings ...` to show where the warning was created)
    2022-03-21T14:15:28.637Z [4571/91294] - warn: [plugins/load] DEPRECATION The hook has been deprecated as of v1.15.3, and slated for removal in v2.1.0. Please use instead. The following plugins are still listening for this hook:
      * nodebb-plugin-write-api
    2022-03-21T14:15:28.724Z [4571/91294] - info: [plugins/spam-be-gone] Settings loaded
    2022-03-21T14:15:28.734Z [4571/91294] - info: [reputation-rules] settings loaded
    2022-03-21T14:15:28.925Z [4571/91294] - info: [api] Adding 4 route(s) to `api/v3/plugins`
    2022-03-21T14:15:28.936Z [4571/91294] - info: [router] Routes added
    2022-03-21T14:15:28.947Z [4571/91294] - info: NodeBB Ready
    2022-03-21T14:15:28.948Z [4571/91294] - info: Enabling 'trust proxy'
    2022-03-21T14:15:28.950Z [4571/91294] - info: NodeBB is now listening on:
    2022-03-21T14:15:47.488Z [4571/91294] - error: [plugin/iframely] Could not parse embed: Failed to lookup view "partials/iframely-widget-card" in views directory "/home/". Url:
    Missing translation "2factor:title" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_unsolved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:topic_solved" for language "en-GB"
    Missing translation "qanda:menu.solved" for language "en-GB"
    Missing translation "qanda:menu.solved" for language "en-GB"
    2022-03-21T14:15:48.899Z [4571/91294] - error: POST /logout
    invalid csrf token

    Tried clearing cache, no dice. Tried incognito mode, no dice.

    After some significant head scratching, it suddenly dawned on me that the cookie domain would need to be reset as this is a PROD database replica in a new domain.

    To do this.

    1. Open the mondogb console
    2. Select your database - in my case use sudonixdev;
    3. Issue this command db.objects.update({_key: "config"}, {$set: {cookieDomain: ""}});
    4. Restart nodebb

    Problem solved - able to login 🙂

  • phenomlabundefined phenomlab has marked this topic as solved on
  • phenomlabundefined phenomlab moved this topic from Configure on
  • phenomlabundefined phenomlab referenced this topic on
  • This post helped me in August.

    Now that I have migrated the server, this topic appears again, and the command no longer works.

    Do you know what causes this problem? How to avoid it?

  • @小城风雨多 The command should still work. What is the output?

  • @phenomlab


    mongoDB version: 6.0.11
    nodebb version: 3.4.3


    renew install nodebb application and whole server machine, use mongodump backup and restored mongoDB data.
    Then I got this.


    server nodebb log when I tried to login and register

    2023-11-03T08:55:23.895Z [4567/5442] - error: POST /login
    invalid csrf token
    2023-11-03T08:55:44.204Z [4567/5442] - error: POST /register
    invalid csrf token

    executed mongo command then print

    nodebb> db.objects.update({_key: "config"}, {$set: {cookieDomain: ""}});
    DeprecationWarning: Collection.update() is deprecated. Use updateOne, updateMany, or bulkWrite.
      acknowledged: true,
      insertedId: null,
      matchedCount: 1,
      modifiedCount: 0,
      upsertedCount: 0
    nodebb> db.objects.updateOne({ _key: "config" }, { $set: { cookieDomain: "" } })
      acknowledged: true,
      insertedId: null,
      matchedCount: 1,
      modifiedCount: 0,
      upsertedCount: 0

    match 1 result, but modifed 0.


    I’m sorry I didn’t post the detailed information before, and I’m very grateful for your timely reply to my message.
    Now I have bound the email address for my account, and the follow-up news should be notified in time.

  • @小城风雨多

    Occasionally I tried to change the url in config.json from https to http.
    It works!


    Thanks a lot!

  • @小城风雨多 Looking at the above, it seems you are missing the command to use nodebb for example. Otherwise, you are running the command against the admin database 🙂 Made that mistake myself before…

Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation💗

  • 0 Votes
    4 Posts

    @DownPW it’s in relation to the response I provided above

  • 13 Votes
    30 Posts

    Here’s a small modification to the chatBanner function that will place the message just above the composer/reply component meaning it is pinned at the bottom and always in view as a reminder. I’ve made this change to support the threadedChat I’m currently developing

    // Chat message banner function chatBanner() { var roomName = $("h5[component='chat/header/title']").text().trim(); var bannerContent; if (roomName === "Testing 3") { bannerContent = '<div id="chatbanner">This message will fire for chat rooms with the title of "Testing 3"</div>'; } else { bannerContent = '<div id="chatbanner">This session is for <strong>private discussion only</strong> between the chosen participants. Please do <strong>not</strong> place support requests here and create a <a href="#" onclick="app.newTopic();">new topic</a> instead.</div>'; } var chatMessagesContainer = $('[component="chat/system-message"]:last-of-type'); //var existingMessages = $('[component="chat/message"]'); var existingMessages = $('[component="chat/composer"]'); if (existingMessages.length === 0) { // If there are no messages, append the banner to the messages container chatMessagesContainer.first().after(bannerContent); } else { // If there are messages, add the banner after the last message // existingMessages.last().after(bannerContent); existingMessages.before(bannerContent); } }

    There are only two changes here:

    var existingMessages = $('[component="chat/message"]');


    var existingMessages = $('[component="chat/composer"]');




  • 1 Votes
    1 Posts

    I got hit with this today. As I have a Pro subscription to Font Awesome, this allows me to use a much wider range of fonts. Unfortunately, NodeBB only seems to list the free fonts, so in order to use the Pro icons, you have to manually type the font name you want (leave the fa- part off, as it’s not needed).

    No issues, so I went ahead and typed in the name. Below is the result


    Now, despite the icon not showing here, it does once you save and reload the site. Great - problem solved then?

    Yes - until you want to change the icon back…

    Highlight over an unchanged icon, and you’ll see the mouse pointer change meaning there is a link behind it


    However, hover over one you’ve changed by typing in the value manually, and you’ll see the link is gone


    Panic stations… headless chicken… major cussing session… No - there is a way out

    Fire up the dev tools (F12 for console), and press the select tool. Now select the element with the missing link


    In the resultant element list, follow the HTML until you reach


    change-icon-link hidden

    Now delete the hidden part, so you are left with just change-icon-link and press enter

    You’ll see that the alt text appears for the image, which is enough for you to be able to click the anchor, and change the icon



    There you go. Now enjoy how smug you feel that you’ve sorted this problem yourself 🙂

  • 3 Votes
    6 Posts

    Seems like Google is finally crawling this site. And, “crawling” in the sense that it’s still extremely slow …

  • 3 Votes
    5 Posts

    @DownPW Same here.

  • 2 Votes
    2 Posts

    As an aside to this, there is also the command of tasklist which will provide a list of processes running on your machine, or a remote machine you are looking to query.


    There is also a useful list of switches below, plus the ability to format into a table, or CSV.

  • 2 Votes
    3 Posts

    @DownPW odd indeed. Looks like it’s spawning, immediately dying, then spawning again.

  • 4 Votes
    2 Posts

    @phenomlab this is useful 👍 thanks