forge
Explore
Log in

Don't you dare go Hollow

a link from before addresses could be re-shown stops pretending: the legacy row no longer wears a masked field that reads like a copyable URL — it states the fact and offers one Mint-a-new-link button (remint revokes the dead link, mints a fresh one carrying the permission, password and any still-future expiry, and lands on the copy-once banner where the full address wraps and one click copies it); also rides along uncommitted work found in the tree from the identity follow-up (directory via the im-client SDK, provision_user's admin+photo_version columns, avatar version-etag tests) — it compiles and the whole http suite passes with it

Browse files at this commit

95114ec593de8eea004e12108a1972eff0d56e16Ahmet Kaan GümüşParent: 8713c40
crates/in-web/src/i18n.rsmodified+3 -0
@@ -238,6 +238,7 @@ pub enum Key {
238238 // Re-viewable share links (LinkVisible owns this block).
239239 Shared,
240240 LegacyLinkNote,
241+ RemintLink,
241242 }
242243
243244 pub fn t(lang: Lang, key: Key) -> &'static str {
@@ -403,6 +404,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
403404 LegacyLinkNote => {
404405 "This link predates re-viewable addresses — revoke and mint a new one to carry it forward."
405406 }
407+ RemintLink => "Mint a new link",
406408 },
407409 Lang::Tr => match key {
408410 Cancel => "Vazgeç",
@@ -566,6 +568,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
566568 LegacyLinkNote => {
567569 "Bu bağlantı, adreslerin yeniden görüntülenebildiği dönemden önce oluşturuldu — devam ettirmek için iptal edip yeni bir tane oluşturun."
568570 }
571+ RemintLink => "Yeni bağlantı oluştur",
569572 },
570573 }
571574 }
crates/in-web/src/settings.rsmodified+5 -2
@@ -472,7 +472,7 @@ async fn settings(cx: &Cx) -> Result {
472472 </div>
473473 // The same affordance the modal's live row
474474 // carries: the full address with its copy
475- // button, or the masked value plus the
475+ // button, or the one-click mint plus the
476476 // carry-forward note for a link from before
477477 // the sealing.
478478 <div class="share-link-row">
@@ -480,7 +480,10 @@ async fn settings(cx: &Cx) -> Result {
480480 <p class="member-link-value share-link-url" aria-label=(t(language, Key::ShareLink))>(url.clone())</p>
481481 <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button>
482482 } else {
483- <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/…")) aria-label=(t(language, Key::ShareLink))>
483+ <form class="pop-row-form" method="post" action="/api/share/link/remint">
484+ <input type="hidden" name="id" value=(link.id.clone())>
485+ <button class="quiet" type="submit">(t(language, Key::RemintLink))</button>
486+ </form>
484487 }
485488 </div>
486489 if url.is_none() {
crates/in-web/src/share.rsmodified+119 -6
@@ -1,6 +1,7 @@
11 //! Sharing: public links, per-user grants, and the shared-with-me page.
22 //!
3-//! `POST /api/share/link/create|revoke` mints and kills bearer links over a
3+//! `POST /api/share/link/create|revoke|remint` mints, kills, and re-mints
4+//! bearer links over a
45 //! file or folder (`can_download`, optional expiry in days; only the token
56 //! hash is stored). `POST /api/share/user/add|remove` grants and revokes
67 //! named users the same way. `GET /s/{token}` is public — no auth —
@@ -373,6 +374,108 @@ async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect {
373374 }
374375 }
375376
377+/// Carries a legacy link forward: a fresh mint over the same target, with
378+/// the old row's `can_download`, its password, and a still-future expiry —
379+/// an elapsed one drops, since a minted expiry opens for no one. Only its
380+/// creator may; a foreign or unknown link is answered as if it never
381+/// existed. The old row and its sealed setting die with the mint, the
382+/// revoke path's exact semantics: the address remint replaces was already
383+/// unrecoverable.
384+#[route(POST "/api/share/link/remint")]
385+async fn remint_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect {
386+ let user = match require_user(cx).await {
387+ Ok(user) => user,
388+ Err(refusal) => {
389+ return redirect_back(cx, "/settings?section=links", "remint", Some(refusal));
390+ }
391+ };
392+ let store = app(cx).store;
393+ let mine = store
394+ .share_links(&user.id)
395+ .await
396+ .map_err(|_| Refusal::Unavailable);
397+ let Ok(links) = mine else {
398+ return redirect_back(
399+ cx,
400+ "/settings?section=links",
401+ "remint",
402+ Some(Refusal::Unavailable),
403+ );
404+ };
405+ let Some(old) = links
406+ .iter()
407+ .find(|link| link.id == input.id && link.created_by == user.id)
408+ else {
409+ return redirect_back(
410+ cx,
411+ "/settings?section=links",
412+ "remint",
413+ Some(Refusal::NotFound),
414+ );
415+ };
416+ // A still-future expiry carries over; an elapsed one would mint a link
417+ // that is dead on arrival.
418+ let expires_at = old.expires_at.filter(|at| *at > OffsetDateTime::now_utc());
419+ let created = store
420+ .create_share_link(
421+ &user.id,
422+ old.kind.clone(),
423+ &old.target_id,
424+ old.can_download,
425+ expires_at,
426+ old.password_hash.clone(),
427+ )
428+ .await;
429+ match created {
430+ Ok(minted) => match store.revoke_share_link(&input.id).await {
431+ Ok(()) => {
432+ // The sealed address dies with the link — part of the
433+ // remint, not cleanup after it, so a failed delete reports
434+ // the remint as refused.
435+ match store
436+ .delete_setting(&format!("share_token:{}", input.id))
437+ .await
438+ {
439+ Ok(()) => {
440+ // The fresh token gets the seal, exactly as a
441+ // creation seals its own; a failed seal is lived
442+ // with, because the redirect below shows the full
443+ // address regardless.
444+ let sealed =
445+ in_core::store::secret::seal(&app(cx).link_key, &minted.token);
446+ let _ = app(cx)
447+ .store
448+ .set_setting(&format!("share_token:{}", minted.link.id), &sealed)
449+ .await;
450+ let back = back_to(cx, "/settings?section=links");
451+ let separator = if back.contains('?') { '&' } else { '?' };
452+ let location = format!("{back}{separator}created={}", minted.token);
453+ Ok((StatusCode::SEE_OTHER, [(header::LOCATION, location)]))
454+ }
455+ Err(error) => redirect_back(
456+ cx,
457+ "/settings?section=links",
458+ "remint",
459+ Some(refusal_of(error)),
460+ ),
461+ }
462+ }
463+ Err(error) => redirect_back(
464+ cx,
465+ "/settings?section=links",
466+ "remint",
467+ Some(refusal_of(error)),
468+ ),
469+ },
470+ Err(error) => redirect_back(
471+ cx,
472+ "/settings?section=links",
473+ "remint",
474+ Some(refusal_of(error)),
475+ ),
476+ }
477+}
478+
376479 /// Whether `at` is the link's target or sits under it: every step up must be
377480 /// live, owned by the link's owner, and end at the target. A break anywhere
378481 /// means the browse is outside the share.
@@ -1520,10 +1623,17 @@ pub(crate) async fn share_modal(
15201623 // leaves the typed-address field in place below.
15211624 let default_quota = app(cx).config.default_quota_bytes;
15221625 let mut candidates: Vec<User> = Vec::new();
1523- if let Some(members) = in_client::directory(cx).await {
1626+ if let Ok(members) = app(cx).directory.directory().await {
15241627 for member in members {
15251628 let row = store
1526- .provision_user(&member.sub, &member.email, &member.name, default_quota)
1629+ .provision_user(
1630+ &member.sub,
1631+ &member.email,
1632+ &member.name,
1633+ Some(member.admin),
1634+ member.photo_version,
1635+ default_quota,
1636+ )
15271637 .await?;
15281638 if !row.disabled
15291639 && row.id != user.id
@@ -1629,9 +1739,9 @@ pub(crate) async fn share_modal(
16291739 </form>
16301740 }
16311741 for link in live.iter().take(1) {
1632- // The full address, re-derived from the token the creation sealed
16331742 // away. A link from before the sealing — or one whose key is gone —
1634- // keeps the masked value and carries the carry-forward note.
1743+ // has no address to re-show: the row carries the mint action and the
1744+ // note below states the fact.
16351745 let url = share_link_url(cx, *link).await;
16361746 let legacy = url.is_none();
16371747 <div class="member-row">
@@ -1648,7 +1758,10 @@ pub(crate) async fn share_modal(
16481758 <p class="member-link-value share-link-url" aria-label=(t(language, Key::ShareLink))>(url)</p>
16491759 <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button>
16501760 } else {
1651- <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/…")) aria-label=(t(language, Key::ShareLink))>
1761+ <form class="pop-row-form" method="post" action="/api/share/link/remint">
1762+ <input type="hidden" name="id" value=(link.id.clone())>
1763+ <button class="quiet" type="submit">(t(language, Key::RemintLink))</button>
1764+ </form>
16521765 }
16531766 <form class="pop-row-form" method="post" action="/api/share/link/revoke">
16541767 <input type="hidden" name="id" value=(link.id.clone())>
crates/in-web/tests/http.rsmodified+168 -26
@@ -396,6 +396,11 @@ impl TestApp {
396396 // Deliberately not the cookie key: the sealing helpers must
397397 // reach for `link_key`, not for whatever key sits nearest.
398398 link_key: [11u8; 32],
399+ directory: im_client::directory::DirectoryClient::new(
400+ fake.url(),
401+ "in-test".to_string(),
402+ "s3cr3t".to_string(),
403+ ),
399404 })
400405 .app_context(in_client::LogoutBack(Arc::new(|cx: &Cx| {
401406 Box::pin(async move { Some(in_web::server::share_origin(cx).await) })
@@ -417,7 +422,14 @@ impl TestApp {
417422 async fn sign_in(&self, sub: &str, email: &str, name: &str) -> String {
418423 let user = self
419424 .store
420- .provision_user(sub, email, name, self.config.default_quota_bytes)
425+ .provision_user(
426+ sub,
427+ email,
428+ name,
429+ None,
430+ 0,
431+ self.config.default_quota_bytes,
432+ )
421433 .await
422434 .unwrap();
423435 let token = format!("tok-{}", Ulid::new());
@@ -755,7 +767,7 @@ async fn file_id(app: &TestApp, owner: &str, name: &str, bytes: &[u8]) -> String
755767
756768 async fn owner_of(app: &TestApp, sub: &str) -> String {
757769 app.store
758- .provision_user(sub, "x@y.z", "X", app.config.default_quota_bytes)
770+ .provision_user(sub, "x@y.z", "X", None, 0, app.config.default_quota_bytes)
759771 .await
760772 .unwrap()
761773 .id
@@ -2264,10 +2276,10 @@ async fn revoke_deletes_the_sealed_token_row() {
22642276 }
22652277
22662278 /// A link minted before the sealing has no row to open: the modal and the
2267-/// settings panel keep the masked value and carry the carry-forward note
2268-/// instead of a copy button.
2279+/// settings panel state the carry-forward fact and offer the one-click
2280+/// mint — no masked value, nothing that reads as an address.
22692281 #[tokio::test]
2270-async fn legacy_link_stays_masked_with_the_carry_forward_note() {
2282+async fn legacy_link_states_the_carry_forward_note_and_offers_the_mint() {
22712283 let app = TestApp::build().await;
22722284 let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await;
22732285 let owner = owner_of(&app, "sub-admin").await;
@@ -2284,7 +2296,12 @@ async fn legacy_link_stays_masked_with_the_carry_forward_note() {
22842296 .await;
22852297 assert_eq!(page.status, StatusCode::OK, "{}", page.text());
22862298 let text = page.text();
2287- assert!(text.contains("/s/…"), "no masked value: {text}");
2299+ assert!(!text.contains("/s/…"), "masked value on a legacy link: {text}");
2300+ assert!(
2301+ text.contains("action=\"/api/share/link/remint\""),
2302+ "no mint action on a legacy link: {text}"
2303+ );
2304+ assert!(text.contains("Mint a new link"), "no mint button: {text}");
22882305 assert!(
22892306 text.contains("predates re-viewable addresses"),
22902307 "no carry-forward note: {text}"
@@ -2297,7 +2314,11 @@ async fn legacy_link_stays_masked_with_the_carry_forward_note() {
22972314 let page = app.get("/settings?section=links", Some(&ada)).await;
22982315 assert_eq!(page.status, StatusCode::OK, "{}", page.text());
22992316 let text = page.text();
2300- assert!(text.contains("/s/…"), "no masked value: {text}");
2317+ assert!(!text.contains("/s/…"), "masked value on a legacy link: {text}");
2318+ assert!(
2319+ text.contains("action=\"/api/share/link/remint\""),
2320+ "no mint action on a legacy link: {text}"
2321+ );
23012322 assert!(
23022323 text.contains("predates re-viewable addresses"),
23032324 "no carry-forward note: {text}"
@@ -2308,6 +2329,107 @@ async fn legacy_link_stays_masked_with_the_carry_forward_note() {
23082329 );
23092330 }
23102331
2332+/// Reminting carries a legacy link forward: the fresh token opens the same
2333+/// target with the carried rights, the old token is dead, the old row and
2334+/// its seal are gone, and the settings panel shows the new full address
2335+/// with its copy button.
2336+#[tokio::test]
2337+async fn remint_carries_a_legacy_link_forward() {
2338+ let app = TestApp::build().await;
2339+ let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await;
2340+ let owner = owner_of(&app, "sub-admin").await;
2341+ let file = file_id(&app, &owner, "carried.txt", b"carried").await;
2342+ let answer = app
2343+ .post(
2344+ "/api/share/link/create",
2345+ Some(&ada),
2346+ &[
2347+ ("kind", "file"),
2348+ ("target_id", &file),
2349+ ("can_download", "1"),
2350+ ("expires_in_days", "30"),
2351+ ],
2352+ )
2353+ .await;
2354+ assert!(answer.accepted(), "create refused: {:?}", answer.location);
2355+ let old_token = created_token(answer.location.as_deref().unwrap());
2356+ let old_id = app.store.share_links(&owner).await.unwrap()[0].id.clone();
2357+ // Lose the seal: the address is unrecoverable, the link reads legacy.
2358+ app.store
2359+ .delete_setting(&format!("share_token:{old_id}"))
2360+ .await
2361+ .unwrap();
2362+
2363+ let answer = app
2364+ .post("/api/share/link/remint", Some(&ada), &[("id", &old_id)])
2365+ .await;
2366+ assert_eq!(answer.status, StatusCode::SEE_OTHER, "{:?}", answer.location);
2367+ let location = answer.location.as_deref().expect("remint set no location");
2368+ let new_token = created_token(location);
2369+ assert!(!new_token.is_empty(), "remint minted no token: {location}");
2370+
2371+ // The fresh token opens the same file; the old one is dead.
2372+ let card = app.get(&format!("/s/{new_token}"), None).await;
2373+ assert_eq!(card.status, StatusCode::OK, "{}", card.text());
2374+ assert!(
2375+ card.text().contains("carried.txt"),
2376+ "the fresh token did not open the file: {}",
2377+ card.text()
2378+ );
2379+ let dead = app.get(&format!("/s/{old_token}"), None).await;
2380+ assert!(
2381+ dead.text().contains("no longer works"),
2382+ "the old token still opens: {}",
2383+ dead.text()
2384+ );
2385+
2386+ // The old row died with its seal; the carried rights ride the new row.
2387+ let links = app.store.share_links(&owner).await.unwrap();
2388+ assert_ne!(links[0].id, old_id, "the old row survived the remint");
2389+ assert!(links[0].can_download, "remint dropped the download right");
2390+ assert!(links[0].expires_at.is_some(), "remint dropped the expiry");
2391+ assert!(
2392+ app.store
2393+ .get_setting(&format!("share_token:{}", links[0].id))
2394+ .await
2395+ .unwrap()
2396+ .is_some(),
2397+ "the fresh token came unsealed"
2398+ );
2399+ assert!(
2400+ app.store
2401+ .get_setting(&format!("share_token:{old_id}"))
2402+ .await
2403+ .unwrap()
2404+ .is_none(),
2405+ "the old seal survived the remint"
2406+ );
2407+
2408+ // The settings panel shows the new full address with its copy button —
2409+ // no masked placeholder, no legacy row left to carry forward.
2410+ let page = app
2411+ .get(
2412+ &format!("/settings?section=links&created={new_token}"),
2413+ Some(&ada),
2414+ )
2415+ .await;
2416+ assert_eq!(page.status, StatusCode::OK, "{}", page.text());
2417+ let text = page.text();
2418+ assert!(
2419+ text.contains(&format!("\">http://127.0.0.1:7655/s/{new_token}</p>")),
2420+ "no full new url row in settings: {text}"
2421+ );
2422+ assert!(
2423+ text.contains("class=\"quiet share-copy\""),
2424+ "no copy button in settings: {text}"
2425+ );
2426+ assert!(!text.contains("/s/…"), "masked value after remint: {text}");
2427+ assert!(
2428+ !text.contains("predates re-viewable addresses"),
2429+ "a legacy row survived the remint: {text}"
2430+ );
2431+}
2432+
23112433 /// Live public links and grants to other people mark their drive rows with
23122434 /// the Shared chip; unmarked siblings carry nothing, and no row carries two.
23132435 #[tokio::test]
@@ -4543,35 +4665,40 @@ async fn settings_lives_in_the_user_menu_not_the_topbar() {
45434665 }
45444666
45454667 #[tokio::test]
4546-async fn avatar_serves_own_photo_with_etag() {
4668+async fn avatar_serves_photo_with_a_version_etag() {
45474669 let app = TestApp::build().await;
45484670 let cookie = app.sign_in("sub-face", "face@in.test", "Face").await;
45494671 let me = owner_of(&app, "sub-face").await;
45504672 app.fake.set_photo("sub-face", tiny_png(), "image/png");
45514673
4674+ // Unstamped, the route answers and revalidates: no-cache, the etag the
4675+ // row's photo_version spells, a 304 on a matching If-None-Match.
45524676 let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await;
45534677 assert_eq!(face.status, StatusCode::OK);
45544678 assert_eq!(face.content_type.as_deref(), Some("image/png"));
45554679 assert_eq!(
45564680 face.cache_control.as_deref(),
4557- Some("private, max-age=31536000, immutable")
4681+ Some("private, no-cache"),
4682+ "unstamped avatar must revalidate: {:?}",
4683+ face.cache_control
45584684 );
4685+ assert_eq!(face.etag.as_deref(), Some("\"p0\""));
45594686 assert_eq!(face.bytes, tiny_png());
45604687
4561- let etag = face.etag.clone().expect("no etag on the avatar");
45624688 let cached = app
4563- .get_with_if_none_match(&format!("/avatar/{me}"), Some(&cookie), &etag)
4689+ .get_with_if_none_match(&format!("/avatar/{me}"), Some(&cookie), "\"p0\"")
45644690 .await;
45654691 assert_eq!(cached.status, StatusCode::NOT_MODIFIED);
45664692 assert!(cached.bytes.is_empty());
45674693
4568- // The user menu wears the photo over the initials, with the fallback script.
4694+ // The user menu wears the photo over the initials, stamped with the
4695+ // row's version so a changed photo is a changed URL.
45694696 let page = app.get("/drive", Some(&cookie)).await;
45704697 assert_eq!(page.status, StatusCode::OK);
45714698 let body = page.text();
45724699 assert!(
4573- body.contains(&format!("src=\"/avatar/{me}\"")),
4574- "menu wears no photo img"
4700+ body.contains(&format!("src=\"/avatar/{me}?v=0\"")),
4701+ "menu wears no versioned photo img"
45754702 );
45764703 assert!(
45774704 body.contains("avatar-stack"),
@@ -4581,18 +4708,33 @@ async fn avatar_serves_own_photo_with_etag() {
45814708 }
45824709
45834710 #[tokio::test]
4584-async fn avatar_without_photo_is_not_found() {
4711+async fn avatar_version_stamped_url_caches_immutable() {
45854712 let app = TestApp::build().await;
4586- let cookie = app.sign_in("sub-noface", "noface@in.test", "NoFace").await;
4587- let me = owner_of(&app, "sub-noface").await;
4713+ let cookie = app.sign_in("sub-stamp", "stamp@in.test", "Stamp").await;
4714+ let me = owner_of(&app, "sub-stamp").await;
4715+ app.fake.set_photo("sub-stamp", tiny_png(), "image/png");
45884716
4589- let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await;
4590- assert_eq!(face.status, StatusCode::NOT_FOUND);
4591- assert!(face.bytes.is_empty());
4717+ // `?v` equal to the row's version: a year of immutable, no revalidation.
4718+ let fresh = app
4719+ .get(&format!("/avatar/{me}?v=0"), Some(&cookie))
4720+ .await;
4721+ assert_eq!(fresh.status, StatusCode::OK);
4722+ assert_eq!(
4723+ fresh.cache_control.as_deref(),
4724+ Some("private, max-age=31536000, immutable")
4725+ );
4726+ // A stale stamp — the browser holds a face the row has moved past —
4727+ // falls back to revalidate, so the next answer is the truth.
4728+ let stale = app
4729+ .get(&format!("/avatar/{me}?v=7"), Some(&cookie))
4730+ .await;
4731+ assert_eq!(stale.status, StatusCode::OK);
4732+ assert_eq!(stale.cache_control.as_deref(), Some("private, no-cache"));
4733+ assert_eq!(stale.etag.as_deref(), Some("\"p0\""));
45924734 }
45934735
45944736 #[tokio::test]
4595-async fn avatar_for_someone_else_is_not_found() {
4737+async fn avatar_serves_any_member_to_any_signed_in_user() {
45964738 let app = TestApp::build().await;
45974739 let alice = app
45984740 .sign_in("sub-alice-face", "alice@in.test", "Alice")
@@ -4601,13 +4743,13 @@ async fn avatar_for_someone_else_is_not_found() {
46014743 let bob_id = owner_of(&app, "sub-bob-face").await;
46024744 app.fake.set_photo("sub-bob-face", tiny_png(), "image/png");
46034745
4604- // Bob's face through Alice's session: the same 404 as no photo at all,
4605- // never a hint that Bob has one.
4746+ // Bob's face through Alice's session: a coworker's face renders in her
4747+ // topbar too, so the gate is the session, not the id.
46064748 let face = app.get(&format!("/avatar/{bob_id}"), Some(&alice)).await;
4607- assert_eq!(face.status, StatusCode::NOT_FOUND);
4608- assert!(face.bytes.is_empty());
4749+ assert_eq!(face.status, StatusCode::OK);
4750+ assert_eq!(face.bytes, tiny_png());
46094751
4610- // And an id that names nobody at all.
4752+ // An id that names nobody provisioned stays the empty answer.
46114753 let ghost = app
46124754 .get("/avatar/00000000000000000000000000", Some(&alice))
46134755 .await;