Skip to content

fix(flow): parse prefixed routes with denylists and refine login - #48

Open
google-labs-stitch[bot] wants to merge 4 commits into
mainfrom
stitch/route-allowlists-angular-query-state-jm0-326edc4b-30d1-4f0b-8ba3-6aba001c436f
Open

google-labs-stitch[bot] wants to merge 4 commits into
mainfrom
stitch/route-allowlists-angular-query-state-jm0-326edc4b-30d1-4f0b-8ba3-6aba001c436f

Conversation

@google-labs-stitch

@google-labs-stitch google-labs-stitch Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add neutral leaf route modules (src/flow_url.rs and ts/flow_route.ts) that strip /fx/tools/flow, /fx, /u/<digits>, and /<org>/global prefixes in any order while preserving the non-workspace route denylist (NON_WORKSPACE_SEGMENT_PREFIXES, /flow, /api, and /_) so unlisted workspace routes and /project/<id>/... subroutes remain accepted.
  • Parse full URLs with Url::parse and pass parsed.path() in project_id_from_url and is_project_subroute_url (src/project_route.rs), keeping /project/<id>/collection/<cid> on the collection grid while returning to /project/<id> from non-grid subroutes in ensure_project_workspace_root.
  • Detect /about, /flow, /flow/about, and /tools/flow/about under all supported prefixes in is_about_landing_url.
  • Keep ts/check_auth.ts on the read-only cPZSdc (FLOW_APP_CONFIG) batchexecute probe (config[30] === false and config[31] === false), forwarding URL-derived authuser (?authuser= or /u/<digits>) without QueryCache traversal, KV2T2d, or unverified minified names.
  • Detect .google.com auth cookies directly from Cookies in inspect_login_profile (src/chrome.rs) while reading optional flow_url and rejected_url from History when present.
  • In login_with_chrome (flow_login action="login"), settle for 4 seconds and promote (closing LoginChrome to flush cookies and DBSC keys) once .google.com auth cookies appear or when LoginChrome exits, keep polling across temporary Flow SSO redirect routes in finalize_promoted_login, return explicit errors for unsupported_country and age_restricted instead of "Run flow_login again", and return an error without opening a second window when verification fails.
  • Leave an open LoginChrome window running during passive flow_status and flow_login action="status" checks while !st.exited.

Verification

  • Pass cargo xtask ci (cargo fmt --all -- --check, license header and <= 800 code-line checks, tsc --noEmit, Flow build contracts for 20261129.06_p0, clippy -D warnings, cargo doc --document-private-items, cargo build --locked --workspace, and cargo deny).
  • Verify TypeScript prefix stripping and non-workspace route denylists across root, /fx/tools/flow, /fx, /u/<digits>, and /<org>/global, unlisted workspace and project subroutes, and URL-only authuser resolution.
  • Verify end-to-end MCP stdio flow_login and flow_status behavior: Cookies-only LoginChrome promotion without History, passive status checks preserving open LoginChrome, temporary /fx/api/auth/... SSO redirect polling, project_id_from_url on full prefixed URLs, /collection/<cid> preservation, specific unsupported_country and age_restricted errors (via both cPZSdc and redirect routes), and 0700 profile / 0600 lock permissions.

- Strip Flow host, account, and org prefixes in route allowlists.
- Detect /about, /flow, and /flow/about across all route prefixes.
- Read FLOW_APP_CONFIG and CHECK_TOOL_AVAILABILITY from QueryCache.
- Send authuser and pageId on batched cPZSdc and KV2T2d fallbacks.
- Reject JSPB 0, false, sparse 31/32 flags, and KV2T2d codes 4-8.
- Require Google cookies, Flow cookies, and History URL on login.
- Keep LoginChrome open on status polls and keep active Flow URLs.
@byteland-app

Copy link
Copy Markdown
Contributor

Changes requested. Keep this PR as the route and sign-in PR. I close #41, which overlaps with it. The point 1 below blocks the merge.

  1. src/project_route.rs:11-23 (project_id_from_url): it splits a full URL at ? or # but does not parse the path. For https://flow.google.com/project/abc the first segment is https:, so the route becomes /https:/flow.google.com/project/abc and the function returns None. The callers in project.rs, characters.rs, scenes.rs and voices.rs pass engine.current_url(), which is a full URL, so these tools see "not in a project". is_project_subroute_url has the same fault and always returns false, so ensure_project_workspace_root never navigates. Parse the URL with Url::parse and pass path().
  2. src/auth.rs:246 (finalize_promoted_login): a Flow host with a route that is not in the allow list stops the login at once. A temporary SSO redirect route (for example /fx/api/auth/...) can fail the login after the cookie is written. The old code kept polling.
  3. src/auth.rs (about L373-378): when finalize_promoted_login fails and the window is open, the code starts a new interactive login and then returns an error. The user gets a new window and an error together.
  4. src/chrome.rs:451 (has_google_auth_cookies) now also needs a Flow URL in the History database. Chrome writes History late, so the check can be slow or fail early.
  5. ts/check_auth.ts: the codes 4, 5, 6 and 8 mean unavailable. This meaning is not verified, and a wrong meaning rejects a signed-in account.
  6. ts/angular.ts is about 796 code lines. The limit is 800, and the merge of fix(flow): resolve Angular views, NG0950 inputs, and store loading #29, fix(flow): bind verified scene signals and emit clip assets #46, fix(flow): mutate project titles in store and read query caches #49 or fix(flow): bind edit controllers with scene delegation #50 will go over it. project_route calls auth::is_signed_in_flow_url, which is a reverse dependency. Move the shared function to a neutral module.

Take the useful parts of #41 (batch probes of cPZSdc and KV2T2d) in a later PR, with its review points fixed.

- Parse URL paths in project_id_from_url and is_project_subroute_url
- Keep polling across Flow SSO redirect routes during login promotion
- Do not open a second login window when verification fails
- Detect Google auth cookies from Cookies without requiring History
- Reject only verified KV2T2d code 7 in check_auth
- Move shared route and Angular query helpers to leaf modules
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed all 6 review items in 824f551:

  1. src/project_route.rs (project_id_from_url & is_project_subroute_url): Parse full URLs with Url::parse (verifying is_signed_in_parsed_flow_url) and pass parsed.path() to split_flow_path, while preserving raw /... path support and keeping /project/<id>/collection/<cid> on the collection grid.
  2. src/auth.rs (finalize_promoted_login): Removed the if is_flow_host_url(&cur) && !is_signed_in_flow_url(&cur) break so promotion keeps polling across temporary Flow SSO redirect routes such as /fx/api/auth/..., and verified is_signed_in_flow_url(&final_url) after login completes.
  3. src/auth.rs (login_with_chrome): Removed engine.launch_interactive_login(FLOW_SSO_URL, false).await? before anyhow::bail! so a failed workspace verification returns an error without opening a second browser window.
  4. src/chrome.rs (inspect_login_profile): Computed has_google_auth_cookies directly from .google.com auth cookies in Cookies (is_google_auth_cookie_pair) without requiring History, while still reading flow_url and rejected_url from History when present.
  5. ts/check_auth.ts: Restricted KV2T2d availability rejection to verified code 7 (age_restricted), dropped the unverified unavailable mapping for codes 4, 5, 6, and 8, and skipped non-16 KV2T2d errors when cPZSdc passes.
  6. Module boundaries & ts/angular.ts line budget: Moved shared Rust Flow URL helpers to leaf module src/flow_url.rs (removing the reverse project_route -> auth dependency), and extracted TypeScript route and Angular query helpers into ts/flow_route.ts and ts/angular_query.ts (reducing ts/angular.ts from ~796 code lines to ~542 code lines).

@byteland-app

Copy link
Copy Markdown
Contributor

I reviewed this pull request on top of current main (build 20261129.06_p0 is now supported). The merge is clean and the six earlier review points are fixed. The URL route parsing, the prefix handling (/u/<n>, /<org>/global, /fx), and the Cookies-only probe are useful. I did not merge it, because of these defects:

  1. ts/check_auth.ts reads literal minified names (qf, Cla, um, vf), and ts/types.ts adds QrtxK and S06Grb. None are in ts/frontend_builds.ts or ts/frontend_nov29*.ts.
  2. ts/check_auth.ts:198 treats KV2T2d code 7 as age_restricted. Line 156 widens "disabled" to false || 0 for fields 31 and 32, and tool ID 22 is hard-coded. Nothing in the repo shows these meanings, so a signed-in account can be rejected.
  3. is_workspace_flow_route (src/flow_url.rs:142) and isWorkspaceFlowRoute use an allowlist. An unlisted route reads as "not signed in" or "not in a project". Keep the denylist, or prove the list is complete for the current build.
  4. finalize_promoted_login (src/auth.rs:211-216) returns Ok(None) for unsupported_country and age_restricted. The caller then shows the generic "Run flow_login again" text.
  5. eval_check_auth_once now runs bind_angular_views on each call, and ensureAngularQueryCache dispatches synthetic hover events on page buttons. engine.rs now injects FLOW_RUNTIME_JS when it is missing.
  6. login_with_chrome still closes the interactive window after cookies appear, which contradicts the description.
  7. The first commit leaves project_id_from_url broken for full URLs. Please squash.

Please split the change: the URL parsing and login fixes can land alone. The QueryCache and KV2T2d probe can follow later.

- Keep the non-workspace route denylist in flow_url and flow_route
- Strip /fx, /fx/tools/flow, /u/<n>, and /<org>/global prefixes
- Parse full URLs in project_id_from_url and is_project_subroute_url
- Remove QueryCache, KV2T2d, minified names, and runtime injection
- Forward URL authuser on the read-only cPZSdc workspace probe
- Report unsupported_country and age_restricted errors on promotion
@google-labs-stitch google-labs-stitch Bot changed the title fix(flow): verify workspace routes and angular query state fix(flow): parse prefixed routes with denylists and refine login Dec 1, 2026
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Split out the QueryCache and KV2T2d changes and addressed the review points in f60b5e9:

  1. Unverified minified identifiers: Removed ts/angular_query.ts, reverted ts/types.ts to main (dropping QrtxK, S06Grb, and AngularQuery*), removed qf, Cla, um, and vf from ts/check_auth.ts, and resolved authuser in ts/flow_route.ts strictly from ?authuser= or /u/<digits>.
  2. KV2T2d, tool ID 22, and false || 0 widening: Restored ts/check_auth.ts to main's read-only cPZSdc (FLOW_APP_CONFIG) probe checking only config[30] === false (unsupported_country) and config[31] === false (age_restricted), while forwarding URL-derived authuser.
  3. Workspace route denylist: Replaced the route allowlists in src/flow_url.rs (is_workspace_flow_route) and ts/flow_route.ts (isWorkspaceFlowRoute) with the prefix-stripped non-workspace denylist (NON_WORKSPACE_SEGMENT_PREFIXES, /flow, /api, and /_) so unlisted workspace routes and /project/<id>/... subroutes remain accepted.
  4. unsupported_country and age_restricted errors in finalize_promoted_login: Returned explicit unsupported_country and age_restricted errors (from both check_page_auth reasons and /unsupported-country or /age-restricted redirect routes) instead of Ok(None), preventing the generic "Run flow_login again" message.
  5. Runtime side effects: Removed bind_angular_views from eval_check_auth_once (src/auth.rs), deleted ensureAngularQueryCache and its synthetic hover probes (ts/angular_query.ts), and removed FLOW_RUNTIME_JS re-injection from bind_browser_instances (src/engine.rs).
  6. LoginChrome lifecycle vs. PR description: Deduplicated promote_ready_login_chrome in src/auth.rs and updated the PR title and description to match the implementation and architecture docs: login_with_chrome (flow_login action="login") settles for 4 seconds and promotes (closing LoginChrome to flush cookies and DBSC keys) once .google.com auth cookies appear or when LoginChrome exits, while passive flow_status and flow_login action="status" checks keep LoginChrome open while !st.exited.
  7. Commit history / squash: The automated push environment allows fast-forward pushes only (force-push is disabled here), so f60b5e9 is pushed on top and the PR title and description are formatted for a clean single-commit Squash and merge onto main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant