-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[Bug]: \OC::$server->getSession()->set('key', 'value') not saved #34935
Comments
Which NC version? |
24.0.6 |
You are probably using @juliushaertl do you have an idea why we are using the in memory session handling? |
The only scenario I would have in mind is if your call to getSession is actually taking place before the initSession call of Nextcloud. Line 418 in 11bedf1
Maybe you could add some logging to that to see if that is the case. Otherwise maybe you can provide the link to where the setSession in your apps code doesn't take effect, then I could have a quick look. |
The code is executed after the App Controller is called.
Here is the code block (with ocSession disabled): |
You may need to add the |
Well that is a problem. |
But why would search need to write the session? |
Because of the horrible Impersonate app. My SnappyMail app has an automatic login system. When doing a unified search or open the app, it tries to login.
Now the impersonate app is used and you impersonate someone:
To prevent this, i want to:
If the impersonate app properly triggers the |
I know that you want to close the session immediately. However, with simultaneous requests there are issues:
As this issue is always there, a different approach to sessions could be written.
|
Ok, so for Nextcloud 25 there would be a way to reopen the session with #32162 Now I don't have much insight into the impersonate app but with the described behavior I would imagine this also has all kind of issues with external storages where the login data is stored in the session and probably other session-related cases. Maybe @blizzz has any further insight as the main contributor to the impersonate app? |
Yes that would be better. As for Nextcloud my approach for sessions might be easy to implement to improve #32162 class Internal extends Session {
/**
* @param string $name
* @throws \Exception
*/
public function __construct(string $name) {
set_error_handler([$this, 'trapError']);
$this->invoke('session_name', [$name]);
try {
$this->startSession();
$this->invoke('session_abort'); // ADDED, close immediately
} catch (\Exception $e) {
setcookie($this->invoke('session_name'), '', -1, \OC::$WEBROOT ?: '/');
}
restore_error_handler();
if (!isset($_SESSION)) {
throw new \Exception('Failed to start session');
}
}
public function set(string $key, $value) {
// ADDED
$closed = $this->sessionClosed;
$closed && $this->startSession(); // reopen() ?!?
// $closed && $this->invoke('session_reset'); // possible? no idea
// $this->validateSession();
$_SESSION[$key] = $value;
// ADDED
$closed && $this->close();
} This approach has more IOPS when setting multiple. This way the session:
This would also solve my problem if the Impersonate (or other app) provides similar issues. |
Oh never mind my response. I looked at the first code but the real solution was later on in the thread. I will use that if Impersonate can't solve this. |
Bug description
My app is trying to set a custom session value using. But
NULL
is always returned.Steps to reproduce
Expected behavior
Return 'value' instead of
NULL
Installation method
Community Manual installation with Archive
Operating system
RHEL/CentOS
PHP engine version
PHP 7.4
Web server
Apache (supported)
Database engine version
SQlite
Is this bug present after an update or on a fresh install?
Fresh Nextcloud Server install
Are you using the Nextcloud Server Encryption module?
Encryption is Enabled
What user-backends are you using?
Configuration report
List of activated Apps
Nextcloud Signing status
Nextcloud Logs
Additional info
The text was updated successfully, but these errors were encountered: