inistate-mcp 1.3.4 → 1.3.5
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.
- package/build/authorize-app-routes.js +10 -85
- package/build/authorize-pages.d.ts +24 -0
- package/build/authorize-pages.js +110 -0
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import express from "express";
|
|
3
|
-
import {
|
|
4
|
-
import { INISTATE_LOGO_SVG } from "./inistate-logo.js";
|
|
2
|
+
import { PAGE_HEADERS, renderConfirmPage, renderExpiredPage, renderWrongBrowserPage } from "./authorize-pages.js";
|
|
5
3
|
import { browserSecretCookieName, browserSecretCookieOptions, readCookie, } from "./oauth-provider.js";
|
|
6
4
|
/**
|
|
7
5
|
* SS06370: the Inistate App approves a flow natively (no cookie), then hands the user to the
|
|
@@ -12,72 +10,20 @@ import { browserSecretCookieName, browserSecretCookieOptions, readCookie, } from
|
|
|
12
10
|
* GET /authorize/finish the browser: confirmation page (cookie + token)
|
|
13
11
|
* POST /authorize/finish the browser: Confirm -> 302 to the client with the code
|
|
14
12
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* A second tap on Confirm used to burn the flow: the first POST had already issued the code
|
|
18
|
-
* and consumed the nonce, so the retry could only say "expired". Disable the button on submit.
|
|
19
|
-
* Inline, so the CSP carries its hash instead of allowing scripts in general.
|
|
20
|
-
*/
|
|
21
|
-
const SUBMIT_SCRIPT = "document.addEventListener('submit',function(e){var b=e.target.querySelector('button');if(b){b.disabled=true;b.textContent='Connecting\\u2026'}})";
|
|
22
|
-
const SUBMIT_SCRIPT_HASH = `'sha256-${createHash("sha256").update(SUBMIT_SCRIPT).digest("base64")}'`;
|
|
23
|
-
// No form-action here: Chrome also applies it to the redirect that follows the POST, and the
|
|
24
|
-
// whole point of Confirm is to redirect to the client's own origin, so 'self' blocked it and
|
|
25
|
-
// "nothing happened". Everything interpolated into the page is escaped, so nothing here
|
|
26
|
-
// can be steered into posting elsewhere.
|
|
27
|
-
const CSP = `default-src 'none'; style-src 'unsafe-inline'; script-src ${SUBMIT_SCRIPT_HASH}; img-src data:; frame-ancestors 'none'`;
|
|
28
|
-
// Palette from the web app (webApp src/assets/scss/colors.scss): primary #2b9ec6, green #a4ce3a.
|
|
29
|
-
// The button uses a darker shade of the primary because white on #2b9ec6 is only ~3:1.
|
|
30
|
-
const STYLE = `
|
|
31
|
-
:root{color-scheme:light dark;--bg:#f4f8fa;--card:#fff;--fg:#212121;--muted:#5f6b72;--line:#e6e6e6;--brand:#2b9ec6;--green:#a4ce3a;--btn:#1d7fa3;--btn-hover:#18698a;--btn-fg:#fff;--warn-bg:#fff6e8;--warn-line:#f3d19e}
|
|
32
|
-
@media (prefers-color-scheme:dark){:root{--bg:#121a1e;--card:#1b252b;--fg:#eef3f5;--muted:#a2b0b8;--line:#2d3b43;--btn:#2b9ec6;--btn-hover:#4db3d6;--btn-fg:#06161c;--warn-bg:#2b2516;--warn-line:#5a4a1e}}
|
|
33
|
-
*{box-sizing:border-box}
|
|
34
|
-
body{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;padding:16px;background:var(--bg);color:var(--fg);font:16px/1.5 Inter,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
|
|
35
|
-
main{position:relative;width:100%;max-width:26rem;background:var(--card);border:1px solid var(--line);border-radius:16px;padding:32px 24px 28px;overflow:hidden;box-shadow:0 2px 12px rgba(16,40,52,.08)}
|
|
36
|
-
main::before{content:"";position:absolute;inset:0 0 auto 0;height:5px;background:linear-gradient(to right,var(--brand),var(--green))}
|
|
37
|
-
.pair{display:flex;align-items:center;gap:12px;margin:0 0 16px}
|
|
38
|
-
.logo{display:block;width:44px;height:44px;border-radius:10px}.logo svg{display:block;width:100%;height:100%}
|
|
39
|
-
.link{color:var(--muted);font-size:1.2rem;line-height:1}
|
|
40
|
-
.where{font-size:.9rem}.where strong{color:var(--fg);font-weight:600;word-break:break-all}
|
|
41
|
-
h1{margin:0 0 6px;font-size:1.3rem;line-height:1.3}
|
|
42
|
-
p{margin:0 0 14px;color:var(--muted)}
|
|
43
|
-
.account{margin:16px 0;padding:12px 14px;border:1px solid var(--line);border-left:4px solid var(--brand);border-radius:10px;word-break:break-all}
|
|
44
|
-
.account small{display:block;color:var(--muted);font-size:.8rem;margin-bottom:2px}
|
|
45
|
-
.account strong{color:var(--fg);font-weight:600}
|
|
46
|
-
.note{padding:10px 12px;border-radius:10px;background:var(--warn-bg);border:1px solid var(--warn-line);color:var(--fg);font-size:.9rem;margin:0 0 18px}
|
|
47
|
-
button{width:100%;padding:12px 16px;border:0;border-radius:10px;background:var(--btn);color:var(--btn-fg);font:inherit;font-weight:600;cursor:pointer}
|
|
48
|
-
button:hover:not(:disabled){background:var(--btn-hover)}
|
|
49
|
-
button:disabled{opacity:.6;cursor:default}
|
|
50
|
-
button:focus-visible{outline:3px solid var(--brand);outline-offset:2px}
|
|
51
|
-
`;
|
|
52
|
-
const INISTATE_MARK = `<span class="logo">${INISTATE_LOGO_SVG}</span>`;
|
|
53
|
-
function page(res, status, title, body, header = INISTATE_MARK) {
|
|
54
|
-
res
|
|
55
|
-
.status(status)
|
|
56
|
-
.set({
|
|
57
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
58
|
-
"Cache-Control": "no-store",
|
|
59
|
-
"Referrer-Policy": "no-referrer",
|
|
60
|
-
// The Confirm button must not be clickjackable from another origin.
|
|
61
|
-
"X-Frame-Options": "DENY",
|
|
62
|
-
"Content-Security-Policy": CSP,
|
|
63
|
-
})
|
|
64
|
-
.send(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">` +
|
|
65
|
-
`<title>${escapeHtml(title)}</title><style>${STYLE}</style></head><body><main><div class="pair">${header}</div>${body}</main>` +
|
|
66
|
-
`<script>${SUBMIT_SCRIPT}</script></body></html>`);
|
|
13
|
+
function sendPage(res, status, html) {
|
|
14
|
+
res.status(status).set(PAGE_HEADERS).send(html);
|
|
67
15
|
}
|
|
68
16
|
function failure(res, error) {
|
|
69
17
|
const message = error instanceof Error ? error.message : "Authorization failed";
|
|
70
18
|
if (/does not belong to this browser|Invalid finish token/.test(message)) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
19
|
+
sendPage(res, 400, renderWrongBrowserPage());
|
|
20
|
+
}
|
|
21
|
+
else if (/expired|Invalid or expired/i.test(message)) {
|
|
22
|
+
sendPage(res, 400, renderExpiredPage());
|
|
74
23
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
`<p>It may already have been used. Go back to ChatGPT or Claude and start connecting again.</p>`);
|
|
78
|
-
return;
|
|
24
|
+
else {
|
|
25
|
+
res.status(400).type("text/plain").send(message);
|
|
79
26
|
}
|
|
80
|
-
res.status(400).type("text/plain").send(message);
|
|
81
27
|
}
|
|
82
28
|
export function registerAppAuthorizeRoutes(app, provider, issuerUrl) {
|
|
83
29
|
const secure = issuerUrl.startsWith("https:");
|
|
@@ -108,28 +54,7 @@ export function registerAppAuthorizeRoutes(app, provider, issuerUrl) {
|
|
|
108
54
|
const token = String(req.query.token ?? "");
|
|
109
55
|
const cookie = readCookie(req.headers.cookie, browserSecretCookieName(nonce));
|
|
110
56
|
const info = provider.getFinishInfo(nonce, token, cookie);
|
|
111
|
-
|
|
112
|
-
// otherwise the self-chosen client name is all there is, and the host is shown plainly.
|
|
113
|
-
const brand = clientLogoForRedirect(info.redirectUri);
|
|
114
|
-
const label = brand?.name ?? (info.clientName || "this app");
|
|
115
|
-
let host = "";
|
|
116
|
-
try {
|
|
117
|
-
host = new URL(info.redirectUri).host;
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
/* shown without a host */
|
|
121
|
-
}
|
|
122
|
-
const header = (brand ? `<img class="logo" src="${brand.logo}" alt="${escapeHtml(brand.name)}"><span class="link" aria-hidden="true">⇄</span>` : "") +
|
|
123
|
-
INISTATE_MARK;
|
|
124
|
-
page(res, 200, "Confirm connection", `<h1>Connect ${escapeHtml(label)} to Inistate?</h1>` +
|
|
125
|
-
`<p>It will be able to work in Inistate as this account:</p>` +
|
|
126
|
-
`<div class="account"><small>Signed in as</small><strong>${escapeHtml(info.account)}</strong></div>` +
|
|
127
|
-
(host ? `<p class="where">After you confirm, you'll be sent back to <strong>${escapeHtml(host)}</strong>.</p>` : "") +
|
|
128
|
-
`<p class="note">Only continue if you just started this from ChatGPT or Claude. If someone sent you this link, close this page.</p>` +
|
|
129
|
-
`<form method="post" action="/authorize/finish">` +
|
|
130
|
-
`<input type="hidden" name="nonce" value="${escapeHtml(nonce)}">` +
|
|
131
|
-
`<input type="hidden" name="token" value="${escapeHtml(token)}">` +
|
|
132
|
-
`<button type="submit">Confirm</button></form>`, header);
|
|
57
|
+
sendPage(res, 200, renderConfirmPage({ ...info, nonce, token }));
|
|
133
58
|
}
|
|
134
59
|
catch (error) {
|
|
135
60
|
failure(res, error);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SS06370: the pages the browser shows while finishing an App-approved authorization.
|
|
3
|
+
* Pure rendering - no Express, no provider - so wording, layout and styling live in one file
|
|
4
|
+
* and are easy to change. authorize-app-routes.ts decides WHICH page to send.
|
|
5
|
+
*/
|
|
6
|
+
export declare const escapeHtml: (s: string) => string;
|
|
7
|
+
/** Headers for every page: no caching, no referrer, not frameable (Confirm must not be clickjackable). */
|
|
8
|
+
export declare const PAGE_HEADERS: Record<string, string>;
|
|
9
|
+
export interface ConfirmPageInput {
|
|
10
|
+
/** The self-chosen (dynamic client registration) name; untrusted display text. */
|
|
11
|
+
clientName: string;
|
|
12
|
+
/** Backend-verified account the connection will act as. */
|
|
13
|
+
account: string;
|
|
14
|
+
/** Where the authorization code will be returned. */
|
|
15
|
+
redirectUri: string;
|
|
16
|
+
nonce: string;
|
|
17
|
+
token: string;
|
|
18
|
+
}
|
|
19
|
+
/** The page the user lands on after approving in the App: who connects, as whom, and Confirm. */
|
|
20
|
+
export declare function renderConfirmPage(input: ConfirmPageInput): string;
|
|
21
|
+
/** The link was opened in a browser that did not start the flow (no cookie) or with the wrong token. */
|
|
22
|
+
export declare function renderWrongBrowserPage(): string;
|
|
23
|
+
/** The flow is gone: already confirmed, timed out, or never existed. */
|
|
24
|
+
export declare function renderExpiredPage(): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { clientLogoForRedirect } from "./client-logos.js";
|
|
3
|
+
import { INISTATE_LOGO_SVG } from "./inistate-logo.js";
|
|
4
|
+
/**
|
|
5
|
+
* SS06370: the pages the browser shows while finishing an App-approved authorization.
|
|
6
|
+
* Pure rendering - no Express, no provider - so wording, layout and styling live in one file
|
|
7
|
+
* and are easy to change. authorize-app-routes.ts decides WHICH page to send.
|
|
8
|
+
*/
|
|
9
|
+
/* ------------------------------------------------------------------ */
|
|
10
|
+
/* Escaping */
|
|
11
|
+
/* ------------------------------------------------------------------ */
|
|
12
|
+
export const escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
13
|
+
/** Escaped text that may wrap after an "@", so an email breaks at a sensible place on a narrow screen. */
|
|
14
|
+
const breakable = (s) => escapeHtml(s).replace(/@/g, "@<wbr>");
|
|
15
|
+
/* ------------------------------------------------------------------ */
|
|
16
|
+
/* Security headers */
|
|
17
|
+
/* ------------------------------------------------------------------ */
|
|
18
|
+
/**
|
|
19
|
+
* A second tap on Confirm used to burn the flow: the first POST had already issued the code
|
|
20
|
+
* and consumed the nonce, so the retry could only say "expired". Disable the button on submit.
|
|
21
|
+
* Inline, so the CSP carries its hash instead of allowing scripts in general.
|
|
22
|
+
*/
|
|
23
|
+
const SUBMIT_SCRIPT = "document.addEventListener('submit',function(e){var b=e.target.querySelector('button');if(b){b.disabled=true;b.textContent='Connecting\\u2026'}})";
|
|
24
|
+
const SUBMIT_SCRIPT_HASH = `'sha256-${createHash("sha256").update(SUBMIT_SCRIPT).digest("base64")}'`;
|
|
25
|
+
// No form-action here: Chrome also applies it to the redirect that follows the POST, and the
|
|
26
|
+
// whole point of Confirm is to redirect to the client's own origin, so 'self' blocked it and
|
|
27
|
+
// "nothing happened". Everything interpolated into a page is escaped, so nothing here can be
|
|
28
|
+
// steered into posting elsewhere.
|
|
29
|
+
const CSP = `default-src 'none'; style-src 'unsafe-inline'; script-src ${SUBMIT_SCRIPT_HASH}; img-src data:; frame-ancestors 'none'`;
|
|
30
|
+
/** Headers for every page: no caching, no referrer, not frameable (Confirm must not be clickjackable). */
|
|
31
|
+
export const PAGE_HEADERS = {
|
|
32
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
33
|
+
"Cache-Control": "no-store",
|
|
34
|
+
"Referrer-Policy": "no-referrer",
|
|
35
|
+
"X-Frame-Options": "DENY",
|
|
36
|
+
"Content-Security-Policy": CSP,
|
|
37
|
+
};
|
|
38
|
+
/* ------------------------------------------------------------------ */
|
|
39
|
+
/* Look */
|
|
40
|
+
/* ------------------------------------------------------------------ */
|
|
41
|
+
// Palette from the web app (webApp src/assets/scss/colors.scss): primary #2b9ec6, green #a4ce3a.
|
|
42
|
+
// The button uses a darker shade of the primary because white on #2b9ec6 is only ~3:1.
|
|
43
|
+
const STYLE = `
|
|
44
|
+
:root{color-scheme:light dark;--bg:#f4f8fa;--card:#fff;--fg:#212121;--muted:#5f6b72;--line:#e6e6e6;--brand:#2b9ec6;--green:#a4ce3a;--btn:#1d7fa3;--btn-hover:#18698a;--btn-fg:#fff;--warn-bg:#fff6e8;--warn-line:#f3d19e}
|
|
45
|
+
@media (prefers-color-scheme:dark){:root{--bg:#121a1e;--card:#1b252b;--fg:#eef3f5;--muted:#a2b0b8;--line:#2d3b43;--btn:#2b9ec6;--btn-hover:#4db3d6;--btn-fg:#06161c;--warn-bg:#2b2516;--warn-line:#5a4a1e}}
|
|
46
|
+
*{box-sizing:border-box}
|
|
47
|
+
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
|
|
48
|
+
body{margin:0;min-height:100vh;min-height:100dvh;display:flex;padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));background:var(--bg);color:var(--fg);font:16px/1.5 Inter,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
|
|
49
|
+
main{position:relative;margin:auto;width:100%;max-width:26rem;background:var(--card);border:1px solid var(--line);border-radius:16px;padding:32px 24px 28px;overflow:hidden;box-shadow:0 2px 12px rgba(16,40,52,.08)}
|
|
50
|
+
main::before{content:"";position:absolute;inset:0 0 auto 0;height:5px;background:linear-gradient(to right,var(--brand),var(--green))}
|
|
51
|
+
.pair{display:flex;align-items:center;gap:12px;margin:0 0 16px}
|
|
52
|
+
.logo{display:block;width:44px;height:44px;border-radius:10px}.logo svg{display:block;width:100%;height:100%}
|
|
53
|
+
.link{color:var(--muted);font-size:1.2rem;line-height:1}
|
|
54
|
+
.where{font-size:.9rem}.where strong{color:var(--fg);font-weight:600;overflow-wrap:anywhere}
|
|
55
|
+
h1{margin:0 0 6px;font-size:1.3rem;line-height:1.3;text-wrap:balance}
|
|
56
|
+
p{margin:0 0 14px;color:var(--muted)}
|
|
57
|
+
.account{margin:16px 0;padding:12px 14px;border:1px solid var(--line);border-left:4px solid var(--brand);border-radius:10px;overflow-wrap:anywhere}
|
|
58
|
+
.account small{display:block;color:var(--muted);font-size:.8rem;margin-bottom:2px}
|
|
59
|
+
.account strong{color:var(--fg);font-weight:600}
|
|
60
|
+
.note{padding:10px 12px;border-radius:10px;background:var(--warn-bg);border:1px solid var(--warn-line);color:var(--fg);font-size:.9rem;margin:0 0 18px}
|
|
61
|
+
button{width:100%;min-height:48px;padding:12px 16px;border:0;border-radius:10px;background:var(--btn);color:var(--btn-fg);font:inherit;font-weight:600;cursor:pointer}
|
|
62
|
+
button:hover:not(:disabled){background:var(--btn-hover)}
|
|
63
|
+
button:disabled{opacity:.6;cursor:default}
|
|
64
|
+
button:focus-visible{outline:3px solid var(--brand);outline-offset:2px}
|
|
65
|
+
@media (max-width:400px){main{padding:28px 20px 24px}h1{font-size:1.2rem}.pair{margin-bottom:14px}}
|
|
66
|
+
@media (max-height:480px){main{padding-top:24px}.pair{margin-bottom:10px}}
|
|
67
|
+
`;
|
|
68
|
+
const INISTATE_MARK = `<span class="logo">${INISTATE_LOGO_SVG}</span>`;
|
|
69
|
+
/** The shared shell: head, card, logos row, body. */
|
|
70
|
+
function layout(title, body, header = INISTATE_MARK) {
|
|
71
|
+
return (`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">` +
|
|
72
|
+
`<title>${escapeHtml(title)}</title><style>${STYLE}</style></head><body><main><div class="pair">${header}</div>${body}</main>` +
|
|
73
|
+
`<script>${SUBMIT_SCRIPT}</script></body></html>`);
|
|
74
|
+
}
|
|
75
|
+
/** The page the user lands on after approving in the App: who connects, as whom, and Confirm. */
|
|
76
|
+
export function renderConfirmPage(input) {
|
|
77
|
+
// A logo and a verified name only when the code is going to that service's own host;
|
|
78
|
+
// otherwise the self-chosen client name is all there is, and the host is shown plainly.
|
|
79
|
+
const brand = clientLogoForRedirect(input.redirectUri);
|
|
80
|
+
const label = brand?.name ?? (input.clientName || "this app");
|
|
81
|
+
let host = "";
|
|
82
|
+
try {
|
|
83
|
+
host = new URL(input.redirectUri).host;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
/* shown without a host */
|
|
87
|
+
}
|
|
88
|
+
const header = (brand
|
|
89
|
+
? `<img class="logo" src="${brand.logo}" alt="${escapeHtml(brand.name)}"><span class="link" aria-hidden="true">⇄</span>`
|
|
90
|
+
: "") + INISTATE_MARK;
|
|
91
|
+
return layout("Confirm connection", `<h1>Connect ${escapeHtml(label)} to Inistate?</h1>` +
|
|
92
|
+
`<p>It will be able to work in Inistate as this account:</p>` +
|
|
93
|
+
`<div class="account"><small>Signed in as</small><strong>${breakable(input.account)}</strong></div>` +
|
|
94
|
+
(host ? `<p class="where">After you confirm, you'll be sent back to <strong>${escapeHtml(host)}</strong>.</p>` : "") +
|
|
95
|
+
`<p class="note">Only continue if you just started this from ChatGPT or Claude. If someone sent you this link, close this page.</p>` +
|
|
96
|
+
`<form method="post" action="/authorize/finish">` +
|
|
97
|
+
`<input type="hidden" name="nonce" value="${escapeHtml(input.nonce)}">` +
|
|
98
|
+
`<input type="hidden" name="token" value="${escapeHtml(input.token)}">` +
|
|
99
|
+
`<button type="submit">Confirm</button></form>`, header);
|
|
100
|
+
}
|
|
101
|
+
/** The link was opened in a browser that did not start the flow (no cookie) or with the wrong token. */
|
|
102
|
+
export function renderWrongBrowserPage() {
|
|
103
|
+
return layout("Open this link in the original browser", `<h1>Open this link in the original browser</h1>` +
|
|
104
|
+
`<p>Finish connecting in the same browser where you started from ChatGPT or Claude, then try again.</p>`);
|
|
105
|
+
}
|
|
106
|
+
/** The flow is gone: already confirmed, timed out, or never existed. */
|
|
107
|
+
export function renderExpiredPage() {
|
|
108
|
+
return layout("This link has expired", `<h1>This link has expired</h1>` +
|
|
109
|
+
`<p>It may already have been used. Go back to ChatGPT or Claude and start connecting again.</p>`);
|
|
110
|
+
}
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"url": "https://github.com/inistate/inistate-mcp",
|
|
9
9
|
"source": "github"
|
|
10
10
|
},
|
|
11
|
-
"version": "1.3.
|
|
11
|
+
"version": "1.3.5",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "npm",
|
|
15
15
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
16
16
|
"identifier": "inistate-mcp",
|
|
17
|
-
"version": "1.3.
|
|
17
|
+
"version": "1.3.5",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
20
20
|
},
|