fix(mcp): every web sign-in is asked in the window, with a matching code (P15 B1 review, D-90)

An approval is never reused for a new sign-in: the product's redirect host
is public, so a stranger registering a client with claude.ai's callback got
a code with no Allow. /authorize now always parks the request. Every Allow
is a new approval with exactly the permissions ticked, a revoke ends the
approval's tokens at once under the lock, and raising or lowering posting
swaps the token in one step (a revoke during it wins). The window shows a
short code the browser's page also shows, says what is known in neutral
words (where it is sent back to first), counts the requests beyond the
newest few, and no request is presented as a known product on the strength
of its host. Refresh checks and marks the token used in one hold of the
lock, so two refreshes at once cannot both succeed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 12:05:09 -07:00
1 parent 0a91656f14
commit c4fd1580d8
11 files changed
+1461 -615

No files matched your search

+71 -16
View File
@@ -51,9 +51,16 @@
//! Allow and Don't allow; it appears over any page of the company
//! (`State::web_prompt`) and on this page (`State::web_section`).
//! Nothing on the web page can approve: only these buttons do, through
//! the owner. What the assistant calls itself is shown in quotes and
//! is never what names the product. Posting is off unless the person
//! ticks it, per assistant, and can be turned on or off later.
//! the owner. What is known is said in neutral words, where it will be
//! sent back to first ("An assistant that will be sent back to
//! claude.ai"), never as a known or trusted product on the strength of
//! that address: a host is public, and says nothing of who asks. Each
//! card shows its own short code, the one its browser page shows, and
//! says to allow only on a match; at most MOST_CARDS cards are drawn
//! at once, the newest, and the rest are counted. What the assistant
//! calls itself is shown in quotes, after the address. Posting is off
//! unless the person ticks it, per assistant, and can be turned on or
//! off later; every Allow is a new approval with only what is ticked.
//! ```
use crate::connections::{Connection, Link, Status, describe, program_name};
@@ -461,12 +468,14 @@ impl State {
ui.add_space(24.0);
section(ui, "Assistants on the web");
let mut want: Want = None;
for request in &status.web_pending {
let (shown, more) = newest_waiting(&status.web_pending);
for request in shown {
if let Some(w) = self.pending_card(ui, status, request, owner) {
want = Some(w);
}
ui.add_space(6.0);
}
say_more_waiting(ui, more);
for a in &status.web_approvals {
Frame::new()
.fill(p.surface)
@@ -537,26 +546,40 @@ impl State {
.inner_margin(Margin::symmetric(14, 12))
.show(ui, |ui| {
ui.set_width(ui.available_width());
// What is known is said in neutral words: where it will be
// sent back to first, never a product's name made from it.
ui.label(
RichText::new(format!(
"{} wants to connect to {}. Allow?",
request.client_name, status.company
"An assistant that will be sent back to {} wants to connect to {}. Allow?",
request.redirect_host, status.company
))
.font(theme::semibold(15.0)),
);
ui.add_space(4.0);
if request.recognised {
if !request.client_name.is_empty() {
ui.label(
RichText::new(
"Only allow it if you just asked this assistant to connect.",
)
RichText::new(format!(
"It calls itself \u{201c}{}\u{201d}. That is only its own word for itself.",
request.client_name
))
.font(theme::regular(13.0))
.color(p.muted),
);
} else {
}
ui.add_space(4.0);
ui.label(
RichText::new(format!("Code {}", request.code)).font(theme::semibold(22.0)),
);
ui.label(
RichText::new(
"Allow only if the page in your browser shows this same code. If it shows another code, or you didn't just ask an assistant to connect, choose Don't allow.",
)
.font(theme::regular(13.0))
.color(p.muted),
);
if !request.known_host {
ui.label(
RichText::new(
"Wanderbooks doesn't recognise this assistant: it only gave this name for itself. Don't allow it unless you just set it up yourself.",
"Wanderbooks doesn't know this address. Don't allow it unless you just set this assistant up yourself.",
)
.font(theme::regular(13.0))
.color(p.warning),
@@ -622,9 +645,9 @@ impl State {
let owner = owner.clone()?;
let id = request.id.clone();
let what = if approve {
format!("Allow {}", request.client_name)
format!("Allow the assistant sent back to {}", request.redirect_host)
} else {
format!("Don't allow {}", request.client_name)
format!("Don't allow the assistant sent back to {}", request.redirect_host)
};
Some((
what,
@@ -655,12 +678,14 @@ impl State {
.resizable(false)
.anchor(egui::Align2::CENTER_CENTER, vec2(0.0, 0.0))
.show(ui.ctx(), |win| {
for request in &status.web_pending {
let (shown, more) = newest_waiting(&status.web_pending);
for request in shown {
if let Some(w) = self.pending_card(win, status, request, owner) {
want = Some(w);
}
win.add_space(6.0);
}
say_more_waiting(win, more);
});
if let Some((what, keep, work)) = want {
self.start(ui, jobs, what, &keep, work);
@@ -857,6 +882,36 @@ impl State {
}
}
/// The most requests drawn at once: a few addresses must not be able to
/// bury the one the person is waiting for under a screenful.
pub const MOST_CARDS: usize = 3;
/// The newest requests (the one just asked for is the one the person is
/// looking for), and how many more are waiting.
fn newest_waiting(all: &[crate::owner::WebRequest]) -> (Vec<&crate::owner::WebRequest>, usize) {
let mut sorted: Vec<&crate::owner::WebRequest> = all.iter().collect();
// Most time left is the newest.
sorted.sort_by(|a, b| b.expires_in_secs.cmp(&a.expires_in_secs));
let more = sorted.len().saturating_sub(MOST_CARDS);
sorted.truncate(MOST_CARDS);
(sorted, more)
}
fn say_more_waiting(ui: &mut Ui, more: usize) {
if more == 0 {
return;
}
let p = pal(ui.ctx());
ui.label(
RichText::new(format!(
"{more} more {} waiting. Answer these first; the next ones then show.",
if more == 1 { "is" } else { "are" }
))
.font(theme::regular(12.5))
.color(p.muted),
);
}
fn section(ui: &mut Ui, title: &str) {
ui.label(RichText::new(title).font(theme::semibold(17.0)));
ui.add_space(4.0);
+8 -4
View File
@@ -213,11 +213,15 @@ pub struct WebRequest {
pub id: String,
/// The company it asks to reach.
pub book: String,
/// The product recognised by where it is sent back to ("Claude on
/// the web"), else what it calls itself.
/// What it calls itself: its own word, cleaned and short, possibly
/// empty. Never a product's name made from where it is sent back to.
pub client_name: String,
/// Whether the product is one Wanderbooks recognises.
pub recognised: bool,
/// Whether the address it is sent back to is one of the vendors' known
/// hosts. Only the warning depends on it; nothing is shown as known or
/// trusted for it.
pub known_host: bool,
/// The short code to match with the one its browser page shows.
pub code: String,
/// The address it is sent back to, in full.
pub redirect: String,
/// That address's host.
+63 -13
View File
@@ -1080,12 +1080,13 @@ fn pictures() {
// ---- 7: a web assistant asks to connect (plan P15 D-83, unit B1) --------------
fn asking(id: &str, name: &str, recognised: bool) -> WebRequest {
fn asking(id: &str, name: &str, known_host: bool) -> WebRequest {
WebRequest {
id: id.into(),
book: "alpha".into(),
client_name: name.into(),
recognised,
known_host,
code: format!("482 {}", 100 + id.len()),
redirect: "https://claude.ai/api/mcp/auth_callback".into(),
redirect_host: "claude.ai".into(),
from: "203.0.113.9".into(),
@@ -1108,23 +1109,38 @@ fn a_web_assistant_asking_is_put_to_the_person_over_any_page_in_plain_words() {
let owner = Fake::new();
with_pending(
&owner,
vec![asking("p_1", "Claude on the web", true)],
vec![asking("p_1", "Claude", true)],
vec![],
);
let mut h = start(&w, &["alpha"], &owner);
refresh(&mut h);
// On the company's own page, not the Connect page.
assert_ne!(h.state().route(), &Route::Connect);
// Where it is sent back to first, in neutral words: a host says nothing
// of who asks, so nothing is called a known product, and the one
// address of a vendor is not warned about, nor praised.
assert!(
h.query_by_label_contains("Claude on the web wants to connect to Wanderland Labs. Allow?")
h.query_by_label_contains(
"An assistant that will be sent back to claude.ai wants to connect to Wanderland Labs. Allow?"
)
.is_some()
);
assert!(h.query_by_label_contains("Claude on the web").is_none());
assert!(h.query_by_label_contains("doesn't know this address").is_none());
// What it calls itself, after the address, as its own word.
assert!(h.query_by_label_contains("It calls itself").is_some());
// The code to match with the one the browser's page shows.
assert!(h.query_by_label_contains("Code 482 103").is_some());
assert!(
h.query_by_label_contains("Allow only if the page in your browser shows this same code")
.is_some()
);
// Who, where it goes, from where: in words, nothing about OAuth.
assert!(
h.query_by_label_contains("sent back to claude.ai")
h.query_all_by_label_contains("The request came from the internet address 203.0.113.9")
.next()
.is_some()
);
assert!(h.query_by_label_contains("203.0.113.9").is_some());
assert!(
h.query_by_label_contains("can't post entries unless you tick")
.is_some()
@@ -1162,11 +1178,8 @@ fn refusing_and_allowing_with_posting_are_their_own_answers() {
);
let mut h = start(&w, &["alpha"], &owner);
refresh(&mut h);
// A product that is not recognised is said not to be.
assert!(
h.query_by_label_contains("doesn't recognise this assistant")
.is_some()
);
// An address that isn't a known vendor's keeps its warning.
assert!(h.query_by_label_contains("doesn't know this address").is_some());
h.get_by_role_and_label(Role::Button, "Don't allow").click();
h.run_steps(2);
wait_for("the refusal was given", || {
@@ -1179,7 +1192,7 @@ fn refusing_and_allowing_with_posting_are_their_own_answers() {
// Another asks; this time posting is ticked, then allowed.
with_pending(
&owner,
vec![asking("p_8", "Claude on the web", true)],
vec![asking("p_8", "Claude", true)],
vec![],
);
refresh(&mut h);
@@ -1195,13 +1208,50 @@ fn refusing_and_allowing_with_posting_are_their_own_answers() {
drop(h);
}
#[test]
fn waiting_requests_each_show_their_own_code_and_only_a_few_are_drawn() {
let w = World::new(&[("alpha", "Wanderland Labs")]);
let owner = Fake::new();
let mut all = Vec::new();
for (i, id) in ["p_a", "p_b", "p_c", "p_d", "p_e"].iter().enumerate() {
let mut r = asking(id, "Claude", true);
// Never merged: each has its own code.
r.code = format!("{}{}{} 6{}{}", i, i, i, i, i);
// The later the id, the newer it is (more time left).
r.expires_in_secs = 100 + 10 * i as u64;
all.push(r);
}
with_pending(&owner, all, vec![]);
let mut h = start(&w, &["alpha"], &owner);
refresh(&mut h);
// The newest three, each with its own code; the rest are counted.
for shown in ["444 644", "333 633", "222 622"] {
assert!(
h.query_by_label_contains(&format!("Code {shown}")).is_some(),
"{shown}"
);
}
for hidden in ["111 611", "000 600"] {
assert!(
h.query_by_label_contains(&format!("Code {hidden}")).is_none(),
"{hidden}"
);
}
assert_eq!(
h.query_all_by_label_contains("wants to connect").count(),
3
);
assert!(h.query_by_label_contains("2 more are waiting").is_some());
drop(h);
}
#[test]
fn a_request_that_ran_out_goes_away_and_posting_is_turned_on_and_off_on_the_connect_page() {
let w = World::new(&[("alpha", "Wanderland Labs")]);
let owner = Fake::new();
with_pending(
&owner,
vec![asking("p_2", "Claude on the web", true)],
vec![asking("p_2", "Claude", true)],
vec![],
);
let mut h = start(&w, &["alpha"], &owner);