mirror of
https://github.com/saltbo/zpan.git
synced 2026-09-21 04:59:47 +08:00
* fix(downloads): block SSRF targets in remote-download source URL The remote-download source URI was only length-validated, so an authenticated editor could point a task at the cloud metadata endpoint, loopback, or RFC 1918 hosts and have the response exfiltrated to their own drive. Add a shared isSafeHttpUrl/isBlockedUrlHost guard (scheme allowlist + private/loopback/link-local/metadata/IPv6 blocking) and cross-check source type vs uri in createDownloadTaskSchema. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(api): cover 9 untested src/lib/api.ts wrappers Adds api.test.ts coverage (RPC path, method, payload, success + ApiError paths) for listObjectsByPath, isNameConflictError, listAdminAuthProviders, upsertAuthProvider, deleteAuthProvider, listInviteCodes, generateInviteCodes, deleteInviteCode, and listTeamActivities — satisfying the CLAUDE.md coverage gate that otherwise blocks PRs touching api.ts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(spaces): release source quota on cross-space move A cross-space "move" copied bytes into the target (reserving quota there) but only trashed the source. Trashed files still count toward usage, so the moved bytes were billed in both spaces and the source never freed — contrary to the design doc ("copy + delete source, quota effectively transfers"). Purge the source subtree (independent S3 copy already exists in the target) instead of trashing it, which deletes the objects, cascades share cleanup, and reconciles usage. Rename the response field sourceTrashed -> sourceDeleted and update the move hint copy accordingly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(upload): wire S3 multipart for large files The upload UI only ever did a single presigned PUT, which caps at S3's 5 GiB limit and fails the whole transfer on any network blip — despite a complete multipart backend (object-upload-sessions) sitting unused. Add uploadPartToS3 (PUTs a part, returns its ETag) and a multipart-upload orchestrator: open session -> presign parts in batches of 100 -> PUT parts with bounded concurrency and per-part retry -> complete. Files over 100 MiB take this path; smaller files keep the single-PUT flow. Cancellation aborts the multipart and the draft. Also fixes the presignObjectUploadParts wrapper type to match the server's actual `url` field. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(auth): add password-reset flow There was no self-service password recovery — a forgotten password needed admin intervention. SMTP/email sending was already built; this wires the last mile: better-auth sendResetPassword (reset email), a "Forgot password?" link on sign-in, and /forgot-password + /reset-password pages. The forgot-password page never reveals whether an account exists. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(trash): auto-purge trashed items past a retention window Trashed files counted toward quota forever — trash never auto-emptied, so storage was never reclaimed without a manual "empty trash". Add a daily cron (CF Workers 0 4 * * * + Node setInterval) that purges trashed items older than ZPAN_TRASH_RETENTION_DAYS (default 30, 0 disables) across all orgs, reusing the existing purge path so S3 objects, share references, and quota are all cleaned. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(notifications): typed NotificationType, i18n rendering, team-join Notifications were a bare-string type with only 3 producers, and server copy was stored as hardcoded English (zh users saw English). - Add a NotificationType union in shared/ and type the notification service. - Render notification title/body client-side from type + metadata via i18n, falling back to stored strings for older rows (fixes the hardcoded-English gap). - Notify users when they join a team (team_join). (Login auditing was intentionally dropped: reusing the activity-events feed for sign_in events would spam every user's per-org activity timeline. Proper auth auditing belongs in a dedicated log and can be added separately.) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test: cover SSRF guard and multipart upload branches Raise patch coverage on the new code: uploadPartToS3 pre-aborted-signal and network-error paths, the url-safety octet-overflow and public-IPv6 branches, and the invalid-magnet rejection in the download-task schema. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
65 lines
2.5 KiB
TypeScript
65 lines
2.5 KiB
TypeScript
/**
|
|
* SSRF guards for user-supplied URLs that the server (or a server-side agent)
|
|
* will fetch — currently the remote-download source URI.
|
|
*
|
|
* The literal-host checks below stop the obvious attacks (metadata endpoint,
|
|
* loopback, RFC 1918). They cannot stop DNS rebinding, where a public hostname
|
|
* resolves to a private address at fetch time — that must be re-checked after
|
|
* DNS resolution by whoever performs the actual fetch.
|
|
*/
|
|
|
|
function ipv4Octets(host: string): [number, number, number, number] | null {
|
|
if (!/^\d{1,3}(\.\d{1,3}){3}$/.test(host)) return null
|
|
const parts = host.split('.').map(Number)
|
|
if (parts.some((n) => n > 255)) return null
|
|
return parts as [number, number, number, number]
|
|
}
|
|
|
|
function isBlockedIpv4(host: string): boolean {
|
|
const octets = ipv4Octets(host)
|
|
if (!octets) return false
|
|
const [a, b] = octets
|
|
if (a === 0) return true // 0.0.0.0/8 "this network"
|
|
if (a === 10) return true // private
|
|
if (a === 127) return true // loopback
|
|
if (a === 169 && b === 254) return true // link-local incl. 169.254.169.254 metadata
|
|
if (a === 172 && b >= 16 && b <= 31) return true // private
|
|
if (a === 192 && b === 168) return true // private
|
|
if (a === 100 && b >= 64 && b <= 127) return true // CGNAT shared address space
|
|
return false
|
|
}
|
|
|
|
function isBlockedIpv6(host: string): boolean {
|
|
const h = host.toLowerCase()
|
|
if (h === '::' || h === '::1') return true // unspecified / loopback
|
|
if (h.startsWith('fe8') || h.startsWith('fe9') || h.startsWith('fea') || h.startsWith('feb')) {
|
|
return true // fe80::/10 link-local
|
|
}
|
|
if (h.startsWith('fc') || h.startsWith('fd')) return true // fc00::/7 unique local
|
|
const mapped = h.match(/^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/)
|
|
if (mapped) return isBlockedIpv4(mapped[1])
|
|
return false
|
|
}
|
|
|
|
/** True when `hostname` resolves to a non-routable / internal address we must not fetch. */
|
|
export function isBlockedUrlHost(hostname: string): boolean {
|
|
const host = hostname.toLowerCase()
|
|
if (host === 'localhost' || host.endsWith('.localhost')) return true
|
|
const bare = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host
|
|
if (isBlockedIpv4(bare)) return true
|
|
if (bare.includes(':') && isBlockedIpv6(bare)) return true
|
|
return false
|
|
}
|
|
|
|
/** Validates an http(s) URL is well-formed and not pointed at an internal host. */
|
|
export function isSafeHttpUrl(value: string): boolean {
|
|
let url: URL
|
|
try {
|
|
url = new URL(value)
|
|
} catch {
|
|
return false
|
|
}
|
|
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false
|
|
return !isBlockedUrlHost(url.hostname)
|
|
}
|