FlandreDaisuki / Patchouli

An image searching and browsing tool on pixiv
MIT License
80 stars 6 forks source link

CSRF Token Changes #52

Closed alexwh closed 4 years ago

alexwh commented 4 years ago

Describe the bug

Attempting to bookmark images on member.php pages (potentially others too), will show the heart icon, but upon refreshing not actually be bookmarked. Checking the console (see logs below), it seems the CSRF token fetching has been changed - it's now a JSON object under a <meta> tag with the ID meta-global-data, which is parsed and then removed before Patchouli loads (see screenshots).

Suggested fix would be something along the lines of adding the @run-at document-start userscript directive, snagging the token (e.g. JSON.parse(document.getElementById("meta-global-data").content).token), then waiting for the document to load to run the rest of the script. I didn't attempt this as I'm not familiar enough with the codebase to make a change this large.

Steps to reproduce

  1. Go to a member.php page
  2. Click on a heart on any image
  3. Refresh page
  4. See image has not actually been bookmarked

Screenshots

chrome_2019-12-14_18-55-36

Environment

Debug messages

``` Pixiv#tt getter vendors~spa.6fb6b11381dd681f798c.js:3630:257 Pixiv#fetch: error: ConnectionError: "400 Bad Request" ExtendableError moz-extension://6a21cb74-c8eb-4094-85a1-559e468d9cf2/Patchouli.user.js#6:324 ConnectionError moz-extension://6a21cb74-c8eb-4094-85a1-559e468d9cf2/Patchouli.user.js#6:328 fetch moz-extension://6a21cb74-c8eb-4094-85a1-559e468d9cf2/Patchouli.user.js#6:359 vendors~spa.6fb6b11381dd681f798c.js:3630:257 Pixiv#fetchJSON: error: TypeError: "resp is undefined" fetchJSON moz-extension://6a21cb74-c8eb-4094-85a1-559e468d9cf2/Patchouli.user.js#6:372 ```
FlandreDaisuki commented 4 years ago

@alexwh Thanks for the report 😊 I fixed this in v4.2.6 You can confirm it with a 👍 or close the issue directly

alexwh commented 4 years ago

Seems to be working now. Thanks for the quick fix!