mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-13 02:57:44 -05:00
TFA broken after update from 1.14.x to 1.15.x. #7794
Closed
opened 2025-11-02 07:36:38 -06:00 by GiteaMirror
·
14 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2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v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#7794
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Kusoneko on GitHub (Sep 2, 2021).
[x]):Description
After updating from 1.14.6 to 1.15.0 (presumably when the issue happened as I didn't try login in then and then from 1.15.0 to 1.15.1, I couldn't login with either my scratch code or my TFA TOTP generated code. I had to manually go delete my entry in my MySQL database in the two_factor table to be able to login again. Then I went to set it up again, and using both a desktop TOTP generator and copying the secret into it, as well as using the QR code for a mobile TFA app and made both generate the 6-digit codes, and both generate the exact same codes and switch codes at the exact same time, however, the Enroll into TFA page on my gitea instance is claiming that the new passcodes generated by both using the secret it provides is invalid somehow. I'm assuming there's some form of breaking change that happened with TFA in between 1.14.x and 1.15.x otherwise this wouldn't make any sense, despite my not seeing any TFA related stuff in the changelog for the breaking changes of 1.15.0. I'm essentially wanting to find out what I need to do to fix it. So far I haven't changed anything when building the new versions, only built them and then restarted gitea via
# systemctl restart gitea. If there is any manual changes I need to do to fix this in config files or whatever, I would appreciate having them noted somewhere.Screenshots
Not Applicable
@zeripath commented on GitHub (Sep 2, 2021):
Did you backup and restore using gitea dump? (I'm suggesting this as a potential cause - not a solution)
@Kusoneko commented on GitHub (Sep 2, 2021):
No, I did not. If I should have how do I fix this now? Note that besides TFA everything else appears to work fine on both the web app and using git commands locally and pushing/pulling from the gitea instance, so I might have gotten off lightly if that's something that should be done before upgrading versions like this.
@techknowlogick commented on GitHub (Sep 2, 2021):
@zeripath could this be related to secret not being set?
@Kusoneko commented on GitHub (Sep 2, 2021):
I'd doubt it personally, if we're talking about my app.ini file, I just did
# cat /etc/gitea/app.ini | grep SECRETand I have LFS_JWT_SECRET, SECRET_KEY and JWT_SECRET set. RECAPTCHA_SECRET, HCAPTCHA_SECRET and MINIO_SECRET_ACCESS_KEY unset.@zeripath commented on GitHub (Sep 2, 2021):
that would explain it failing only once I think.
I'm a bit stumped. The usual failure for TOTP is something to do with time offsets but I don't understand why it would have worked previously and not now.
There's nothing that immediately comes to mind as a possible cause - except maybe - just maybe some weird cookie issue.
I can't immediately replicate it here, and so the only thing I can think of is for you to add extra logging and build gitea.
@Kusoneko commented on GitHub (Sep 3, 2021):
I'm not sure what you mean by building gitea after adding extra logging, I just changed to log level to Debug in app.ini and restarted gitea, and couldn't find anywhere in the docs a build setting to use to enable further logging, but I'm missing something clearly. First, the log only contains the following for TFA stuff that I can see:
Similarly, when looking from the dev tools of the browser, the TFA enroll page indeed starts off with a 302 followed by a 200, and when clicking the Verify button, it reloads but shows an Invalid passcode message. Nothing new seems to appear in the logs.
I did notice however that no matter how many time I leave and come back to the TFA enroll page, the TOTP secret shown on the page is always exactly the same secret (and the QR is likely the same since it gives my phone app the same TOTP secret as well), implying the problem is potentially with it not showing the right secret rather than TFA by itself not working. Hopefully that'll help a little with figuring out what's wrong.
A bit unrelated, but while we're here, I looked at the start of the logs and I'm seeing the following 2 Errors at the start:
and the following ton of warnings right after the PING DATABASE thing:
Are these errors and warnings fixable?
Thank you!
@zeripath commented on GitHub (Sep 3, 2021):
As per our FAQ it is safe to ignore the table warnings although
gitea doctor recreate-tableshould make them go away.[E] Missing required keys from markup.sanitizer.1. Must have ELEMENT and ALLOW_ATTR or ALLOW_DATA_URI_IMAGES defined!This implies that, like many people, you have copied app.ini.sample/app.example.ini straight across as your app.ini despite the very large warning at the top of that file NOT to do that. (We have had to comment almost the whole file out in 1.15+ because of this.)
You need to seriously simplify your app.ini dropping whole sections from it that you have not explicitly set. My own app.ini is 75 lines long and really that is still too long.
These app.ini issues aren't obviously the cause of the problem (except where maybe you've incorrectly overconfigured your cookies?)
Looking at your logs I see that the IP address you are posting from to appears to be flipping from 127.0.0.1 to [::1] which is concerning that you might be associated with different sessions etc.
You've sanitized the session id away so I can't check that theyre the same and you've not given me the logs from the GET before the enroll POST so I can't check that either. We need to see a little more of the interaction before the POST.
It's helpful to double check if the issue is a browser specific one - i.e. are there multiple weird cookies on your browser that need to be erased.
You haven't told us whether there's a reverse proxy involved or if Gitea is mounted on a suburl. Are you definitely accessing gitea by its ROOT_URL - maybe the cookies aren't being passed down - the session id being the same should assert that.
Regarding additional logging:
You asserted that debug logs were not helpful - although it does appear that they may help shed further light on this issue so follow the instructions given in issue proforma and give us those logs. My suggestion about us adding extra logging was that we would need to compile in some extra logging at certain places.
Give us the logs as per https://docs.gitea.io/en-us/logging-configuration/#debugging-problems sanitising only the minimum and asserting where things are the same if you've sanitized them away.
Explain your setup, e.g. reverse proxy or not, how are you running gitea, what is your systemd unit file, what version of mysql/mariadb.
Show us your app.ini - you can send me the unsanitised one on discord if you message me directly.
Check if on private browsing or different browser if things work. The problem may be cookie related.
@Kusoneko commented on GitHub (Sep 3, 2021):
Thanks, that fixed the errors and most of the warnings, I assume the last 2 that gitea doctor didn't fix, where it says the table's field should be int unsigned and that it's currently int(10) unsigned is far from the end of the world.
Well, I did configure them a bit, but I just swapped it from storing the sessions from file mode to memory mode, and deleted all my cookies for the instance to see if something changed, indeed, the TOTP secret has changed afterwards, but it's sticking to the new secret now, and still refusing codes. This is a really odd issue.
They were identical for that specific snippet.
Right, my gitea instance is configured to listen to localhost:3001 (unless I'm misunderstanding the app.ini comments), except for ssh requests which is actually using the git user and openssh's sshd. SSH works fine, so that's not the issue. The server is actually serving multiple (mostly personal) web apps and services, so to prevent port collision issues and all that, all of them are being run behind nginx as a reverse proxy (except for one or 2 webpages that nginx serves itself), unless they're not web apps and therefore don't require port 443/80 to be used without fiddling around with ports in a browser.
The results of
$ mysql --version:mysql Ver 15.1 Distrib 10.6.4-MariaDB, for Linux (x86_64) using readline 5.1SystemD service file: gitea.service
The logs after stopping gitea, removing all my cookies from my browser, then restarting gitea, while I go speedrun to the TFA enroll page are here: log.txt
The Session IDs were renamed id# and the CSRF Tokens token# with sed, so they should have the same number for all occurrences of each.
The app.ini configuration for the looks like this: app.ini
Note that I'm not sure in this app.ini file (which I did a quick cleanup of) what's left that is by default and thus can be removed and what isn't. I'm off to bed for now though, so I'll perhaps think about looking it up later.
Thanks.
EDIT: Moved the code snippets for each file to actual attachments to prevent a 30-meters long wall of text.
@wxiaoguang commented on GitHub (Sep 3, 2021):
A small question, have you checked your system time (running Gitea instance) is accurate and correct? You can check your system time here: https://time.is . Or check time by google:
@Kusoneko commented on GitHub (Sep 3, 2021):
That's odd, it's apparently off by a full minute, I'm not sure how to fix that though.
@wxiaoguang commented on GitHub (Sep 3, 2021):
You see, it's your system time's problem.
TOTP won't work correctly if the error between your server's time and client's time is greater than a few seconds.
The time window for a TOTP code is usually 30 seconds. The larger the error is, the more likely the OTP code will fail. When the error is greater than 30 seconds, the OTP code will always fail.
As long as you set your server's time to the correct time, the problem will disappear.
So it's not Gitea's bug 😊
@wxiaoguang commented on GitHub (Sep 3, 2021):
PS: Maybe the TOTP problem should be written into FAQ. I know many people use servers with wrong system time.
@zeripath commented on GitHub (Sep 3, 2021):
@wxiaoguang I meant to suggest timing but I was distracted by them saying it had previously worked but yes this would be consistent with that being the issue.
So I'm gonna close.
@Kusoneko commented on GitHub (Sep 3, 2021):
Just to confirm, I went and enabled and started systemd-timesyncd that was for some reason not enabled nor started, and tried again and this time it worked. Thank you everyone!