mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix(server): the second pass over this branch's own fixes
An adversarial review of what had already landed here turned up three that
were wrong, and they are the reason for this commit.
The CSP change removed 'unsafe-eval', which is not leftover: heic-to's
libheif build initialises embind through new Function(), and without it every
iPhone .heic upload fails in the browser. 'wasm-unsafe-eval' alone was tried
once already and was not enough (93b51a0b). Put back, with the reason written
down this time and the test pinning it rather than its absence.
The idempotency in-flight guard never fired. finalize() runs when the
handler's observable completes, but Nest writes the response - and therefore
stores the row - several microtasks later, so the waiting request always woke
up before the row existed and ran the handler a second time. It releases from
the point the row is written now; finalize is the backstop for handlers that
answer another way. The test drove the two in the opposite order from Nest,
which is why it passed either way.
And the trip-scoping check treated an id that resolves to nothing like one
belonging to someone else. accommodation_id has no foreign key, so shortening
a trip's dates leaves a booking pointing at a gap - which update() has always
healed by clearing the link, and which would have become a permanent 400.
The rest: a reply to a soft-deleted chat message is refused and the create
path blanks the quote like the list path does; the ws-token buckets are keyed
by account rather than by IP, where every user behind one NAT shared a
ceiling; the weather and vacay caps read through the stream, since a chunked
response has no content-length to check; the Google host gate takes country
domains again; abandoned response bodies are cancelled instead of left to GC;
the boot failure prints its errno; and a share link that is not yours to read
now says so instead of reporting that the journey has none.
TICKETJSON gets a real repair: the in-place GLOB fix only helps installs that
have not run it yet, so an appended migration puts back the note text the
case-insensitive LIKE cut off, for rows where what it stored is not valid
JSON. A genuine receipt always parses, so it cannot be touched.
Wiki: the audit log records the IP Express resolves after TRUST_PROXY, not
the leftmost X-Forwarded-For entry a caller can write. That is the right way
round, but it means the hop count has to be accurate - said plainly in both
places now.
This commit is contained in:
@@ -4089,6 +4089,40 @@ function runMigrations(db: Database.Database): void {
|
||||
() => {
|
||||
db.exec("UPDATE trip_files SET filename = substr(filename, 7) WHERE filename LIKE 'files/%'");
|
||||
},
|
||||
// Give back the notes the TICKETJSON step chopped up (#1658).
|
||||
//
|
||||
// That step matched with LIKE, which is case-insensitive in SQLite, so a
|
||||
// note somebody had typed starting "ticketjson:" was read as a receipt: the
|
||||
// first eleven characters were dropped, the rest was moved into ticket_json
|
||||
// and the note was set to NULL. The step now matches with GLOB, but that
|
||||
// only helps a fresh install — the array is index-addressed against
|
||||
// schema_version, so a repaired step never runs again on a database that
|
||||
// already applied it.
|
||||
//
|
||||
// A receipt comes out of JSON.stringify and always parses; typed text does
|
||||
// not. So a row moves back only when its ticket_json fails to parse AND the
|
||||
// note is still empty — anything that parses, and any row someone has
|
||||
// written a note on since, is left exactly as it is. The eleven marker
|
||||
// characters themselves are gone for good: their case was the only thing
|
||||
// separating a receipt from a note, and writing "TICKETJSON:" back would
|
||||
// hand the row straight to the reader that reads that prefix as a receipt.
|
||||
// Appended LAST — the array is index-addressed against schema_version.
|
||||
() => {
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT id, ticket_json FROM budget_items
|
||||
WHERE ticket_json IS NOT NULL AND ticket_json != '' AND COALESCE(note, '') = ''`
|
||||
)
|
||||
.all() as Array<{ id: number; ticket_json: string }>;
|
||||
const restore = db.prepare('UPDATE budget_items SET note = ?, ticket_json = NULL WHERE id = ?');
|
||||
for (const row of rows) {
|
||||
try {
|
||||
JSON.parse(row.ticket_json);
|
||||
} catch {
|
||||
restore.run(row.ticket_json, row.id);
|
||||
}
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
if (currentVersion < migrations.length) {
|
||||
|
||||
Reference in New Issue
Block a user