<?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 Possible security bug in the web api auth example from gitbub in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Possible-security-bug-in-the-web-api-auth-example-from-gitbub/m-p/5103067#M1814</link>
    <description>&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I've cloned the code from: &lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://github.com/spotify/web-api-auth-examples" target="_blank" rel="noopener"&gt;https://github.com/spotify/web-api-auth-examples&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt; and possibly found some security bug - but please correct me and explain why I'm wrong if that is the case.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;State is set in /login route to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  var state = generateRandomString(16);
  res.cookie(stateKey, state);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then updated and checked in /callback route with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  var state = req.query.state || null;
  var storedState = req.cookies ? req.cookies[stateKey] : null
  if (state === null || state !== storedState) {&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As "state" is overwritten with the users incoming query.state, wouldn't that mean that if a users traffic was interrupted by a malicious user, they could just use whatever string they wanted in their query, as long as it corresponded to their cookie and overtake the connection? Why do you overwrite the state variable at all? Shouldn't it be kept the same as when assigned in the /login route and then used as a basis for comparison and security?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Jan 2021 15:16:08 GMT</pubDate>
    <dc:creator>alexlindgren</dc:creator>
    <dc:date>2021-01-03T15:16:08Z</dc:date>
    <item>
      <title>Possible security bug in the web api auth example from gitbub</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Possible-security-bug-in-the-web-api-auth-example-from-gitbub/m-p/5103067#M1814</link>
      <description>&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I've cloned the code from: &lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://github.com/spotify/web-api-auth-examples" target="_blank" rel="noopener"&gt;https://github.com/spotify/web-api-auth-examples&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt; and possibly found some security bug - but please correct me and explain why I'm wrong if that is the case.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;State is set in /login route to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  var state = generateRandomString(16);
  res.cookie(stateKey, state);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then updated and checked in /callback route with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  var state = req.query.state || null;
  var storedState = req.cookies ? req.cookies[stateKey] : null
  if (state === null || state !== storedState) {&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As "state" is overwritten with the users incoming query.state, wouldn't that mean that if a users traffic was interrupted by a malicious user, they could just use whatever string they wanted in their query, as long as it corresponded to their cookie and overtake the connection? Why do you overwrite the state variable at all? Shouldn't it be kept the same as when assigned in the /login route and then used as a basis for comparison and security?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 15:16:08 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Possible-security-bug-in-the-web-api-auth-example-from-gitbub/m-p/5103067#M1814</guid>
      <dc:creator>alexlindgren</dc:creator>
      <dc:date>2021-01-03T15:16:08Z</dc:date>
    </item>
  </channel>
</rss>

