Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank page with "Invalid csrf token." #14167

Closed
2 of 7 tasks
DuckDuckWhale opened this issue Dec 28, 2020 · 16 comments · Fixed by #14937
Closed
2 of 7 tasks

Blank page with "Invalid csrf token." #14167

DuckDuckWhale opened this issue Dec 28, 2020 · 16 comments · Fixed by #14937
Labels

Comments

@DuckDuckWhale
Copy link
Contributor

  • Gitea version (or commit ref): 1.13.0
  • Git version: 2.25.1
  • Operating system: Ubuntu Server 20.04
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Haven't tried
  • Log gist: N/A

Description

When clicking buttons or adding comments in issues I often see a blank page saying Invalid csrf token., which I had to work around using a refresh and a re-click, which has problems such as losing text already typed up in the comments. This could be related to me using a lot of tabs.

Issues that this might be related to are:

@lunny lunny added the type/bug label Dec 28, 2020
@lunny
Copy link
Member

lunny commented Dec 28, 2020

csrf token has an expired time. Most time it occurred because stay in an input page too long.

@lunny
Copy link
Member

lunny commented Dec 28, 2020

The CSRF token expired time should larger than session expired time. Then if you click the submit button, you will be redirected to a Gitea login page but not returned invalid csrf token.

@DuckDuckWhale
Copy link
Contributor Author

That's strange... After how long does it expire? I have just encountered it again when I opened a lot of Gitea tabs and waited for only about an hour.

@lunny
Copy link
Member

lunny commented Jan 1, 2021

That's wired. CSRF expired time is one day.

@DuckDuckWhale
Copy link
Contributor Author

DuckDuckWhale commented Jan 6, 2021

Encountered this again (400 Bad Request with Invalid csrf token but when saving a comment, in which case after the refresh the typed up comment disappeared so it might lead to small scale data loss which is bad), I think this page lived less than a day as well.

@somera
Copy link

somera commented Jan 6, 2021

That's wired. CSRF expired time is one day.

Is this a new feature in 1.13.x? I didn't get it before 1.13.x.

And if it expired, why the browsing is working? I get the error only when I start import new mirror:

@lakostin
Copy link

Have the same problem.

@zeripath
Copy link
Contributor

zeripath commented Mar 6, 2021

CSRF is only checked on POST so GETs will not affect it.

@lafriks
Copy link
Member

lafriks commented Mar 9, 2021

Could it be related to token strict attribute?

@kevung
Copy link

kevung commented Mar 23, 2021

I encounter the same problem, on version 1.13.0+rc1. I have only one Gitea tab open and the "Invalid csrf token" page appears imediately after I try to comment and review a Pull request. (for me, no need to wait an expire time to see the problem)

@JulianOrteil
Copy link

Encountering the same scenario as @kevung as well on 1.13.6 for Windows. What do you guys need from us since @CL-Jeremy says you need more information in the linked PR?

@kevung
Copy link

kevung commented Mar 25, 2021

Hello everybody,
I migrated today to Gitea 1.14.0+rc2, and I could not reproduce the problem :) I could smoothly review pull requests. It seems to have been fixed somehow. Perhaps, it is wise to confirmation from other people using 1.14 before resolving this issue.
Thanks to the Gitea team for the amazing work.

@lunny
Copy link
Member

lunny commented Mar 25, 2021

v1.14 changed web framework from macaron to chi and modified the old csrf middleware. But I cannot ensure we fixed that.

@josch
Copy link

josch commented Apr 25, 2021

I just created a fresh installation of v1.14.1 and am seeing the Invalid csrf token. message every time there is a POST request. Interestingly this only happens with firefox 86 but not with chromium 89. In contrast to the other reports, refreshing the page does not fix this.

EDIT: what fixed the problem for me was to clear all cookies and site data in the firefox preferences.

@xergio
Copy link

xergio commented May 2, 2021

@josch solution was the key for me, I had some cookies from a previous instalation of gogs, then installed gitea in the same domain and some cookies remained (maybe the one called _csrf) and was doing something bad.

@kevung
Copy link

kevung commented May 4, 2021

Hello, I am encountering the problem "Invalid csrf token." when I try to start the Timer on an issue. I use Gitea Version: 1.14.0+rc2

@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants