mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
fix(client): correct the second pass over this branch's own client fixes
Four of the fixes already on this branch were wrong, and an adversarial read of the diff is what turned them up. The shared merge helper claimed to implement the server's COALESCE(assignment_time, place_time) and did not: it pinned the embedded times to whatever the assignment already showed, ignoring the override column entirely. Sharing that with the WS applier traded one bug for another - a collaborator moving a place from 08:00 to 10:00 stopped reaching the day card for every assignment WITHOUT an override, which is most of them. It merges the way the server projects now, and the test that was supposed to pin this seeded a fixture the server could never produce (embedded times that differ from the pool row with no override to explain the difference). The per-iteration auth gate went into every loop in tripSyncManager except the one that matters most: the mutation-queue replay, which writes server responses straight into Dexie. After a logout that is the shared anonymous database. The fire-and-forget tags/categories writes two lines below a gate added in the same commit were ungated for the same reason - they resolve later, and the check has to happen then. safeHttpUrl is backed by placeWebsiteSchema: http(s) only, capped at 500 characters. A booking url is deliberately free-form - shared's own contract says so in as many words, because people paste bare hosts and long provider deep links - so guarding it with the stricter schema turned a link somebody saved last year into dead text. safeExternalHref refuses the schemes that execute in this origin and gives a scheme-less value https://, which is what an address bar does with the same input. And the memories timeout was 20s while the server's own budget for a Synology call is 30s, doubled again when the session has expired and it re-authenticates: a slow NAS that answered before this branch would have started reading as disconnected. Those calls had no client timeout at all before; they have none again, and the ones that need to give up early carry an AbortSignal. The notes thumbnail also loses its NUL byte cache separator - it made git treat the whole file as binary, so a security fix landed in it unreviewable - and gains the same cache cap its chat sibling got.
This commit is contained in:
@@ -16,3 +16,31 @@ import { placeWebsiteSchema } from '@trek/shared'
|
||||
export function safeHttpUrl(value: string | null | undefined): string | null {
|
||||
return typeof value === 'string' && placeWebsiteSchema.safeParse(value).success ? value : null
|
||||
}
|
||||
|
||||
/**
|
||||
* A user-pasted link, made safe for an href without narrowing what people are
|
||||
* allowed to paste.
|
||||
*
|
||||
* Different job from safeHttpUrl above. That one guards fields whose contract
|
||||
* really is http(s)-only and capped. A booking url is deliberately free-form -
|
||||
* shared's reservationUrlSchema says so in as many words, because people paste
|
||||
* bare hosts and very long provider deep links - so holding it to the stricter
|
||||
* contract would turn a link somebody saved last year into dead text.
|
||||
*
|
||||
* Only the schemes that execute in this origin are refused. A value with no
|
||||
* scheme gets https://, which is what an address bar does with the same input;
|
||||
* without it the browser would resolve "www.hotel.com" against the current page
|
||||
* and navigate inside the app.
|
||||
*/
|
||||
export function safeExternalHref(value: string | null | undefined): string | null {
|
||||
if (typeof value !== 'string') return null
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) return null
|
||||
// Browsers strip control characters before they resolve a scheme, so the test
|
||||
// has to run against the same string they will see.
|
||||
const collapsed = Array.from(trimmed).filter(c => c > ' ').join('')
|
||||
if (/^https?:\/\//i.test(collapsed)) return trimmed
|
||||
// Any other scheme, executing or merely unexpected, stays unlinked.
|
||||
if (/^[a-z][a-z0-9+.-]*:/i.test(collapsed)) return null
|
||||
return `https://${trimmed}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user