mecha-cms / mecha

Minimalist content management system.

Home Page:https://mecha-cms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prevent HTML Prefetch, Preload, Prerender (and The Like) From Invalidating the Form Tokens

taufik-nurrohman opened this issue · comments

Screenshot from 2020-05-01 20 29 09

Form tokens are updated on every page visits. Adding HTML5 prefetch, preload and prerender features causes the token values to be refreshed in the background. Need to find a way to detect if current page was accessed in the background and so we could disable the token refresh.

Possible Solutions

  • Refresh the token only if it is accessed from the same URL.
  • Token refresh should be made limited to the current URL only. So, refreshing token on the other pages would only update token values for that pages.
  • Refresh the token only after form submission.
  • Refresh the token after certain time-out. 👍
  • Detect response header specific to prefetching from all browsers. 👎

Fixed by 8aad7ca

public static function token($id = 0, $for = '1 minute') {