Files
c36e2f4fe1 Bugfix session 2026 10 15 (#1267)
* Guard payment method counters against missing keys in dashboard stats

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>

* fix(notifications): a custom header value can no longer end the notification run

A webhook or ntfy "custom headers" field that is not valid JSON ends the
scheduled run with a fatal error, and everything after it is not notified:

    Fatal error: Uncaught TypeError: curl_setopt(): The CURLOPT_HTTPHEADER
    option must have an array value in .../sendnotifications.php:931
    #0 ... curl_setopt(Object(CurlHandle), 10023, NULL)

The job checks whether the field has something in it, decodes it as JSON, and
passes the result to cURL without looking: json_decode() answers null for
anything it cannot read, and on PHP 8 curl_setopt() with null is a TypeError
rather than a warning. In a cron job that is the end of the run, so the
channels after the webhook block and every account after this one go without
their notification too. It is reported from a real installation in #1212, where
it happened daily and nothing on any screen said so.

The Test button next to the same field reports success throughout, because it
decodes first and only sets the headers when the result is usable. That is why
the field is not where anybody looks.

Five readers, four readings:

* sendnotifications.php decoded the field as JSON and passed the result
  straight to cURL, the crash above.
* sendcancellationnotifications.php split the same field into lines instead of
  decoding it, so a value that worked there was a value that ended the other
  run, and the other way round.
* Both ntfy blocks decoded it and mapped key => value into "Name: value". The
  one in sendcancellationnotifications.php does so without checking the decode,
  which is the same fatal one array_keys() further along.
* testwebhooknotifications.php decoded it and used the result only when it was
  non-empty, which is the behaviour that hides the defect.

They now share one reader, includes/webhook_headers.php. It accepts the two
shapes that were already in use: a JSON object, the shape the ntfy blocks
documented by example, and a JSON array of complete header lines, which is what
a value handed straight to cURL had to be. Anything else yields no headers, so
a typo in an optional field costs the headers rather than the notifications.

tests/cases/webhook_headers_test.php covers both shapes, every value that is
not JSON, the entries that cannot become a header line, and that each of the
four readers goes through the one function. Checked against the defect: with
the old decode restored in sendnotifications.php, the last of those fails.

* fix(push): do not let a second first-use replace the VAPID keypair

webpush_get_vapid_keys() writes a freshly generated keypair with an
unconditional UPDATE. Two requests that find the columns empty at the same
moment - the settings page of one household member and the notification cron,
say, or two people opening the settings page after an upgrade - each generate a
pair and each write it, and the second write wins.

That is not a lost keypair, it is a lost channel. A push subscription is bound
to the applicationServerKey the browser saw when it subscribed: every device
that had already subscribed with the first key is answered 403 by its push
service from that moment on. 403 is not 404/410, so the cron prunes nothing,
the settings page still lists the device, and the notifications simply stop
with nothing anywhere to say why. The same window exists on a first visit to
the settings page while the cron is running, because the page generates the
pair too.

The write is conditional now, and the row is read back afterwards: when the
UPDATE matched nothing, the pair that matters is the one already stored, so the
second caller signs with the key the browsers actually know rather than with
its own.

The two steps are separated into webpush_store_vapid_keys() so the property can
be tested without a second process: storing one pair and then offering another
answers with the first, and leaves the row holding the first. With the
unconditional UPDATE restored, that case fails on all three of its assertions.

* ci: stop building an image ref from an empty variable on fork pull requests

Every pull request from a fork fails all three build jobs:

    ERROR: failed to parse ref "docker.io/": invalid reference format

The outputs line names the image as ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},
and IMAGE_NAME is vars.DOCKERHUB_TAG, which is not available to a workflow run
triggered by a pull request from a fork. The name is therefore "docker.io/",
buildx refuses it, and the build ends before it has compiled anything - even
though push is already false for these runs, so nothing was going to be pushed
under that name in the first place.

A pull request run needs the image built, not named: type=cacheonly builds and
populates the layer cache without an image reference. Everything downstream
already skips these runs - the two digest steps and the merge job are guarded
by github.event_name != 'pull_request' - so nothing else changes, and runs on
main and on tags keep the reference and the push they had.

This is the change gwpreston made in #1213. It is sent on its own because it is
unrelated to the feature that pull request carries, and until it lands every
contributor's checks are red for a reason that has nothing to do with their
change.

Co-authored-by: Gareth Preston <gareth.preston@propertypal.com>

* fix(api): answer for the settings writes that were made, not the ones attempted

api/settings/set_settings.php contradicts itself. The settings UPDATE near the
end reads its own result and answers "Database error" when it fails. The four
writes above it discard theirs — the delete and insert that replace the custom
css, and the pair that replace the custom colours — and the file finishes with
success: true either way.

The consequence is not a lost setting. It is two rows where there should be one:
a delete that fails while the insert succeeds leaves both, and every reader of
these tables selects by user_id and takes the first row it is handed. Which of
the two that is, is decided by nothing. So the page can go on serving the css or
the theme this request was meant to replace, after the API has said it was saved.

All four are read now, and a failure answers in the shape this file already uses
a few lines further down.

Note what this does to the delete-before-replace gate. That gate deliberately
leaves a pair alone when neither half is read — adding a check to the delete
alone would not make the file honest, and the gate would then be calling it
fixed. Reading both is what brings these two pairs under it: after this change
they are governed, and an edit that drops either check fails there as well as in
the new case.

tests/cases/settings_api_writes_test.php checks the whole file rather than the
four lines that had it, so a fifth write added later is caught by the same rule.
It also demonstrates the outcome against the real schema: a trigger refuses the
delete — which is how a locked database or a read-only disk looks from here,
since SQLite reports all of them through the statement result and through
nothing else — and the second row goes in. Verified by reverting the file to
what it replaces (both cases fail, naming lines 87, 92, 137 and 144) and by
reverting only the css half.

* fix(backup): remove the archive even when the download is abandoned

endpoints/db/backup.php builds a zip of the database and every uploaded file in
the system temp directory, streams it to the admin who asked, and deletes it on
the line after readfile().

A download the browser abandons - a closed tab, a lost connection, a proxy
timing out - ends the script inside readfile(). The line below it never runs,
and a complete copy of the installation stays in the temp directory until
something else clears it. Every retry leaves another one.

The removal is registered with register_shutdown_function() before the stream
starts, so it runs on that path too. The two branches that give up before
streaming keep their own unlink and their own message: the shutdown function is
an answer for the path that had none, not a replacement for the ones that do.

The comment at the top of that file is about the archive not being
web-accessible any more. This is the smaller version of the same thing: a file
that should live for the length of one request instead living until a reboot.

The two cases pin the shape rather than the behaviour, and say so. Proving the
removal for an abandoned download would need an HTTP stream cut in the middle,
which the harness has no way to do.

* fix(oidc): consume the state on disk before the token exchange, not after it

Reported as #1239, with the measurement in it: a browser on a mobile connection
sent the OIDC callback, abandoned it after 61 ms, and sent it again. Both
requests carried the same authorization code, which a provider redeems once.
The second attempt was answered invalid_grant, and the person was shown

    OIDC token exchange failed. Check the Wallos server logs for details.

for a login that had in fact succeeded.

checksession.php validates the state and removes it, and the removal lives only
in memory: PHP writes the session at the end of the request, and oidc_login.php
calls session_regenerate_id(true) before that, which deletes the file the
removal would have been written to. A second request carrying the same callback
waits on the session lock while the first one talks to the provider, is then
handed the state as it stood before, passes hash_equals, and redeems the code
again.

The session is now written out and reopened as soon as the state is consumed,
in both places that consume it - the refusal path as well, where a state left
in memory would be checked again by a retry of a callback that was already
refused.

The behaviour is in oidc_persist_session() rather than inline so a test can
drive it: the case spawns a request that consumes the state and then holds for
a second and a half, the way the exchange does, and reads the session file from
outside while that is running - which is exactly what a second callback is
handed. Emptying the function makes it fail.

What this does not address is the other half of #1239: the session the first
request established has an id the browser never received, because the response
carrying it went to a connection that was already gone. After this change the
second callback no longer breaks the code redemption, but the person still has
to sign in again. That half touches the sign-in path more widely and is worth
deciding separately.

* fix(i18n): fill in missing Japanese translations

Add the 22 keys that exist in en.php but not ja.php, and keep the
Japanese file in the same key order as the English source. Also
correct a few strings that were untranslated or said the wrong thing.

Co-authored-by: akinechan <weezer.and.you@gmail.com>

* fix: tolerate missing subscription relations in list views

* fix: preserve layout classes when changing the theme

* style: keep CRLF line endings in checksession.php

* fix(webhook): keep newline-separated headers working and strip CR/LF from values

* fix(export): prefix CSV with UTF-8 BOM so currency symbols open correctly (#863)

* fix(webhook): send JSON payloads with a JSON Content-Type (#990)

* fix(oidc): send id_token_hint and client_id on RP-initiated logout (#891)

* fix(subscriptions): sort by price using the converted main-currency value (#861)

* fix(export): tolerate subscriptions with no payer, payment method or category

* fix(subscriptions): rank price sort by converted value inside the list printer (#861)

* chore: bump version to 5.8.4 and add BUGFIXSESSION.md

* chore: ignore AI assistant files in git and docker builds

---------

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Co-authored-by: Sai Asish Y <say.apm35@gmail.com>
Co-authored-by: thorstenhornung1 <134448024+thorstenhornung1@users.noreply.github.com>
Co-authored-by: Gareth Preston <gareth.preston@propertypal.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: akinechan <weezer.and.you@gmail.com>
Co-authored-by: Pengusto <106893073+pengusto@users.noreply.github.com>
2026-10-17 15:09:07 +02:00

89 lines
2.8 KiB
PHP

<?php
require_once 'includes/connect.php';
require_once 'includes/oidc_settings.php';
require_once 'includes/oidc/logout_url.php';
$secondsInMonth = 30 * 24 * 60 * 60;
if (session_status() === PHP_SESSION_NONE) {
session_set_cookie_params([
'lifetime' => $secondsInMonth,
'httponly' => true,
'samesite' => 'Lax'
]);
session_start();
}
$logoutOIDC = false;
// Check if user is logged in with OIDC
if (isset($_SESSION['from_oidc']) && $_SESSION['from_oidc'] === true) {
$logoutOIDC = true;
$oidcConfiguration = wallos_get_effective_oidc_configuration($db);
$oidcSettings = $oidcConfiguration['settings'];
$logoutUrl = $oidcSettings['logout_url'] ?? '';
$oidcIdToken = $_SESSION['oidc_id_token'] ?? null;
}
// get token from cookie to remove from DB
//
// $userId is not assigned anywhere in this file, so the statement bound null
// and "user_id = null" matched no row: every logout left a usable remember-me
// token behind, and the next request signed the browser straight back in. On a
// shared machine that is the whole point of logging out.
//
// The token identifies the row on its own — it is 32 random bytes and the
// credential itself — so scoping the delete by user adds nothing and was the
// only reason this failed. The result is checked because a delete that could
// not run and a token that was not there are different outcomes.
if (isset($_SESSION['token'])) {
$token = $_SESSION['token'];
$sql = "DELETE FROM login_tokens WHERE token = :token";
$stmt = $db->prepare($sql);
if ($stmt === false) {
error_log('Wallos: could not prepare the login token deletion on logout; '
. 'any browser still holding the cookie stays signed in');
} else {
$stmt->bindParam(':token', $token, SQLITE3_TEXT);
if ($stmt->execute() === false) {
error_log('Wallos: could not revoke the login token on logout; '
. 'any browser still holding the cookie stays signed in');
}
}
}
$_SESSION = array();
session_destroy();
$cookieExpire = time() - 3600;
setcookie('wallos_login', '', $cookieExpire);
$db->close();
if ($logoutOIDC && !empty($logoutUrl)) {
header('Location: ' . oidc_build_logout_url(
$logoutUrl,
$oidcSettings['redirect_url'] ?? '',
$oidcIdToken,
$oidcSettings['client_id'] ?? ''
));
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<script>
async function clearAndRedirect() {
if ('caches' in window) {
await caches.delete('pages-cache-v1');
}
sessionStorage.removeItem('sw_prefetched');
window.location.href = '.';
}
clearAndRedirect();
</script>
</head>
<body></body>
</html>
<?php
exit();