mirror of
https://github.com/prasathmani/tinyfilemanager.git
synced 2026-04-26 10:55:56 +03:00
[GH-ISSUE #1282] "Invalid Token" Error When Saving Files in TinyFileManager v2.6 #825
Labels
No labels
Feature
Feature
Is It Really an Issue?
Need More Info
Request
Security
bug
duplicate
enhancement
enhancement
help wanted
invalid
pull-request
question
suggestion
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tinyfilemanager#825
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
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 @smalos on GitHub (Feb 14, 2025).
Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1282
I'm encountering an issue with TinyFileManager v2.6. Logging in and opening files work as expected, but attempting to save a file results in an "Invalid Token" error. This issue did not occur in version 2.4.7.
Configuration Details:
I am using the following configuration:
To debug, I added a simple logMessage() function to log the CSRF token. I observed that the token changes with every action in TFM, which might be expected behavior.
Here’s the relevant section of the code:
However, the verifyToken() function fails, meaning:
hash_equals($_SESSION['token'], $token)returns false.
Observations:
It seems like the CSRF token is not being correctly passed to the server before saving the file.
The issue is new in v2.6—it did not occur in v2.4.7.
Every action in TinyFileManager seems to generate a new token.
Expected Behavior:
Saving a file should not trigger an "Invalid Token" error if the session token is valid.
Any insights on why hash_equals($_SESSION['token'], $token) fails in v2.6 but worked in v2.4.7 would be greatly appreciated.
Could this be related to FM_EMBED mode, or has there been a change in how CSRF tokens are handled?
@prasathmani commented on GitHub (Feb 14, 2025):
thanks for reporting, i'll check it out.
@smalos commented on GitHub (Feb 15, 2025):
I think the issue lies here: For FM_EMBED, no session is created as far as I have seen, which is why the token is generated again and again with every click:
As a quick test has shown, the aforementioned error is no longer displayed if a session is also started for FM_EMBED.
(There might be other ways to solve the issue of course)
But I’m not sure why the whole session initialization block is omitted at all for FM_EMBED here:
@smalos commented on GitHub (Feb 24, 2025):
Is there any reason not to use sessions in embedded mode as well? Someone probably once decided they weren't needed.