Skip to content

Commit ae8dada

Browse files
Merge pull request #19168 from nextcloud/backport/19163/stable35
[stable35] fix(TalkSession): fall back to known tabId for requests without header
2 parents 367d451 + ca2c7b0 commit ae8dada

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

lib/TalkSession.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,23 @@ protected function getValues(string $key): array {
113113
}
114114

115115
protected function getValue(string $key, string $token, bool $useTabId = true): ?string {
116-
$token .= $useTabId ? $this->getTabId() : '';
117116
$values = $this->getValues($key);
118-
return $values[$token] ?? null;
117+
$tabId = $useTabId ? $this->getTabId() : '';
118+
119+
if ($tabId !== '') {
120+
return $values[$token . $tabId] ?? null;
121+
}
122+
123+
// Requests without the tab id header (e.g. an <img> tag) can not tell the
124+
// tabs apart, so fall back to any value stored for the token
125+
foreach ($values as $tokenKey => $value) {
126+
$tokenKey = (string)$tokenKey;
127+
if ($tokenKey === $token || str_starts_with($tokenKey, $token . self::TAB_ID_SEPARATOR)) {
128+
return $value;
129+
}
130+
}
131+
132+
return null;
119133
}
120134

121135
protected function setValue(string $key, string $token, string $value, bool $useTabId = true): void {
@@ -142,7 +156,7 @@ protected function removeValue(string $key, string $token, bool $useTabId = true
142156
// This request does not support tabId, so we need to destroy all related data
143157
foreach ($values as $tokenKey => $value) {
144158
$tokenKey = (string)$tokenKey;
145-
if (str_starts_with($tokenKey, $token)) {
159+
if ($tokenKey === $token || str_starts_with($tokenKey, $token . self::TAB_ID_SEPARATOR)) {
146160
unset($values[$tokenKey]);
147161
}
148162
}

0 commit comments

Comments
 (0)