alexa-remote-control: ERROR: no CSRF cookie received

Running v0.21b of the script, configured to use the REFRESH_TOKEN as obtained by the proxy login. Recently, the script has stopped working with the following output;

rapa-3:/config/scripts# ./alexa_remote_control.sh -a
cookie expired, logging in again ...
trying to get CSRF from handlebars
trying to get CSRF from devices-v2
ERROR: no CSRF cookie received
rapa-3:/config/scripts#

I have tried checking the refresh token by logging in via the proxy again. Interestingly, the token has changed - which I did not exepct - so I tried the new one. Same error.

Is there anything I can do to help diagnose this?

Many thanks.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21

Most upvoted comments

Yes, I saw that. Seems like a reasonable approach. Certainly v0.22 fixes my problem - can verify it works in Home Assistant 2024.4.1 using BusyBox shell.

Thanks for being so responsive and a pleasure to interact with - and thanks for giving your time to support such a useful utility.

You can go ahead and close this as fixed if you wish.

I now set a fixed validity of the cookies to “now + 86400s”. The session cookies always expired after exactly one day (for the past 2.5 years). Worst case we either ask for new cookies to often (once in 24 hours is a lot less than I’ve seen in other implementations), or don’t ask soon enough - in that case any request will fail and a new cookie will be asked for anyways.

Thanks for bearing with me 😄

Can you point me at the docker image you’re using.

This whole date parsing is really driving me crazy. All I wanted is actually not to hammer the Amazon auth service with unnecessary cookie-for-token exchanges. On the other hand the access token is only valid about 24h. So I might as well just have the entire cookie expire some time after that…

Ok, looks like you’re using amazon.co.uk… I don’t have an account there to test with.

Here’s what else you could try.

  • curl -s -v -b /tmp/.alexa.cookie https://alexa.amazon.co.uk/spa/index.html > /dev/null
  • curl -s -v -b /tmp/.alexa.cookie https://alexa.amazon.co.uk/api/strings > /dev/null

See if there is a Set-Cookie: csrf=… in the output. The curl commands alone won’t write the cookie to file.

When you login using the alexa_cookie app, you implicitly register a new device with your Amazon account (visible in My Apps and Devices). Hence the new refresh token.

The script uses a number of URLs to retrieve the CSRF cookie from. In order to check what’s happening please check the following:

  1. you should have a valid cookie file (modification date the last time you tried the script) at /tmp/.alexa.cookie which looks something like this
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_.amazon.de    TRUE    /       TRUE    1712275203      sess-at-acbde   "/Jpfa+/...."
#HttpOnly_.amazon.de    TRUE    /       TRUE    1712275203      at-acbde        "Atza|...."
.amazon.de      TRUE    /       TRUE    2121984003      x-acbde "________________________________
.amazon.de      TRUE    /       TRUE    2121984003      ubid-acbde      261-1234567-890...
.amazon.de      TRUE    /       TRUE    2121984003      session-id      260-1234567-890...

The file is missing a line:

.amazon.de      TRUE    /       FALSE   2027718004      csrf    1234567890

The file should be writable by the user running the script. Curl updates the cookie values automtically.

  1. The CSRF cookie is tried to be recieved at three different URLs please try them an see if there is a Set-Cookie: csrf=… in the output:
  • curl -s -v -b /tmp/.alexa.cookie https://alexa.amazon.de/api/language > /dev/null
  • curl -s -v -b /tmp/.alexa.cookie https://alexa.amazon.de/templates/oobe/d-device-pick.handlebars > /dev/null
  • curl -s -v -b /tmp/.alexa.cookie https://alexa.amazon.de/api/devices-v2/device?cached=false > /dev/null If you use a non-German Amazon account, please change the amazon.de string accordingly.

Please let me know what you see! Alex