S063: web pages can't open nacre:// pages; the passwords page asks on every open and isn't kept in the session

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-18 05:12:09 -06:00
commit 583a92b854
18 changed files with 273 additions and 24 deletions

View file

@ -64,7 +64,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
| `nice cargo build --release -j 2` | compile check, produces `target/release/nacre` | now |
| `nice cargo test --release -j 2` | unit tests (44, ~16 s test-profile build then <1 s run; shares the S001 build) (util, settings, history, bookmarks, permissions, vault, dns, bridge loopback, download, adblock, keys, scripts, updates, inject, hub, theme, ui::widgets input, ui::paint, ui::pages::newtab) | first successful build; not alongside a build |
| `src/selftest.rs` | in-app self test: `NACRE_SCRIPT=<file>` runs script commands (listed at its top) | now |
| `tools/smoke.sh <script> [outdir]` | smoke run in a hidden nested Wayland session (`tools/nested-session.sh start\|stop <dir> [WxH]`: Xvfb → nested niri, software GL, own runtime dir and bus; `SMOKE_SIZE` = nested output size, window at 0,0) with a throwaway home; selftest `click`/`rclick`/`pagescroll`/`pagetype` are real compositor input there (`tools/wl-input`, own crate, built on first use; `wtype`), `resize` goes through the nested niri; outdir (default `target/smoke/<name>-<time>`, use a fresh one: `home/` persists) gets `nacre.log`, `selftest.log`, `<shot>.png`, `<status>.json`, `home/`, `session/`; exits non-zero on crash, panic, no `status done` or a failed `assert <js>`. Scripts in `tests/smoke/` (`launch.txt` offline, `https.txt` needs internet, `restore.txt` with `SMOKE_HOME=<launch outdir>/home`, `chrome.txt` chrome and every flyout dark and light, offline; `colours.txt` colours after welcome and site colour vs internal pages, hidden `SMOKE_SIZE=1280x1100`; `input.txt` real clicks, typing, right click, wheel on a web page, offline; `basics.txt` tabs, navigation, find, zoom, full screen, pop-ups, offline; `heavy-web.txt` DuckDuckGo, Wikipedia, YouTube, needs internet, `SMOKE_TIMEOUT=900`; `keys.txt` every shortcut action, offline; `privacy-net.txt` DNT/GPC/Save-Data headers and third-party cookies on a loopback server, offline, start `python3 tests/smoke/net/server.py &` first; `site-doctor.txt` Google sign-in, captchas, Reddit, GitHub, needs internet; `cache.txt` HTTP cache, offline, start `python3 tests/smoke/cache/server.py &` first; selftest `launch <args>` checks single instance; `cookies.txt` → `cookies-restart.txt` → `cookies-cleared.txt` encrypted cookies across restarts with `SMOKE_KEYRING=1` (own throwaway GNOME Keyring + bus) and `SMOKE_HOME`, `cookies-nokeyring.txt` without, server.py first; `zap.txt` ad removal animation (cookie shield mid-animation, slots closed, players kept, Motion off), dark and light, offline, `SMOKE_SIZE=1280x900`; `stuck.txt` tab lifecycle (leave-page question, Reload, nacre:// pages free their view, Back with history, chatty page closes without CRITICAL, shortcut recording ends), offline, `SMOKE_SIZE=1280x900`; `crash-adblock.txt` R5-01 regression, ~1300 blocked loads with reloads/navigations mid-load plus 3200 timers under GC pressure, offline, server.py first); header documents env vars and commands. `SMOKE_VISIBLE=1` shows the run on the user's screen (real GPU; page input synthesized in the page, no `rclick`/`resize`); it refuses to start unless the user's niri config has the `dev.nacre.Nacre` window rule from the smoke.sh header (DP-1, no focus), so it never moves the user's focus or workspace (D-044). WebKit state (S050): launch, basics, input, keys, chrome, dialogs, pip, auth, stores-*, integ-spell, net-*, privacy-net, privacy-mode, cache*, crash-adblock green hidden (loopback skips the bridge, no `NACRE_NO_BRIDGE` needed); other scripts not yet. Read the PNGs | now (S003, S046) |
| `tools/smoke.sh <script> [outdir]` | smoke run in a hidden nested Wayland session (`tools/nested-session.sh start\|stop <dir> [WxH]`: Xvfb → nested niri, software GL, own runtime dir and bus; `SMOKE_SIZE` = nested output size, window at 0,0) with a throwaway home; selftest `click`/`rclick`/`pagescroll`/`pagetype` are real compositor input there (`tools/wl-input`, own crate, built on first use; `wtype`), `resize` goes through the nested niri; outdir (default `target/smoke/<name>-<time>`, use a fresh one: `home/` persists) gets `nacre.log`, `selftest.log`, `<shot>.png`, `<status>.json`, `home/`, `session/`; exits non-zero on crash, panic, no `status done` or a failed `assert <js>`. Scripts in `tests/smoke/` (`launch.txt` offline, `https.txt` needs internet, `restore.txt` with `SMOKE_HOME=<launch outdir>/home`, `chrome.txt` chrome and every flyout dark and light, offline; `colours.txt` colours after welcome and site colour vs internal pages, hidden `SMOKE_SIZE=1280x1100`; `input.txt` real clicks, typing, right click, wheel on a web page, offline; `basics.txt` tabs, navigation, find, zoom, full screen, pop-ups, offline; `heavy-web.txt` DuckDuckGo, Wikipedia, YouTube, needs internet, `SMOKE_TIMEOUT=900`; `keys.txt` every shortcut action, offline; `privacy-net.txt` DNT/GPC/Save-Data headers and third-party cookies on a loopback server, offline, start `python3 tests/smoke/net/server.py &` first; `site-doctor.txt` Google sign-in, captchas, Reddit, GitHub, needs internet; `cache.txt` HTTP cache, offline, start `python3 tests/smoke/cache/server.py &` first; selftest `launch <args>` checks single instance; `cookies.txt` → `cookies-restart.txt` → `cookies-cleared.txt` encrypted cookies across restarts with `SMOKE_KEYRING=1` (own throwaway GNOME Keyring + bus) and `SMOKE_HOME`, `cookies-nokeyring.txt` without, server.py first; `zap.txt` ad removal animation (cookie shield mid-animation, slots closed, players kept, Motion off), dark and light, offline, `SMOKE_SIZE=1280x900`; `stuck.txt` tab lifecycle (leave-page question, Reload, nacre:// pages free their view, Back with history, chatty page closes without CRITICAL, shortcut recording ends), offline, `SMOKE_SIZE=1280x900`; `nacre-lock.txt` web pages can't reach nacre:// and the passwords page asks on every open (D-049), server.py first, `SMOKE_SIZE=1280x900`; `crash-adblock.txt` R5-01 regression, ~1300 blocked loads with reloads/navigations mid-load plus 3200 timers under GC pressure, offline, server.py first); header documents env vars and commands. `SMOKE_VISIBLE=1` shows the run on the user's screen (real GPU; page input synthesized in the page, no `rclick`/`resize`); it refuses to start unless the user's niri config has the `dev.nacre.Nacre` window rule from the smoke.sh header (DP-1, no focus), so it never moves the user's focus or workspace (D-044). WebKit state (S050): launch, basics, input, keys, chrome, dialogs, pip, auth, stores-*, integ-spell, net-*, privacy-net, privacy-mode, cache*, crash-adblock green hidden (loopback skips the bridge, no `NACRE_NO_BRIDGE` needed); other scripts not yet. Read the PNGs | now (S003, S046) |
| `nacre://gallery` + `SMOKE_SIZE=1400x2800 tools/smoke.sh tests/smoke/gallery.txt` | every design token and widget, dark and light (+ new tab and settings shots); read the PNGs | now (S015) |
| `SMOKE_SIZE=1400x1200 tools/smoke.sh tests/smoke/newtab.txt` | new tab page dark/light, nothing playing and a video playing, weather failed state, tall/narrow/phone widths (offline); `tests/smoke/newtab-weather.txt` shoots the real weather card (needs internet); read the PNGs | now (S017) |
| `SMOKE_SIZE=1400x900 tools/smoke.sh tests/smoke/backgrounds.txt` | every new tab background with the pointer, Customize panel dark/light, image + blur, GIF frames; `perf-*-a/b.json` `frames` (median/max draw ms, `drawn` count) per background at Lots/Fast, hidden tab, still, Motion off. Selftest `pointer x y`, `customize`; `@PAGESDIR@` = path of tests/smoke/pages | now (S018) |

View file

@ -15,13 +15,13 @@ D-049. Today any web page can reach internal pages: `actions.rs` turns a page's
- `src/store/session.rs` + `Tab::saved` (how pages are saved)
## Steps
- [ ] Mark navigations as user-made vs web-made (WebKit `NavigationAction::navigation_type` / `is_user_gesture` + whether Nacre started it); deny web-made nacre:// in the policy and in new-window requests.
- [ ] Passwords: per-open unlock gate, relock on hide/switch/navigate/close, state cleared.
- [ ] Session: never save `nacre://passwords`.
- [ ] Unit tests: the allow/deny rule for nacre:// (pure function), session filter.
- [ ] `tests/smoke/nacre-lock.txt` (offline): a local page with a link, a redirect, `window.open`, and an iframe to `nacre://passwords` → tab never shows the page; address bar open → unlock prompt; switch tab and back → prompt again. Run it only (D-048).
- [ ] DESIGN.md: a short "Internal pages" note with the rule.
- [ ] PROGRESS entry, INDEX line, tracker, commit `S063: …`, push.
- [x] Mark navigations as user-made vs web-made (WebKit `NavigationAction::navigation_type` / `is_user_gesture` + whether Nacre started it); deny web-made nacre:// in the policy and in new-window requests.
- [x] Passwords: per-open unlock gate, relock on hide/switch/navigate/close, state cleared.
- [x] Session: never save `nacre://passwords`.
- [x] Unit tests: the allow/deny rule for nacre:// (pure function), session filter.
- [x] `tests/smoke/nacre-lock.txt` (offline): a local page with a link, a redirect, `window.open`, and an iframe to `nacre://passwords` → tab never shows the page; address bar open → unlock prompt; switch tab and back → prompt again. Run it only (D-048).
- [x] DESIGN.md: a short "Internal pages" note with the rule.
- [x] PROGRESS entry, INDEX line, tracker, commit `S063: …`, push.
## End criteria
- `cargo test` green; `nacre-lock.txt` exit 0 with the asserts above.

View file

@ -15,7 +15,7 @@ Dropped with Servo (D-032): S011, S029, S030, S032, S033, S037, S038.
- [x] [S060 — Picture in picture keeps working (focus)](09%20Fix%20round/S060-pip-focus.md) · Opus medium · 🧑
- [x] [S061 — A site's own context menu wins; video clicks don't open ads](09%20Fix%20round/S061-site-menus-clickthrough.md) · Opus medium · 🧑
- [x] [S062 — Memory saver that actually unloads, sliders, resting tab icons](09%20Fix%20round/S062-memory-saver.md) · Sonnet high
- [ ] [S063 — Lock down nacre:// pages; passwords unlock on every open](09%20Fix%20round/S063-nacre-pages-lockdown.md) · Opus medium
- [x] [S063 — Lock down nacre:// pages; passwords unlock on every open](09%20Fix%20round/S063-nacre-pages-lockdown.md) · Opus medium
- [ ] [S064 — History flyout, bookmark flyout on tab switch, About lists nacre:// pages](09%20Fix%20round/S064-history-flyout-about.md) · Sonnet high
- [ ] [S065 — Custom download manager by name and port](09%20Fix%20round/S065-custom-manager-port.md) · Sonnet high
- [ ] [S066 — UI alignment pass (/unslop)](09%20Fix%20round/S066-ui-alignment.md) · Opus medium · 🧑

View file

@ -115,6 +115,21 @@ extensions replaced by user scripts and styles, the context menu, the download m
- Fingerprinting: bits per metric and what privacy mode covers are in `docs/engine/privacy-mode.md` (the Servo-era
numbers there are historical).
## Internal pages (D-049, S063)
- Nacre's pages (`nacre://…`) are egui, never loaded into a web view, so any `nacre://` navigation a web view asks
for comes from web content: a link, middle click, `target=_blank`, `window.open`, script, frame, meta refresh or
HTTP redirect. The rule is `tabs::web_may_open`; it is enforced in the engine's `decide-policy` (`engine/host.rs`,
denied with one log line), again in `App::on_navigation` and `on_create_new` (backstops), and for the page's
context menu links (`MenuAction::OpenLink`). The one exception is `nacre://allowcert`, the certificate warning's
"Open anyway", taken only from the tab showing that warning.
- The user opens them: address bar, menus, buttons, shortcuts, bookmarks, command line (`Command::Open` /
`Navigate` / `ShowPage`).
- `nacre://passwords` asks first every time it is shown (master password, or a "Show passwords" click without one),
even while the vault is unlocked for autofill. When a frame draws without it (another tab, page, the tab closed)
`PageState::close_passwords` forgets the answer and every field it showed or took. It is saved and restored as a
new tab (`session::kept_url`).
## Media
Playback is WebKit's own (GStreamer) including Media Source Extensions; `tests/smoke/mse*.txt` are plain MSE tests.

View file

@ -498,6 +498,15 @@ Later: S010 list: user checks the Discord icon with their own client (the Discor
- Measured (hidden, 5 http tabs, tab 0 active, `NACRE_REST_UNIT_SECS=2`, discard 4 = 8 s; WebKitWebProcess of that run, summed `smaps_rollup` Pss, sampled every 2 s): all tabs open 15 processes / 774 MB; ~10 s after the hidden four unloaded 6 processes / 329 MB, settling at 295 MB. Unloading frees the web processes and their memory (no shared process or lingering view ref found); the 6 left include the active tab's and WebKit's spare ones. Both `has_web` expects false.
- Not done: no visible run.
## S063 — nacre:// pages locked down; passwords ask on every open (2026-11-18)
- Rule (D-049): `tabs::web_may_open` — web content never goes to `nacre://` (only `nacre://allowcert`, taken from the tab showing the certificate warning). Enforced in the engine's `decide-policy` for every navigation and new-window action (`engine/host.rs`, one `… denied: web pages can't open Nacre's pages` line), with backstops in `App::on_navigation` (no longer turns a page's `nacre://` navigation into `tab.page`), `on_create_new` (closes such a pop-up) and the page context menu's link items. Nacre's own pages, menus, address bar and bookmarks go through `Command::Open`/`ShowPage`, untouched.
- Passwords: the page asks every time it is shown (master password via `check_password` while the store is unlocked for filling; a "Show passwords" click in device mode, which has no password). A frame drawn without the page (`passwords_shown`, as S059's `capture_shown`) calls `PageState::close_passwords`: answer forgotten, revealed/edit/search/generator/master fields and egui's text edit states cleared.
- Session: `session::kept_url` saves and restores `nacre://passwords` as a new tab (title blank).
- Tests: `web_content_cannot_open_internal_pages`, `passwords_page_not_kept`; `tests/smoke/nacre-lock.txt` + `pages/nacre-lock.html`, `nacre-refresh.html`, server.py `/to-nacre` (302): link, middle click, `target=_blank`, `window.open` (click and script), `location=`, iframe, meta refresh, HTTP redirect all denied (12 log lines, tab count 1, page null); address bar → asks; another tab and back → asks; History and back → asks; master password set → asks. Status `lifecycle.passwords_open`.
- Verified: hidden `nacre-lock.txt` exit 0 (server.py running), shots read; session.json of the run has `nacre://newtab` for the passwords tab; `cargo test` 91 + webext 1.
- Not done: typing the master password into the gate isn't scripted (selftest has no egui text input), only the click path and the gate staying shut; window minimised (no frames) keeps the page open until it is drawn without it; no visible run.
- Decision for device mode (no master password, nothing to ask): a click gate, so no page can open it unseen; the orchestrator/user may want "set a master password" pushed harder.
## Later
- A link followed inside a frame still goes through the tab's navigation policy (WebKit's GTK API has no frame info; S050).
- file:// media outside the XDG user folders doesn't play (WebKit sandbox, D-043).

View file

@ -1317,7 +1317,7 @@ impl App {
return;
}
let cert_error = tab.cert_error.take();
if url.as_str() == "nacre://allowcert" {
if url.as_str() == crate::tabs::ALLOW_CERT {
request.deny();
if let (Some(error), Some(engine)) = (cert_error, &self.engine) {
engine.allow_certificate(&error);
@ -1328,13 +1328,10 @@ impl App {
return;
}
match url.scheme() {
// D-049: never one of Nacre's pages from a web page (the engine's policy already denied it).
"nacre" => {
eprintln!("tab {}: navigation to {url} denied: web pages can't open Nacre's pages", self.windows[&window].tabs[index].id);
request.deny();
if let Some(page) = Page::from_url(url.as_str()) {
let win = self.windows.get_mut(&window).expect("found");
win.tabs[index].page = Some(page);
self.redraw(window);
}
},
"view-source" => {
request.deny();
@ -1583,6 +1580,8 @@ impl App {
other => {
drop(menu);
match other {
// The link came from the page (D-049).
MenuAction::OpenLink(url, _) if !crate::tabs::web_may_open(&url) => eprintln!("tab {tab_id}: link to {url} not opened: web pages can't open Nacre's pages"),
MenuAction::OpenLink(url, how) => self.open(window, url, how, Some(tab_id)),
MenuAction::CopyText(text) => {
if let Ok(mut clipboard) = arboard::Clipboard::new() {

View file

@ -982,6 +982,16 @@ impl App {
/// addresses the ad lists block never get here: WebKit's content filters stop them.
fn on_create_new(&mut self, parent: ViewId, view: View, url: Option<Url>, gesture: bool) {
use crate::store::permissions::{Answer, Kind};
// D-049: a pop-up never opens one of Nacre's pages (WebKit's policy check denies it first; this is the
// backstop).
if url.as_ref().is_some_and(|u| !crate::tabs::web_may_open(u.as_str())) {
eprintln!("pop-up to {} denied: web pages can't open Nacre's pages", url.as_ref().map(Url::as_str).unwrap_or(""));
if let Some(engine) = &self.engine {
engine.forget(view.id());
}
view.close();
return;
}
let found = self.find_webview(parent);
let blocked = found.is_some_and(|(w, i)| {
let host = self.windows[&w].tabs[i].host();
@ -1878,7 +1888,11 @@ impl App {
tab.pinned = saved.pinned;
tab.muted = saved.muted;
tab.title = saved.title.clone();
match Page::from_url(&saved.url) {
let url = crate::store::session::kept_url(&saved.url);
if url != saved.url {
tab.title = String::new();
}
match Page::from_url(url) {
Some(page) => tab.page = Some(page),
None => {
tab.page = None;

View file

@ -721,6 +721,15 @@ impl Engine {
webkit::PolicyDecisionType::NavigationAction | webkit::PolicyDecisionType::NewWindowAction => {
let Some(nav) = decision.downcast_ref::<webkit::NavigationPolicyDecision>() else { return false };
let Some(mut action) = nav.navigation_action() else { return false };
// D-049: a page, its frames and its pop-ups never go to one of Nacre's pages (all of these come from
// web content: Nacre opens its pages without a web view).
if let Some(uri) = action.request().and_then(|r| r.uri())
&& !crate::tabs::web_may_open(&uri)
{
eprintln!("view {}: navigation to {uri} denied: web pages can't open Nacre's pages", id.0);
decision.ignore();
return true;
}
// A link clicked with the middle button or Ctrl opens in a new tab (Ctrl+Shift: in front), as in
// other browsers; WebKit would load it here.
let mods = gtk::gdk::ModifierType::from_bits_truncate(action.modifiers());

View file

@ -917,9 +917,10 @@ impl App {
let b = self.shared.bookmarks.borrow();
[crate::store::bookmarks::BAR, crate::store::bookmarks::OTHER].iter().filter_map(|id| b.get(*id)).map(|n| n.children.iter().filter(|c| c.is_folder()).count()).sum::<usize>()
};
// Web views alive (in use, forgotten but kept) and a shortcut being recorded (S059).
// Web views alive (in use, forgotten but kept), a shortcut being recorded (S059), the passwords page past its
// question (S063).
let views = self.engine.as_ref().map(|e| e.view_counts()).unwrap_or_default();
let lifecycle = serde_json::json!({"views": views.0, "views_leaked": views.1, "capture_key": self.windows.get(&window).map(|w| w.ui.pages.capture_key.is_some())});
let lifecycle = serde_json::json!({"views": views.0, "views_leaked": views.1, "capture_key": self.windows.get(&window).map(|w| w.ui.pages.capture_key.is_some()), "passwords_open": self.windows.get(&window).map(|w| w.ui.pages.passwords_open)});
serde_json::json!({
"windows": self.windows.len(),
"notifications": self.notifications_shown,

View file

@ -50,6 +50,12 @@ pub struct SavedSession {
pub saved_at: u64,
}
/// The address a tab is saved and restored with: the passwords page never goes into the session (it restores as
/// a new tab, S063).
pub fn kept_url(url: &str) -> &str {
if crate::tabs::Page::from_url(url) == Some(crate::tabs::Page::Passwords) { "nacre://newtab" } else { url }
}
pub struct Session {
path: PathBuf,
/// What was on disk at start: the previous run's windows.
@ -111,3 +117,17 @@ impl Session {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
// S063: the passwords page is never saved or restored.
#[test]
fn passwords_page_not_kept() {
assert_eq!(kept_url("nacre://passwords"), "nacre://newtab");
assert_eq!(kept_url("nacre:Passwords"), "nacre://newtab");
assert_eq!(kept_url("nacre://settings/privacy"), "nacre://settings/privacy");
assert_eq!(kept_url("https://example.com/passwords"), "https://example.com/passwords");
}
}

View file

@ -104,6 +104,18 @@ impl Page {
}
}
/// The certificate warning's "Open anyway" (`assets/pages/badcert.html`).
pub const ALLOW_CERT: &str = "nacre://allowcert";
/// D-049: whether web content (a page's links, redirects, scripts, frames, pop-ups, the links of its context menu)
/// may go to this address. Never to one of Nacre's pages: only the user opens those (address bar, menus, buttons,
/// shortcuts, bookmarks). The one exception is the certificate warning's "Open anyway", which the browser takes only
/// from the tab showing that warning.
pub fn web_may_open(url: &str) -> bool {
let nacre = |scheme: &str| scheme.eq_ignore_ascii_case("nacre");
url == ALLOW_CERT || !(Url::parse(url).is_ok_and(|u| nacre(u.scheme())) || nacre(url.trim_start().split(':').next().unwrap_or("")))
}
/// A question the tab is asking the user (shown as a bar above the page).
pub enum Prompt {
Permission { host: String, kind: crate::store::permissions::Kind, request: crate::engine::PermissionAsk },
@ -366,9 +378,11 @@ impl Tab {
/// What the session file keeps for this tab.
pub fn saved(&self) -> crate::store::session::SavedTab {
let url = self.pending_url.clone().unwrap_or_else(|| self.shown_url());
let kept = crate::store::session::kept_url(&url);
crate::store::session::SavedTab {
url: self.pending_url.clone().unwrap_or_else(|| self.shown_url()),
title: self.display_title(),
title: if kept == url { self.display_title() } else { String::new() },
url: kept.to_owned(),
pinned: self.pinned,
muted: self.muted,
history: self.back_forward.iter().map(Url::to_string).collect(),
@ -381,6 +395,17 @@ impl Tab {
mod tests {
use super::*;
// S063 (D-049): a page's navigations never reach Nacre's pages, except "Open anyway" of the certificate warning.
#[test]
fn web_content_cannot_open_internal_pages() {
for url in ["nacre://passwords", "NACRE://passwords", "nacre:passwords", " nacre://settings", "Nacre://allowcert/x", "nacre://newtab"] {
assert!(!web_may_open(url), "{url}");
}
for url in [ALLOW_CERT, "https://example.com/nacre://passwords", "about:blank", "data:text/html,x", "http://nacre/"] {
assert!(web_may_open(url), "{url}");
}
}
// S059: a close left without an answer must not keep the tab closing (Reload and navigation ignored) for good.
#[test]
fn unanswered_close_goes_ahead() {

View file

@ -221,6 +221,9 @@ pub fn draw(root: &mut egui::Ui, f: &mut Frame) {
if !std::mem::take(&mut f.ui.pages.capture_shown) {
f.ui.pages.capture_key = None;
}
if !std::mem::take(&mut f.ui.pages.passwords_shown) && f.ui.pages.passwords_open {
f.ui.pages.close_passwords(&ctx);
}
}
/// The page itself: a web page's framebuffer, or one of Nacre's pages.

View file

@ -52,6 +52,10 @@ pub struct PageState {
pub reauth_error: String,
pub unlock: String,
pub unlock_error: String,
/// The master password (or, without one, a click) was given since the passwords page was last shown (S063).
pub passwords_open: bool,
/// The passwords page was drawn this frame.
pub passwords_shown: bool,
pub generated: String,
pub gen_passphrase: bool,
pub script_edit: Option<(u64, String)>,
@ -66,6 +70,27 @@ pub struct PageState {
pub ntp_customize: bool,
}
impl PageState {
/// The passwords page left the screen (another tab, page or window state, the tab closed): it asks again next
/// time, and nothing it showed or was typed into it stays in memory (S063).
pub fn close_passwords(&mut self, ctx: &egui::Context) {
self.passwords_open = false;
self.passwords_search.clear();
self.revealed.clear();
self.login_edit = None;
self.address_edit = None;
self.card_edit = None;
self.reauth.clear();
self.reauth_error.clear();
self.unlock.clear();
self.unlock_error.clear();
self.generated.clear();
self.master = (String::new(), String::new());
// Text fields keep their text for undo.
ctx.data_mut(|d| d.remove_by_type::<egui::text_edit::TextEditState>());
}
}
pub fn draw(ui: &mut Ui, f: &mut Frame, page: &Page) {
match page {
Page::NewTab => newtab::draw(ui, f),

View file

@ -18,7 +18,9 @@ pub fn draw(ui: &mut Ui, f: &mut Frame) {
page_column(ui, "passwords", 900.0, |ui| {
let subtitle = if f.incognito() { "Incognito windows have their own empty store that is thrown away when they close." } else { "" };
page_header(ui, "Passwords and autofill", subtitle, |_| {});
if f.shared.vault.borrow().locked() {
f.ui.pages.passwords_shown = true;
// Every time the page opens it asks first, even when the store is unlocked for filling in (S063).
if f.shared.vault.borrow().locked() || !f.ui.pages.passwords_open {
unlock(ui, f);
return;
}
@ -58,6 +60,15 @@ fn unlock(ui: &mut Ui, f: &mut Frame) {
super::super::widgets::icon(ui, rect.center(), icons::LOCK, theme::ICON_LARGE, true, p.on_secondary_container);
ui.add_space(theme::GAP_L);
ui.label(RichText::new("Your passwords are locked").font(theme::font(theme::TITLE, Weight::Medium)).color(p.on_surface));
// Without a master password there is nothing to ask: a click shows them (no page can click it, D-049).
if f.shared.vault.borrow().mode() != Mode::Master {
ui.label(RichText::new("Set a master password to keep others from seeing them.").font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
ui.add_space(theme::GAP_L);
if button(ui, ButtonKind::Filled, Some(icons::LOCK_OPEN), "Show passwords").clicked() {
f.ui.pages.passwords_open = true;
}
return;
}
ui.label(RichText::new("Enter your master password to see and fill them.").font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface_variant));
ui.add_space(theme::GAP_L);
let r = password_field(ui, &mut f.ui.pages.unlock, "Master password", 280.0);
@ -65,9 +76,14 @@ fn unlock(ui: &mut Ui, f: &mut Frame) {
let go = button(ui, ButtonKind::Filled, Some(icons::LOCK_OPEN), "Unlock").clicked() || (r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)));
if go {
let pw = std::mem::take(&mut f.ui.pages.unlock);
match f.shared.vault.borrow_mut().unlock(&pw) {
Ok(()) => f.ui.pages.unlock_error.clear(),
Err(_) => f.ui.pages.unlock_error = "That master password is not right. Try again.".into(),
let mut vault = f.shared.vault.borrow_mut();
let ok = if vault.locked() { vault.unlock(&pw).is_ok() } else { vault.check_password(&pw) };
drop(vault);
if ok {
f.ui.pages.unlock_error.clear();
f.ui.pages.passwords_open = true;
} else {
f.ui.pages.unlock_error = "That master password is not right. Try again.".into();
}
r.request_focus();
}

View file

@ -0,0 +1,93 @@
# nacre:// lockdown (S063, D-049): a web page's link, middle click, target=_blank, window.open, script navigation,
# frame, meta refresh and HTTP redirect to nacre://passwords never show one of Nacre's pages; the user's address bar
# does, and the passwords page asks first every time it is shown (here without a master password: its button).
# Offline. Run: python3 tests/smoke/net/server.py & then SMOKE_SIZE=1280x900 tools/smoke.sh tests/smoke/nacre-lock.txt ;
# `grep -c "can't open Nacre's pages" <out>/nacre.log` > 0.
wait 3
resize 1280 900
open @PAGES@/nacre-lock.html
waitload
wait 1
expect /active/page null
expect /tab_count 1
# The frame stayed empty: it never got Nacre's page (nothing to read, WebKit has no such address).
assert document.getElementById('state').textContent === 'web page'
locate #link
wait 0.5
click @
wait 1
expect /active/page null
mclick @
wait 1
expect /tab_count 1
locate #blank
wait 0.5
click @
wait 1
expect /tab_count 1
locate #popup
wait 0.5
click @
wait 1
expect /tab_count 1
expect /active/page null
locate #script
wait 0.5
click @
wait 1
expect /active/page null
js location.href = 'nacre://passwords'
wait 1
expect /active/page null
assert location.href.endsWith('nacre-lock.html')
js window.open('nacre://settings')
wait 1
expect /tab_count 1
shot web-denied
open @PAGES@/nacre-refresh.html
waitload
wait 2
expect /active/page null
assert location.href.endsWith('nacre-refresh.html')
open http://127.0.0.1:8767/to-nacre
wait 3
expect /active/page null
expect /tab_count 1
# The user opens it: it asks first.
cmd navigate nacre://passwords
wait 1
expect /active/page "nacre://passwords"
expect /lifecycle/passwords_open false
shot ask
tap 640 400
wait 1
expect /lifecycle/passwords_open true
shot open
# Another tab and back: it asks again.
do new_tab
wait 1
expect /lifecycle/passwords_open false
cmd select 0
wait 1
expect /active/page "nacre://passwords"
expect /lifecycle/passwords_open false
shot ask-again
tap 640 400
wait 1
expect /lifecycle/passwords_open true
# Away to another page in the same tab and back by the address bar: asks again.
cmd navigate nacre://history
wait 1
cmd navigate nacre://passwords
wait 1
expect /lifecycle/passwords_open false
# With a master password and the store unlocked (for filling in), it still asks for the password.
vault master smoke-pw
cmd navigate nacre://history
wait 1
cmd navigate nacre://passwords
wait 1
expect /lifecycle/passwords_open false
shot ask-master
status done
quit

View file

@ -27,6 +27,7 @@ certificate for *.nacre.test. Port 8767 speaks plain HTTP only (an HTTPS upgrade
is titled "Signed in as U" or "Signed out" (S025 restart smoke; the value stays out of history)
/jstp?tag=T page with a cross-site frame (/jscookie) that writes and reads document.cookie and reports what
it read as /note?tag=T&seen=... (S024)
/to-nacre 302 redirect to nacre://passwords (S063: a web redirect must not open Nacre's pages)
/reset empties the "reqs" list of /log
/log JSON: every request path, DNS name asked, Range header and download manager call; "reqs" has
each GET's host, path, Cookie, DNT, Sec-GPC, Save-Data, Accept-Language and User-Agent headers
@ -159,6 +160,8 @@ class Handler(BaseHTTPRequestHandler):
wire = parse_qs(url.query).get("dns", [""])[0]
query = base64.urlsafe_b64decode(wire + "=" * (-len(wire) % 4))
return self.reply(dns_answer(query), "application/dns-message")
if path == "/to-nacre":
return self.reply(b"", "text/html", {"Location": "nacre://passwords"}, 302)
if path == "/reset":
with lock:
log["reqs"].clear()

View file

@ -0,0 +1,11 @@
<!doctype html>
<meta charset="utf-8">
<title>Nacre lock</title>
<!-- S063 (D-049): every way a web page could reach one of Nacre's pages; none may. -->
<style>body { font: 18px sans-serif; margin: 40px } a, button { display: block; margin: 16px 0; font-size: 18px } iframe { width: 400px; height: 120px }</style>
<p id="state">web page</p>
<a id="link" href="nacre://passwords">Link to nacre://passwords</a>
<a id="blank" href="nacre://passwords" target="_blank">Link to nacre://passwords in a new window</a>
<button id="popup" onclick="window.open('nacre://passwords')">window.open nacre://passwords</button>
<button id="script" onclick="location.href = 'nacre://passwords'">location = nacre://passwords</button>
<iframe id="frame" src="nacre://passwords"></iframe>

View file

@ -0,0 +1,6 @@
<!doctype html>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=nacre://passwords">
<title>Nacre refresh</title>
<!-- S063: a meta refresh to one of Nacre's pages stays here. -->
<p>meta refresh to nacre://passwords</p>