Invalid or Missing CSRF Token. Try Going Back and Refresh the page after clearing the browser cache

This message is showing…

Invalid or Missing CSRF Token. Try Going Back and Refresh the page after clearing the browser cache…

LOG file::::

WARN - Slf4JLogger.log(41) |2022-01-15T18:11:36,246| Failed to restore the auto commit to true [INFO] Started o.e.j.m.p.JettyWebAppContext@73971965{OpenMRS,/openmrs,file:///D:/Office%20Projects/temp/mrs/openmrs-core/webapp/src/main/webapp/,AVAILABLE}{file:///D:/Office%20Projects/temp/mrs/openmrs-core/webapp/src/main/webapp/} [INFO] Started ServerConnector@7c385f68{HTTP/1.1, (http/1.1)}{0.0.0.0:8080} [INFO] Started @39152ms [INFO] Started Jetty Server [INFO] Initializing Spring DispatcherServlet ‘openmrs’ WARN - OpenmrsJspServlet.rescanTldsIfNeeded(56) |2022-01-15T18:11:43,930| Rescanning TLDs [INFO] Warning: No org.apache.tomcat.JarScanner set in ServletContext. Falling back to default JarScanner implementation. [INFO] At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. [INFO] Initializing Spring StaticDispatcherServlet ‘openmrs_static_content’ ERROR - Log.execute(73) |2022-01-15T18:11:52,129| potential cross-site request forgery (CSRF) attack thwarted (user:, ip:[0:0:0:0:0:0:0:1], method:POST, uri:/openmrs/ms/legacyui/loginServlet, error:Required Token is missing from the Request) WARN - CsrfGuardFilter.logInvalidRequest(136) |2022-01-15T18:11:52,139| Invalid request: URI: ‘/openmrs/ms/legacyui/loginServlet’ | Remote Address: ‘[0:0:0:0:0:0:0:1]’ ERROR - Log.execute(73) |2022-01-15T18:15:23,813| potential cross-site request forgery (CSRF) attack thwarted (user:, ip:[0:0:0:0:0:0:0:1], method:POST, uri:/openmrs/ms/legacyui/loginServlet, error:Required Token is missing from the Request) WARN - CsrfGuardFilter.logInvalidRequest(136) |2022-01-15T18:15:23,814| Invalid request: URI: ‘/openmrs/ms/legacyui/loginServlet’ | Remote Address: ‘[0:0:0:0:0:0:0:1]’

1 Like

i’m getting the same error

@richa09 and @rayhanshuvo1994 kindly clear the browser cache and login again.Feel free to share the output.

1 Like

@jwnasambu this helps except for the case when I have to create a new patient, program, or any other entity. While saving a new patient, this appears every time even after clearing the cache.

TRY refreshing your work and try again

@josephkagimu1 refreshing didn’t work

Can you share the server side log via pastebin.com?

@dkayiwa this is what I’m getting while creating a patient: pastebin

@rayhanshuvo1994 were you able to resolve this?

In your openmrs application data folder, look for a file named csrfguard.properties and change the value of the property named org.owasp.csrfguard.Enabled to true. Then restart OpenMRS.

@dkayiwa this doesn’t help. It was already true.

Sorry, i meant changing it to false

@dkayiwa this didnt help. Please have a look on my last comment at https://talk.openmrs.org/t/javascript-error/35603/8

In which folder is your csrfguard.properties?

@dkayiwa path to csrfguard.properties is openmrs-core/webapp/src/main/webapp/WEB-INF/csrfguard.properties

Your application data folder is where your runtime properties file is. Overriding OpenMRS Default Runtime Properties - Documentation - OpenMRS Wiki

You could also get it under Local repository from your equivalent of this page: Login

2 Likes

Thanks, it worked for me.

Am using refApp QA server to run the selenium-cucumber test for OCL Subscription feature. When I run npm run refapp2OpenConceptLab this is the error that is displayed on my terminal Deniss-Air:qaframework-bdd-tests juliet$ npm run refapp2OpenConceptLab> open - Pastebin.com and on the server side the error is displayed on the snapshot below. Am firefox as my browser to run the tests.

cc @kdaud , @sharif, @irenyak1, @mherman22, @dkayiwa , @ibacher Kind help please!

@jwnasambu update your branch with the latest changes from master. @dkayiwa fixed the issue at Adding support for CSRF tokens on platform 2.6 · openmrs/openmrs-contrib-qaframework@13e8266 · GitHub

Sure @jwnasambu just follow what @kdaud has advised. It was an issue that was fixed.