Vlan_search plugin, 419 Sorry, your session has expired. Please refresh and try again

Hello.
When I try to seach some vlan via Vlan_search plugin, I got error message:

 ./validate.php 
====================================
Component | Version
--------- | -------
LibreNMS  | 1.53.1-40-gfd42ea6
DB Schema | 2019_05_30_225937_device_groups_rewrite (135)
PHP       | 7.2.14-1+ubuntu16.04.1+deb.sury.org+1
MySQL     | 10.0.38-MariaDB-0ubuntu0.16.04.1
RRDTool   | 1.5.5
SNMP      | NET-SNMP 5.7.3
====================================

I’ve had the same problem, it broke all our plugins except for weathermaps.

This happened because of an update, and seems to be related to the laravel framework, which librenms uses.

Since I update the code manually every month, and keep a history of the versions we run, I was able to revert this quite easily with git checkout.

I can tell the problem happened between version:

38a638358df8a73154c7f68cb2ec5379aa67294f

which was working perfectly, and

c14fd96bb473cd18ef696a870abf2b54f6e55bb7

that shows the error message you posted, but I cannot specify the version that actually broke the plugin functionality.

This is a temporary fix, and is not ideal since it will probably break again in the next code update.

Any help as to what caused it, wether it will be fixed By LibreNMS, or what needs to change in the plugin’s code would be very apreciated.

2 Likes

I found out how what the issue is. The plugin need to be updated with csrf_field()

See https://github.com/librenms/librenms/blob/master/doc/Developing/Dynamic-Config.md

Ex. I fixed one of my plugins with
print " <form action=’/plugin/p=$GLOBALS[plugin_name]’ method=‘post’> ";
print csrf_field();
print $stuff;
print ’ </form> ';

1 Like

Hi @dubbelj,

can you elaborate on what you did exactly? I read the link you provided but it’s not clear to me how it relates to plugins.

From your reply I assume that what fixed it for you was adding:

print csrf_field();

between the form tags. It makes sense to me since the problems only arise after a POST request.

I tried adding a similar line to one of my plugins but it did not work.

Do you know waht this function does exactly?

Thanks.

Edit:

Nevermind, managed to get it working, I just had a lot more forms than I thougth. I added the line to each of them and everything started working again.

@jpengenheiro2
Hello.
Can you show me what did you do?

@freedomwarrior,

You’ll need to insert print csrf_field(); between every form tag.

ex in PHP:

echo '<form method="post" name="some_user_search">';
# insert line below between form tags:
print csrf_field();
echo </form>;

ex in HTML:

<form method="post" name="some_user_search">
<!-- insert 3 lines below between form tags -->
<?php
print csrf_field();
?>
</form>

Hello again.
In vlan search plugin, there is only one form tag, I try to add print csrf_field() before </form> but it doesn`t help.

Add it like this it should work:
<?php
print csrf_field();
?>