AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-only- ..
- assets
- basic-languages
- editor
- language
- nls
- abap-D-t0cyap.js
- apex-CcIm7xu6.js
- azcli-BA0tQDCg.js
- bat-C397hTD6.js
- bicep-DF5aW17k.js
- cameligo-plsz8qhj.js
- clojure-Y2auQMzK.js
- coffee-Bu45yuWE.js
- cpp-CkKPQIni.js
- csharp-CX28MZyh.js
- csp-D8uWnyxW.js
- css-CaeNmE3S.js
- css.worker-C7XcYe5x.js
- cssMode-DpEkhVlW.js
- cypher-DVThT8BS.js
- dart-CmGfCvrO.js
- dockerfile-CZqqYdch.js
- ecl-30fUercY.js
- editor-CG9c2pE-.js
- editor.js
- elixir-O3PRlgxO.js
- flow9-DqtmStfK.js
- freemarker2-DTUDMAl2.js
- fsharp-BOMdg4U1.js
- go-D_hbi-Jt.js
- graphql-CKUU4kLG.js
- handlebars-qLqoXa-4.js
- hcl-DTaboeZW.js
- html-DTxBj26n.js
- html.worker-VIR_LTyv.js
- htmlMode-DFBg6CMj.js
- index-BVflv2uG.js
- index.js
- ini--YXggpAu.js
- java-CI4ZMsH9.js
- javascript-BiL3JN6i.js
- json.worker-DzWXGkG8.js
- jsonMode-Dz4r0pwo.js
- julia-BwzEvaQw.js
- kotlin-IUYPiTV8.js
- less-C0eDYdqa.js
- lexon-iON-Kj97.js
- liquid-lXEUQRVn.js
- loader.js
- lspLanguageFeatures-IeRAvoKK.js
- lua-DtygF91M.js
- m3-CsR4AuFi.js
- markdown-C_rD0bIw.js
- mdx-Dtr248s4.js
- mips-CiYP61RB.js
- monaco.contribution-BRs4bdz5.js
- monaco.contribution-ChoOM5Gg.js
- monaco.contribution-DbKqsbmO.js
- monaco.contribution-DKFaWvum.js
- msdax-C38-sJlp.js
- mysql-CdtbpvbG.js
- nls.messages-loader.js
- objective-c-CntZFaHX.js
- pascal-r6kuqfl_.js
- pascaligo-BiXoTmXh.js
- perl-DABw_TcH.js
- pgsql-me_jFXeX.js
- php-D_kh-9LK.js
- pla-VfZjczW0.js
- postiats-BBSzz8Pk.js
- powerquery-Dt-g_2cc.js
- powershell-B-7ap1zc.js
- protobuf-BmtuEB1A.js
- pug-BRpRNeEb.js
- python-Cma5OvNe.js
- qsharp-BzsFaUU9.js
- r-f8dDdrp4.js
- razor-C8pOqqry.js
- redis-fvZQY4PI.js
- redshift-45Et0LQi.js
- restructuredtext-C7UUFKFD.js
- ruby-CZO8zYTz.js
- rust-Bfetafyc.js
- sb-3GYllVck.js
- scala-foMgrKo1.js
- scheme-CHdMtr7p.js
- scss-C1cmLt9V.js
- shell-ClXCKCEW.js
- solidity-MZ6ExpPy.js
- sophia-DWkuSsPQ.js
- sparql-AUGFYSyk.js
- sql-32GpJSV2.js
- st-CuDFIVZ_.js
- swift-t-PfMj7W.js
- systemverilog-Ch4vA8Yt.js
- tcl-D74tq1nH.js
- toggleHighContrast-CmI6H2gJ.js
- ts.worker-Dp2_QI6H.js
- tsMode-DgC3tGu_.js
- twig-C6taOxMV.js
- typescript-PjDChiYw.js
- typespec-D-PIh9Xw.js
- vb-Dyb2648j.js
- wgsl-BhLXMOR0.js
- workers-B_Zs9c54.js
- xml-BgCkTIhY.js
- yaml-D0tu26m-.js
app/src/lib/oidc-core.mjs
1// Zoo IAM OpenID Connect core: Authorization Code + PKCE (S256), state/nonce, JWKS signature verification, back-channel logout.2// Pure functions (no I/O except an injectable fetch) so they are unit-tested against forged tokens without any live IdP.3import crypto from "node:crypto";4export const CLIENT_ID = "zoo-cloud-studio";5export const DEFAULT_ISSUER = "https://iam.zoobd.com/realms/zoo";6const b64u = b => Buffer.from(b).toString("base64url");7export const rand = (n = 32) => crypto.randomBytes(n).toString("base64url");8export const pkceChallenge = verifier => crypto.createHash("sha256").update(verifier).digest("base64url");9export const newPkce = () => { const verifier = rand(48); return { verifier, challenge: pkceChallenge(verifier), method: "S256" }; };10export const sha = s => crypto.createHash("sha256").update(s).digest("hex");1112/** Discovery document must declare exactly the configured issuer and https endpoints (loopback http only when explicitly allowed for tests). */13export function validateDiscovery(doc, issuer, { allowHttpLoopback = false } = {}) {14 if (!doc || doc.issuer !== issuer) throw new Error("discovery issuer mismatch");15 const okUrl = u => { try { const x = new URL(u); return x.protocol === "https:" || (allowHttpLoopback && x.protocol === "http:" && ["127.0.0.1", "localhost"].includes(x.hostname)); } catch { return false; } };16 for (const k of ["authorization_endpoint", "token_endpoint", "jwks_uri"]) if (!okUrl(doc[k])) throw new Error(`discovery ${k} missing or not https`);17 if (doc.code_challenge_methods_supported && !doc.code_challenge_methods_supported.includes("S256")) throw new Error("IdP does not support PKCE S256");18 return doc;19}20export function authorizationUrl(disc, { clientId = CLIENT_ID, redirectUri, state, nonce, challenge, acr }) {21 const u = new URL(disc.authorization_endpoint);22 for (const [k, v] of Object.entries({ response_type: "code", client_id: clientId, redirect_uri: redirectUri, scope: "openid profile email", state, nonce, code_challenge: challenge, code_challenge_method: "S256", ...(acr ? { acr_values: acr } : {}) })) u.searchParams.set(k, v);23 return u.toString();24}2526const ALGS = { RS256: { hash: "sha256", kty: "RSA" }, ES256: { hash: "sha256", kty: "EC", ieee: true } };27export function decodeJwt(tok) {28 const p = String(tok).split("."); if (p.length !== 3 || p.some(x => !/^[A-Za-z0-9_-]*$/.test(x)) || !p[2]) throw new Error("malformed JWT");29 let header, payload; try { header = JSON.parse(Buffer.from(p[0], "base64url").toString()); payload = JSON.parse(Buffer.from(p[1], "base64url").toString()); } catch { throw new Error("malformed JWT"); }30 return { header, payload, signingInput: p[0] + "." + p[1], sig: Buffer.from(p[2], "base64url") };31}32/** Verifies the signature against the issuer's JWKS. Only RS256/ES256; "none", HS* (key-confusion) and unknown kids are refused. */33export function verifySignature(jwt, jwks) {34 const alg = ALGS[jwt.header.alg]; if (!alg) throw new Error(`unsupported JWT alg ${String(jwt.header.alg).slice(0, 12)}`);35 const keys = (jwks?.keys ?? []).filter(k => k.kty === alg.kty && (!k.use || k.use === "sig") && (jwt.header.kid ? k.kid === jwt.header.kid : (jwks.keys.length === 1)));36 if (!keys.length) throw new Error("no matching signing key (kid)");37 for (const k of keys) { const key = crypto.createPublicKey({ key: k, format: "jwk" }); if (crypto.verify(alg.hash, Buffer.from(jwt.signingInput), alg.ieee ? { key, dsaEncoding: "ieee-p1363" } : key, jwt.sig)) return true; }38 throw new Error("invalid JWT signature");39}40const aud = a => Array.isArray(a) ? a : [a];41export function verifyIdToken(token, jwks, { issuer, clientId = CLIENT_ID, nonce, now = Date.now() / 1000, skew = 60, requireAcr }) {42 const jwt = decodeJwt(token); verifySignature(jwt, jwks); const c = jwt.payload;43 if (c.iss !== issuer) throw new Error("issuer mismatch");44 if (!aud(c.aud).includes(clientId)) throw new Error("audience mismatch");45 if (aud(c.aud).length > 1 && c.azp !== clientId) throw new Error("azp mismatch");46 if (typeof c.exp !== "number" || c.exp + skew < now) throw new Error("token expired");47 if (typeof c.nbf === "number" && c.nbf - skew > now) throw new Error("token not yet valid");48 if (typeof c.iat !== "number" || c.iat - skew > now) throw new Error("bad iat");49 if (!nonce || c.nonce !== nonce) throw new Error("nonce mismatch");50 if (typeof c.sub !== "string" || !c.sub) throw new Error("missing sub");51 if (requireAcr && c.acr !== requireAcr) throw new Error("authentication context (MFA) requirement not met");52 return { iss: c.iss, sub: c.sub, sid: c.sid ?? null, email: typeof c.email === "string" ? c.email : null, emailVerified: c.email_verified === true, name: typeof c.name === "string" ? c.name : null, picture: typeof c.picture === "string" ? c.picture : null, acr: c.acr ?? null, amr: Array.isArray(c.amr) ? c.amr : [], authTime: c.auth_time ?? null };53}54/** OIDC Back-Channel Logout 1.0 §2.6 */55export function verifyLogoutToken(token, jwks, { issuer, clientId = CLIENT_ID, now = Date.now() / 1000, skew = 60 }) {56 const jwt = decodeJwt(token); verifySignature(jwt, jwks); const c = jwt.payload;57 if (c.iss !== issuer || !aud(c.aud).includes(clientId)) throw new Error("issuer/audience mismatch");58 if (typeof c.iat !== "number" || Math.abs(now - c.iat) > 300 + skew) throw new Error("stale logout token");59 if (!c.events || typeof c.events["http://schemas.openid.net/event/backchannel-logout"] !== "object") throw new Error("not a logout token");60 if ("nonce" in c) throw new Error("logout token must not carry a nonce");61 if (!c.sub && !c.sid) throw new Error("logout token needs sub or sid");62 return { iss: c.iss, sub: c.sub ?? null, sid: c.sid ?? null, jti: c.jti ?? null };63}64/** The only stable external identity key. E-mail is display data and is never used to link or to grant roles. */65export const identityKey = (iss, sub) => `${iss}\u0000${sub}`;66
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 1c27633 on master.
Approval requests
None pending.