@aarwitz/tapp 0.23.0 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tapp",
|
|
3
3
|
"description": "Give Claude hands and eyes on iOS, Android, and web apps, with exploration, replayable flows, evidence, and deterministic CI gates.",
|
|
4
|
-
"version": "0.23.
|
|
4
|
+
"version": "0.23.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aaron Horowitz",
|
|
7
7
|
"url": "https://github.com/aarwitz"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"command": "npx",
|
|
25
25
|
"args": [
|
|
26
26
|
"-y",
|
|
27
|
-
"@aarwitz/tapp@0.23.
|
|
27
|
+
"@aarwitz/tapp@0.23.1",
|
|
28
28
|
"mcp"
|
|
29
29
|
],
|
|
30
30
|
"cwd": "${CLAUDE_PROJECT_DIR}"
|
package/browser/app.js
CHANGED
|
@@ -850,7 +850,13 @@ document.addEventListener("click", (event) => {
|
|
|
850
850
|
if (button && button.type === "button") { event.preventDefault(); answerAsk(button.closest("#chat-ask"), button.dataset.ask); }
|
|
851
851
|
const play = event.target.closest("[data-run-journey]");
|
|
852
852
|
if (play) { event.preventDefault(); runJourney(play.dataset.runJourney).catch((error) => toast(error.message, true)); }
|
|
853
|
-
if (event.target.closest("[data-signin]")) {
|
|
853
|
+
if (event.target.closest("[data-signin]")) {
|
|
854
|
+
event.preventDefault();
|
|
855
|
+
// With Cloudflare Access in front, the sign-in page is Cloudflare's; otherwise ask for an
|
|
856
|
+
// address here and mail a link.
|
|
857
|
+
if (state.session?.signInProvider === "cloudflare") { location.href = "/auth/cloudflare"; return; }
|
|
858
|
+
state.signInOpen = true; renderAccount(); showPrompt(); setTimeout(() => $("#signin-email")?.focus(), 50);
|
|
859
|
+
}
|
|
854
860
|
if (event.target.closest("[data-signout]")) { event.preventDefault(); signOut(); }
|
|
855
861
|
const forget = event.target.closest("[data-forget-actor]");
|
|
856
862
|
if (forget) { event.preventDefault(); forgetActor(forget.dataset.forgetHost, forget.dataset.forgetActor).catch((error) => toast(error.message, true)); }
|
package/docs/BROWSER-PRODUCT.md
CHANGED
|
@@ -93,6 +93,15 @@ There is no password. Links work once and expire in 15 minutes; sessions last 90
|
|
|
93
93
|
SHA-256 of either token is on disk (`account-store.js`). One address may ask for five links per
|
|
94
94
|
ten minutes, and the reply is the same whether or not the address has an account.
|
|
95
95
|
|
|
96
|
+
**Cloudflare Access instead of mail.** When the host is fronted by Cloudflare, put an Access
|
|
97
|
+
application on exactly `app.runtapp.com/auth/cloudflare` (policy: allow everyone; login method:
|
|
98
|
+
one-time PIN or Google) and set `TAPP_ACCESS_TEAM_DOMAIN` (`<team>.cloudflareaccess.com`) and
|
|
99
|
+
`TAPP_ACCESS_AUD` (the application's audience tag). *Sign in* then goes to Cloudflare, which
|
|
100
|
+
proves the address itself and returns with a signed assertion (`Cf-Access-Jwt-Assertion`);
|
|
101
|
+
`access-jwt.js` checks the RS256 signature against the team's published keys, the audience, the
|
|
102
|
+
issuer and the expiry, and opens the same session the link flow would. tapp sends no email.
|
|
103
|
+
`/api/session.signInProvider` tells the Studio which of the two to offer.
|
|
104
|
+
|
|
96
105
|
**Mail** is sent through Resend when `TAPP_MAIL_RESEND_KEY` and `TAPP_MAIL_FROM` are set
|
|
97
106
|
(`mailer.js`). Without them, each message is written as a 0600 `.eml` into `TAPP_MAIL_OUTBOX`
|
|
98
107
|
(default `TAPP_HOME/mail-outbox`) — what tests and a local trial use, and what a freshly deployed
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Signing in through Cloudflare Access.
|
|
2
|
+
//
|
|
3
|
+
// When app.runtapp.com puts Cloudflare Access in front of one path (/auth/cloudflare), Cloudflare
|
|
4
|
+
// does the whole identity dance itself — one-time PIN to the address, or Google — and forwards
|
|
5
|
+
// the request with a signed JWT (`Cf-Access-Jwt-Assertion`) that names the email. tapp then never
|
|
6
|
+
// sends an email of its own; it just checks the signature against the team's published keys and
|
|
7
|
+
// opens a session for that address.
|
|
8
|
+
//
|
|
9
|
+
// Verification is deliberately plain Node: RS256 over the JWT's signing input, keys fetched from
|
|
10
|
+
// https://<team>.cloudflareaccess.com/cdn-cgi/access/certs and cached for an hour, `aud` pinned
|
|
11
|
+
// to this application's tag, `iss` pinned to the team, `exp` honoured. Nothing else is trusted.
|
|
12
|
+
import crypto from "node:crypto";
|
|
13
|
+
|
|
14
|
+
const b64url = (value) => Buffer.from(String(value).replace(/-/g, "+").replace(/_/g, "/"), "base64");
|
|
15
|
+
const JWKS_TTL_MS = 60 * 60 * 1000;
|
|
16
|
+
|
|
17
|
+
export function accessConfig(env = process.env) {
|
|
18
|
+
const teamDomain = (env.TAPP_ACCESS_TEAM_DOMAIN || "").trim().replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
19
|
+
const aud = (env.TAPP_ACCESS_AUD || "").trim();
|
|
20
|
+
return teamDomain && aud ? { teamDomain, aud } : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createAccessVerifier({ teamDomain, aud, fetchImpl = fetch, now = () => Date.now() }) {
|
|
24
|
+
const issuer = `https://${teamDomain}`;
|
|
25
|
+
let cache = { keys: null, fetchedAt: 0 };
|
|
26
|
+
|
|
27
|
+
async function keys(force = false) {
|
|
28
|
+
if (!force && cache.keys && now() - cache.fetchedAt < JWKS_TTL_MS) return cache.keys;
|
|
29
|
+
const response = await fetchImpl(`${issuer}/cdn-cgi/access/certs`);
|
|
30
|
+
if (!response.ok) throw new Error(`Access keys unavailable (${response.status})`);
|
|
31
|
+
const body = await response.json();
|
|
32
|
+
cache = { keys: (body.keys || []).filter((k) => k.kty === "RSA"), fetchedAt: now() };
|
|
33
|
+
return cache.keys;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Returns { email } for a valid assertion, or throws with a one-line reason. */
|
|
37
|
+
async function verify(token) {
|
|
38
|
+
const parts = String(token || "").split(".");
|
|
39
|
+
if (parts.length !== 3) throw new Error("Not an Access token");
|
|
40
|
+
let header, claims;
|
|
41
|
+
try { header = JSON.parse(b64url(parts[0]).toString("utf8")); claims = JSON.parse(b64url(parts[1]).toString("utf8")); }
|
|
42
|
+
catch { throw new Error("Malformed Access token"); }
|
|
43
|
+
if (header.alg !== "RS256" || !header.kid) throw new Error("Unexpected Access token algorithm");
|
|
44
|
+
let jwk = (await keys()).find((k) => k.kid === header.kid);
|
|
45
|
+
if (!jwk) jwk = (await keys(true)).find((k) => k.kid === header.kid); // rotated since we cached
|
|
46
|
+
if (!jwk) throw new Error("Access token signed by an unknown key");
|
|
47
|
+
const key = crypto.createPublicKey({ key: jwk, format: "jwk" });
|
|
48
|
+
const valid = crypto.verify("sha256", Buffer.from(`${parts[0]}.${parts[1]}`), { key, padding: crypto.constants.RSA_PKCS1_PADDING }, b64url(parts[2]));
|
|
49
|
+
if (!valid) throw new Error("Access token signature does not verify");
|
|
50
|
+
const audience = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
|
|
51
|
+
if (!audience.includes(aud)) throw new Error("Access token is for a different application");
|
|
52
|
+
if (claims.iss !== issuer) throw new Error("Access token is from a different team");
|
|
53
|
+
if (typeof claims.exp !== "number" || claims.exp * 1000 < now()) throw new Error("Access token has expired");
|
|
54
|
+
const email = String(claims.email || "").trim().toLowerCase();
|
|
55
|
+
if (!email) throw new Error("Access token carries no email");
|
|
56
|
+
return { email };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { verify, issuer };
|
|
60
|
+
}
|
|
@@ -83,7 +83,13 @@ export class AccountStore {
|
|
|
83
83
|
const link = readJson(file);
|
|
84
84
|
try { fs.rmSync(file, { force: true }); } catch { /* spent either way */ }
|
|
85
85
|
if (!link || Date.parse(link.expiresAt) < this.now()) return null;
|
|
86
|
-
|
|
86
|
+
return this.signIn(link.email);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Open a session for an address whose owner has already been verified (a redeemed link, or
|
|
90
|
+
* an identity provider such as Cloudflare Access). */
|
|
91
|
+
signIn(rawEmail) {
|
|
92
|
+
const account = this.#ensureAccount(normalizeEmail(rawEmail));
|
|
87
93
|
const session = token();
|
|
88
94
|
writeJson(this.#file("sessions", sha(session)), { accountId: account.id, createdAt: new Date(this.now()).toISOString(), expiresAt: new Date(this.now() + SESSION_TTL_MS).toISOString() });
|
|
89
95
|
return { session, account };
|
|
@@ -20,6 +20,7 @@ import { JobLanes } from "./job-lanes.js";
|
|
|
20
20
|
import { AccountStore } from "./account-store.js";
|
|
21
21
|
import { ActorStore, hostKey } from "./actor-store.js";
|
|
22
22
|
import { createMailer, signInMessage } from "./mailer.js";
|
|
23
|
+
import { accessConfig, createAccessVerifier } from "./access-jwt.js";
|
|
23
24
|
|
|
24
25
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
25
26
|
const assetRoot = path.join(packageRoot, "browser");
|
|
@@ -132,8 +133,8 @@ function anonymousAllows(method, pathname) {
|
|
|
132
133
|
if (/^\/api\/captures\/[A-Za-z0-9._-]{1,128}\/files$/.test(pathname)) return true;
|
|
133
134
|
if (/^\/evidence\/captures\//.test(pathname)) return true;
|
|
134
135
|
if (/^\/api\/jobs\/[a-f0-9]{20}(\/frame)?$/.test(pathname)) return true;
|
|
135
|
-
// Following a sign-in link from an email.
|
|
136
|
-
if (/^\/auth\/[A-Za-z0-9_-]{20,}$/.test(pathname)) return true;
|
|
136
|
+
// Following a sign-in link from an email, or arriving back from Cloudflare Access.
|
|
137
|
+
if (pathname === "/auth/cloudflare" || /^\/auth\/[A-Za-z0-9_-]{20,}$/.test(pathname)) return true;
|
|
137
138
|
return false;
|
|
138
139
|
}
|
|
139
140
|
// Asking for a sign-in link is the one thing a stranger may post besides a run.
|
|
@@ -453,7 +454,7 @@ function serveLoginPage(response, { failed = false, next = "" } = {}) {
|
|
|
453
454
|
response.end(html);
|
|
454
455
|
}
|
|
455
456
|
|
|
456
|
-
export async function startBrowserProduct({ projectDir, port = 0, launch = false, workspaceRoot, githubProvider, publicOrigin = "", trustedProxyToken = "", directLogin = null, publicEgressOnly = null, publicAccess = false } = {}) {
|
|
457
|
+
export async function startBrowserProduct({ projectDir, port = 0, launch = false, workspaceRoot, githubProvider, publicOrigin = "", trustedProxyToken = "", directLogin = null, publicEgressOnly = null, publicAccess = false, accessVerifier = undefined } = {}) {
|
|
457
458
|
const hosted = !!trustedProxyToken || !!directLogin || !!publicAccess;
|
|
458
459
|
// publicOrigin accepts a comma-separated allowlist; the first entry is canonical.
|
|
459
460
|
const publicOrigins = String(publicOrigin || "").split(",").map((value) => value.trim().replace(/\/$/, "")).filter(Boolean);
|
|
@@ -489,6 +490,16 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
489
490
|
// Accounts exist only on a public Studio: a local one has exactly one person, the operator.
|
|
490
491
|
const accounts = publicAccess ? new AccountStore() : null;
|
|
491
492
|
const mailer = publicAccess ? createMailer() : null;
|
|
493
|
+
// With Cloudflare Access in front of /auth/cloudflare, identity comes from Cloudflare's signed
|
|
494
|
+
// assertion and tapp sends no email at all. Configured by TAPP_ACCESS_TEAM_DOMAIN + TAPP_ACCESS_AUD;
|
|
495
|
+
// tests inject a verifier. The email link stays available as the provider-free path.
|
|
496
|
+
const access = accessVerifier !== undefined ? accessVerifier : (publicAccess && accessConfig() ? createAccessVerifier(accessConfig()) : null);
|
|
497
|
+
const signInProvider = access ? "cloudflare" : "email";
|
|
498
|
+
const openAccountSession = (response, signedIn, location = "/?signin=done") => {
|
|
499
|
+
logUsage("signin.done", { account: signedIn.account.id.slice(0, 8), provider: signInProvider });
|
|
500
|
+
response.writeHead(303, { location, "set-cookie": `${ACCOUNT_COOKIE}=${encodeURIComponent(signedIn.session)}; HttpOnly; SameSite=Lax;${secureCookies ? " Secure;" : ""} Path=/; Max-Age=7776000` });
|
|
501
|
+
response.end();
|
|
502
|
+
};
|
|
492
503
|
const secureCookies = publicOrigins[0]?.startsWith("https:") ?? false;
|
|
493
504
|
const serverStartedAt = new Date().toISOString();
|
|
494
505
|
const sessionToken = crypto.randomBytes(32).toString("base64url");
|
|
@@ -731,9 +742,23 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
731
742
|
if (authLinkMatch) {
|
|
732
743
|
const signedIn = accounts.redeem(authLinkMatch[1]);
|
|
733
744
|
if (!signedIn) { response.writeHead(303, { location: "/?signin=expired" }); response.end(); return; }
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
745
|
+
openAccountSession(response, signedIn);
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
// Back from Cloudflare Access: the assertion header is only ever set by Cloudflare on a
|
|
749
|
+
// request that passed its policy, and the signature proves it. Without Access configured
|
|
750
|
+
// the path says so instead of pretending.
|
|
751
|
+
if (publicAccess && request.method === "GET" && url.pathname === "/auth/cloudflare") {
|
|
752
|
+
if (!access) { response.writeHead(404, { "content-type": "text/plain; charset=utf-8" }); response.end("Cloudflare Access sign-in is not configured here; use the email link."); return; }
|
|
753
|
+
const assertion = String(request.headers["cf-access-jwt-assertion"] || cookies(request).CF_Authorization || "");
|
|
754
|
+
try {
|
|
755
|
+
const { email } = await access.verify(assertion);
|
|
756
|
+
openAccountSession(response, accounts.signIn(email));
|
|
757
|
+
} catch (error) {
|
|
758
|
+
logUsage("signin.access.refused", { reason: String(error.message || error).slice(0, 120) });
|
|
759
|
+
response.writeHead(303, { location: "/?signin=expired" });
|
|
760
|
+
response.end();
|
|
761
|
+
}
|
|
737
762
|
return;
|
|
738
763
|
}
|
|
739
764
|
if (account && request.method === "POST" && url.pathname === "/api/auth/signout") {
|
|
@@ -767,7 +792,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
767
792
|
json(response, 200, {
|
|
768
793
|
csrfToken, mode: "public", product: "Tapp", root: null, repository: null, repositories: [],
|
|
769
794
|
contract: customerProductContract, supportedPlatforms: ["web"], runners: [],
|
|
770
|
-
access: "account", email: account.email,
|
|
795
|
+
access: "account", email: account.email, signInProvider,
|
|
771
796
|
accepts: ["url"],
|
|
772
797
|
selfHostOnly: ["path", "github", "bundle", "app", "apk"],
|
|
773
798
|
});
|
|
@@ -777,7 +802,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
777
802
|
json(response, 200, {
|
|
778
803
|
csrfToken, mode: "public", product: "Tapp", root: null, repository: null, repositories: [],
|
|
779
804
|
contract: customerProductContract, supportedPlatforms: ["web"], runners: [],
|
|
780
|
-
access: "anonymous",
|
|
805
|
+
access: "anonymous", signInProvider,
|
|
781
806
|
// The prompt screen offers folders, bundle ids and builds. None of them can work in
|
|
782
807
|
// a hosted Studio — there is no Mac, no simulator and no access to the visitor's
|
|
783
808
|
// disk — so say so here rather than letting the UI offer them.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarwitz/tapp",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"mcpName": "io.github.aarwitz/tapp",
|
|
5
5
|
"description": "Let coding agents verify UI changes on real iOS, Android, and web surfaces, then enforce reviewed proof in deterministic CI.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"mobile"
|
|
97
97
|
],
|
|
98
98
|
"scripts": {
|
|
99
|
-
"test": "node --test tests/report.test.js tests/regression.test.js tests/engine.test.js tests/project-config.test.js tests/application-model.test.js tests/ui-map.test.js tests/focused-navigation.test.js tests/task-runtime.test.js tests/release-contract.test.js tests/pr-selection.test.js tests/flow-runtime.test.js tests/web-explorer.test.js tests/web-session.test.js tests/web-link-audit.test.js tests/web-audit.test.js tests/capture-provenance.test.js tests/capture-frames.test.js tests/actor-store.test.js tests/account-store.test.js tests/ios-crash-attribution.test.js tests/ios-simulator-selection.test.js tests/ios-recording-stop.test.js tests/web-flow.test.js tests/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/android-flow.test.js tests/android-primitives-protocol.test.js tests/managed-web.test.js tests/product-operations.test.js tests/job-lanes.test.js tests/browser-product.test.js tests/browser-chat-narration.test.js tests/browser-onboarding.test.js tests/managed-operation.test.js tests/ci-setup.test.js tests/ci-install.test.js tests/cli.test.js tests/mcp-workspace.test.js tests/action.test.js tests/package-surface.test.js tests/agent-surface.test.js tests/presentation-contract.test.js tests/landing-brand.test.js tests/ci-gate.test.js tests/ci-report.test.js tests/desktop-protocol.test.js tests/ios-flow-protocol.test.js tests/feedback-triage-0919.test.js vscode-extension/test/bridge.test.js",
|
|
99
|
+
"test": "node --test tests/report.test.js tests/regression.test.js tests/engine.test.js tests/project-config.test.js tests/application-model.test.js tests/ui-map.test.js tests/focused-navigation.test.js tests/task-runtime.test.js tests/release-contract.test.js tests/pr-selection.test.js tests/flow-runtime.test.js tests/web-explorer.test.js tests/web-session.test.js tests/web-link-audit.test.js tests/web-audit.test.js tests/capture-provenance.test.js tests/capture-frames.test.js tests/actor-store.test.js tests/account-store.test.js tests/access-jwt.test.js tests/ios-crash-attribution.test.js tests/ios-simulator-selection.test.js tests/ios-recording-stop.test.js tests/web-flow.test.js tests/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/android-flow.test.js tests/android-primitives-protocol.test.js tests/managed-web.test.js tests/product-operations.test.js tests/job-lanes.test.js tests/browser-product.test.js tests/browser-chat-narration.test.js tests/browser-onboarding.test.js tests/managed-operation.test.js tests/ci-setup.test.js tests/ci-install.test.js tests/cli.test.js tests/mcp-workspace.test.js tests/action.test.js tests/package-surface.test.js tests/agent-surface.test.js tests/presentation-contract.test.js tests/landing-brand.test.js tests/ci-gate.test.js tests/ci-report.test.js tests/desktop-protocol.test.js tests/ios-flow-protocol.test.js tests/feedback-triage-0919.test.js vscode-extension/test/bridge.test.js",
|
|
100
100
|
"test:browser-journey": "node --test tests/browser-journey.test.js",
|
|
101
101
|
"test:browser-native": "TAPP_RUN_NATIVE_BROWSER=1 node --test tests/browser-native-journey.test.js"
|
|
102
102
|
}
|