Skip to content

Instantly share code, notes, and snippets.

@InPermutation
Created March 29, 2013 18:13
Show Gist options
  • Select an option

  • Save InPermutation/5272528 to your computer and use it in GitHub Desktop.

Select an option

Save InPermutation/5272528 to your computer and use it in GitHub Desktop.
#chan
- return HttpResponse(simplejson.dumps(data), mimetype="application/json")
+
+ # The Django Session middleware helpfully adds 'Cookie' to the Vary header if request.session.accessed is true
+ # Firefox won't cache JSON if the response varies by cookie.
+ # Since we mark Cache-Control: private and max-age:60, the attack vector here is very very small:
+ # People on the same machine as the victim, who read the cache within 60 seconds
+ # So, let's fake out the session middleware to not send the Vary: Cookie header, just Vary: Accept-Encoding.
+ request.session.accessed = False
+
+ response = HttpResponse(simplejson.dumps(data), mimetype="application/json; charset=utf-8")
+ response['Vary'] = 'Accept-Encoding'
+ return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment