@interactive-inc/emdash-plugins 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -186,6 +186,8 @@ Notice: defineComponent({
186
186
 
187
187
  CSPを独自に設定するホストでは、すべてのページでテーマのstyle属性(`.site`の`style`)を許可してください。モーションのあるページでは、さらに自オリジンのモジュールscript、Astroのislandが出力するインラインの`<script>`と`<style>`、JavaScript無効時用の`<noscript>`内のインライン`<style>`、動く要素のstyle属性を許可してください。モーションのないページと`motion: false`では、islandのscriptと`<noscript>`のstyleを出力しません。パッケージ既定のCSPは`frame-ancestors`・`object-src`・`base-uri`だけを制限します。
188
188
 
189
+ `builderIntegration`はmiddlewareで、サイトとEmDashのすべての応答に`X-Content-Type-Options: nosniff`・`Referrer-Policy: no-referrer`・既定のCSPを付けます。応答がすでに設定しているヘッダーは上書きしません。`Response.redirect()`や`fetch()`の応答のようにヘッダーを変更できない応答は、状態コード・ヘッダー・本文を保ったまま作り直してから付けます。
190
+
189
191
  ### 権限と検証
190
192
 
191
193
  プレビュー発行はEmDashの`content:read_drafts`権限に従います。匿名とSubscriberは拒否し、Contributor・Author・Editor・Adminは許可します。MCPでは加えて`mcp:tools:builder`スコープが必要です。管理画面は標準セッションを使います。EmDash 1.3.1のプラグインRESTルートをPATで直接呼ぶ場合は`admin`スコープも必要ですが、ロールによる権限チェックは引き続き適用されます。署名リンクは発行から15分有効で、コレクションと1ページに限定されます。
@@ -1,5 +1,5 @@
1
1
  /** Stable plugin identity. Widget names, MCP scopes and plugin API routes derive from this ID. */
2
2
  export declare const pluginId = "builder";
3
3
  /** Kept equal to package.json by tests/builder/constants.test.ts. */
4
- export declare const pluginVersion = "0.1.0";
4
+ export declare const pluginVersion = "0.1.1";
5
5
  //# sourceMappingURL=constants.d.ts.map
@@ -1,5 +1,5 @@
1
1
  /** Stable plugin identity. Widget names, MCP scopes and plugin API routes derive from this ID. */
2
2
  export const pluginId = 'builder';
3
3
  /** Kept equal to package.json by tests/builder/constants.test.ts. */
4
- export const pluginVersion = '0.1.0';
4
+ export const pluginVersion = '0.1.1';
5
5
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,3 @@
1
- export declare const onRequest: import("astro").MiddlewareHandler;
1
+ import type { MiddlewareHandler } from 'astro';
2
+ export declare const onRequest: MiddlewareHandler;
2
3
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/builder/middleware.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,mCAOpB,CAAC"}
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/builder/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,eAAO,MAAM,SAAS,EAAE,iBAYvB,CAAC"}
@@ -1,13 +1,25 @@
1
- import { defineMiddleware } from 'astro:middleware';
2
- export const onRequest = defineMiddleware(async (_context, next) => {
1
+ export const onRequest = async (_context, next) => {
3
2
  const response = await next();
4
- if (!response.headers.has('X-Content-Type-Options'))
5
- response.headers.set('X-Content-Type-Options', 'nosniff');
6
- if (!response.headers.has('Referrer-Policy'))
7
- response.headers.set('Referrer-Policy', 'no-referrer');
3
+ try {
4
+ addSecurityHeaders(response.headers);
5
+ return response;
6
+ }
7
+ catch (error) {
8
+ // Response.redirect() and fetch() responses have immutable headers, so copy them into a new response.
9
+ if (!(error instanceof TypeError))
10
+ throw error;
11
+ const copy = new Response(response.body, { status: response.status, statusText: response.statusText, headers: response.headers });
12
+ addSecurityHeaders(copy.headers);
13
+ return copy;
14
+ }
15
+ };
16
+ function addSecurityHeaders(headers) {
17
+ if (!headers.has('X-Content-Type-Options'))
18
+ headers.set('X-Content-Type-Options', 'nosniff');
19
+ if (!headers.has('Referrer-Policy'))
20
+ headers.set('Referrer-Policy', 'no-referrer');
8
21
  // The admin can embed its own site preview; other sites cannot frame this app.
9
- if (!response.headers.has('Content-Security-Policy'))
10
- response.headers.set('Content-Security-Policy', "frame-ancestors 'self'; object-src 'none'; base-uri 'self'");
11
- return response;
12
- });
22
+ if (!headers.has('Content-Security-Policy'))
23
+ headers.set('Content-Security-Policy', "frame-ancestors 'self'; object-src 'none'; base-uri 'self'");
24
+ }
13
25
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/builder/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,CAAC,MAAM,SAAS,GAAG,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;IACjE,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;QAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IAC/G,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;IACrG,+EAA+E;IAC/E,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;QAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,4DAA4D,CAAC,CAAC;IACpK,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/builder/middleware.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAsB,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;IACnE,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC;QACH,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACrC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sGAAsG;QACtG,IAAI,CAAC,CAAC,KAAK,YAAY,SAAS,CAAC;YAAE,MAAM,KAAK,CAAC;QAC/C,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QAClI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,SAAS,kBAAkB,CAAC,OAAgB;IAC1C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IAC7F,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;IACnF,+EAA+E;IAC/E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,4DAA4D,CAAC,CAAC;AACpJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interactive-inc/emdash-plugins",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "EmDash plugins by Interactive Inc. builder: chat-authored json-render pages, MCP tools and previews",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,4 +1,4 @@
1
1
  /** Stable plugin identity. Widget names, MCP scopes and plugin API routes derive from this ID. */
2
2
  export const pluginId = 'builder';
3
3
  /** Kept equal to package.json by tests/builder/constants.test.ts. */
4
- export const pluginVersion = '0.1.0';
4
+ export const pluginVersion = '0.1.1';
@@ -1,10 +1,22 @@
1
- import { defineMiddleware } from 'astro:middleware';
1
+ import type { MiddlewareHandler } from 'astro';
2
2
 
3
- export const onRequest = defineMiddleware(async (_context, next) => {
3
+ export const onRequest: MiddlewareHandler = async (_context, next) => {
4
4
  const response = await next();
5
- if (!response.headers.has('X-Content-Type-Options')) response.headers.set('X-Content-Type-Options', 'nosniff');
6
- if (!response.headers.has('Referrer-Policy')) response.headers.set('Referrer-Policy', 'no-referrer');
5
+ try {
6
+ addSecurityHeaders(response.headers);
7
+ return response;
8
+ } catch (error) {
9
+ // Response.redirect() and fetch() responses have immutable headers, so copy them into a new response.
10
+ if (!(error instanceof TypeError)) throw error;
11
+ const copy = new Response(response.body, { status: response.status, statusText: response.statusText, headers: response.headers });
12
+ addSecurityHeaders(copy.headers);
13
+ return copy;
14
+ }
15
+ };
16
+
17
+ function addSecurityHeaders(headers: Headers) {
18
+ if (!headers.has('X-Content-Type-Options')) headers.set('X-Content-Type-Options', 'nosniff');
19
+ if (!headers.has('Referrer-Policy')) headers.set('Referrer-Policy', 'no-referrer');
7
20
  // The admin can embed its own site preview; other sites cannot frame this app.
8
- if (!response.headers.has('Content-Security-Policy')) response.headers.set('Content-Security-Policy', "frame-ancestors 'self'; object-src 'none'; base-uri 'self'");
9
- return response;
10
- });
21
+ if (!headers.has('Content-Security-Policy')) headers.set('Content-Security-Policy', "frame-ancestors 'self'; object-src 'none'; base-uri 'self'");
22
+ }