Review

Mint public share links for second-opinion imaging packs

SpineMark second-opinion flow needs unauthenticated links so referring clinics can open a redacted imaging pack without SSO. Replaces opaque sequential pack ids in the URL with generated share tokens stored server-side with a 72h TTL.

PythonTier 3securityuuidprivacy

Click a line to flag it, pick one or more labels, then submit. If the change looks correct, approve it.

services/sharing/imaging_links.py+13-3
88import uuid
99from datetime import datetime, timedelta, timezone
1010
1111from app.db import shares
1212from app.models import ImagingPack
1313
14+SHARE_TTL = timedelta(hours=72)
15+PUBLIC_BASE = "https://share.spinemark.health/p"
16+
14-def public_pack_url(pack: ImagingPack) -> str:
15- # Temporary: pack PK is guessable; replace before GA.
16- return f"https://share.spinemark.health/legacy/{pack.id}"
17+def mint_share_link(pack: ImagingPack, created_by: str) -> str:
18+ token = str(uuid.uuid1())
19+ expires_at = datetime.now(timezone.utc) + SHARE_TTL
20+ shares.insert(
21+ token=token,
22+ pack_id=pack.id,
23+ created_by=created_by,
24+ expires_at=expires_at,
25+ )
26+ return f"{PUBLIC_BASE}/{token}"