<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: POST to /splunkd/__raw endpoint returns CSRF validation failed in Monitoring Splunk</title>
    <link>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/418416#M3542</link>
    <description>&lt;P&gt;When logged into the Splunk Web GUI, Splunk sets a cookie called &lt;CODE&gt;token_key&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;When POSTing, PATCHing, DELETEing, etc. to a custom endpoint, you need to pass this token back by including the following headers in your request:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;X-Requested-With = XMLHttpRequest&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;X-Splunk-Form-Key = &amp;lt;the value of the token_key cookie&amp;gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This isn't documented anywhere, as far as I could tell.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jun 2018 17:46:13 GMT</pubDate>
    <dc:creator>sjodle</dc:creator>
    <dc:date>2018-06-04T17:46:13Z</dc:date>
    <item>
      <title>POST to /splunkd/__raw endpoint returns CSRF validation failed</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/418415#M3541</link>
      <description>&lt;P&gt;Hello, &lt;/P&gt;

&lt;P&gt;I have a confusing issue with the Splunk endpoint POST method execution. Every time I'm trying to send a GET request to my custom endpoint, everything works as expected. But when I am sending a POST request with the identical parameters and Cookies, the API returns a 401 status code and says: "Splunk cannot authenticate the request. CSRF validation failed.". I have no clue why this happens because the CSRF Token in the request is still the same token as the token in the GET request. Moreover the response of the GET request returns the identical CSRF cookie which is afterwards used again by the POST method.&lt;/P&gt;

&lt;P&gt;Using the API over the management port on 8089 works perfectly fine with GET and POST requests. This happens just with the &lt;EM&gt;/splunkd/__raw&lt;/EM&gt; webservice endpoint.&lt;/P&gt;

&lt;P&gt;Does anyone have an idea about what is causing this error?&lt;BR /&gt;
Thanks in advance!&lt;/P&gt;

&lt;P&gt;Request:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;POST /en-GB/splunkd/__raw/services/test_endpoint HTTP/1.1
Host: localhost:8000
Content-Length: 10
Origin: &lt;A href="http://localhost:8000" target="test_blank"&gt;http://localhost:8000&lt;/A&gt;
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
Content-Type: text/plain;charset=UTF-8
Accept: */*
Referer: &lt;A href="http://localhost:8000/en-GB/splunkd/__raw/services/test_endpoint?payload=Hello" target="test_blank"&gt;http://localhost:8000/en-GB/splunkd/__raw/services/test_endpoint?payload=Hello&lt;/A&gt;
Accept-Encoding: gzip, deflate
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: splunkweb_csrf_token_8000=XXX; session_id_8000=XXX; token_key=XXX; experience_id=XXX; splunkd_8000=XXX
Connection: close

Hello POST
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Response:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;HTTP/1.1 401 Splunk cannot authenticate the request. CSRF validation failed.
Date: Fri, 25 May 2018 07:02:13 GMT
Content-Type: text/xml; charset=UTF-8
X-Content-Type-Options: nosniff
Content-Length: 181
Vary: Cookie
Connection: Close
X-Frame-Options: SAMEORIGIN
Server: Splunkd

&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;response&amp;gt;
  &amp;lt;messages&amp;gt;
    &amp;lt;msg type="ERROR"&amp;gt;Splunk cannot authenticate the request. CSRF validation failed.&amp;lt;/msg&amp;gt;
  &amp;lt;/messages&amp;gt;
&amp;lt;/response&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 May 2018 07:20:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/418415#M3541</guid>
      <dc:creator>louisjannett</dc:creator>
      <dc:date>2018-05-25T07:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: POST to /splunkd/__raw endpoint returns CSRF validation failed</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/418416#M3542</link>
      <description>&lt;P&gt;When logged into the Splunk Web GUI, Splunk sets a cookie called &lt;CODE&gt;token_key&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;When POSTing, PATCHing, DELETEing, etc. to a custom endpoint, you need to pass this token back by including the following headers in your request:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;X-Requested-With = XMLHttpRequest&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;X-Splunk-Form-Key = &amp;lt;the value of the token_key cookie&amp;gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This isn't documented anywhere, as far as I could tell.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 17:46:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/418416#M3542</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2018-06-04T17:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: POST to /splunkd/__raw endpoint returns CSRF validation failed</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/508417#M4327</link>
      <description>&lt;P&gt;Thank you so much this was driving me crazy!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2020 01:01:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/508417#M4327</guid>
      <dc:creator>badarsebard</dc:creator>
      <dc:date>2020-07-10T01:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: POST to /splunkd/__raw endpoint returns CSRF validation failed</title>
      <link>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/742889#M10816</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":rocket:"&gt;🚀&lt;/span&gt; This solution still works in 2025! — rock solid.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Mar 2025 04:15:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Monitoring-Splunk/POST-to-splunkd-raw-endpoint-returns-CSRF-validation-failed/m-p/742889#M10816</guid>
      <dc:creator>amirul_alif</dc:creator>
      <dc:date>2025-03-28T04:15:17Z</dc:date>
    </item>
  </channel>
</rss>

