Compare commits
12
Commits
v0.12.0
...
02fb77f72b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02fb77f72b | ||
|
|
09afb438c9 | ||
|
|
2d6ceac0d7 | ||
|
|
bd80ff6a0c | ||
|
|
b90aef79d0 | ||
|
|
84d52390f9 | ||
|
|
4049acf76e | ||
|
|
43a2d8c5a1 | ||
|
|
38a4fcf530 | ||
|
|
dc978231e2 | ||
|
|
5321d613b4 | ||
|
|
b23e63d4c6 |
No files matched your search
@@ -35,8 +35,8 @@ jobs:
|
||||
[worker.oci]
|
||||
max-parallelism = 2
|
||||
|
||||
- name: Test release tooling and wallpaper palette
|
||||
run: node --test tools/ci/release-images.test.mjs static/js/home-palette-core.test.cjs
|
||||
- name: Test release tooling and browser logic
|
||||
run: node --test tools/ci/release-images.test.mjs static/js/home-palette-core.test.cjs static/js/csv-core.test.cjs
|
||||
|
||||
- name: Test
|
||||
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
|
||||
@@ -91,13 +91,25 @@ jobs:
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||
|
||||
- name: Build Gecko relay
|
||||
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.gecko-relay
|
||||
platforms: linux/amd64
|
||||
load: true
|
||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/pageswiki-gecko-relay:${{ env.IMAGE_TAG }}
|
||||
labels: |
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||
|
||||
# Publish only after all builds succeed. Use the host daemon for registry
|
||||
# access; BuildKit does not inherit the runner's /etc/hosts entries.
|
||||
- name: Push images
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer; do
|
||||
for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer pageswiki-gecko-relay; do
|
||||
docker push "$REGISTRY/$IMAGE_OWNER/$image:$IMAGE_TAG"
|
||||
done
|
||||
|
||||
@@ -105,7 +117,7 @@ jobs:
|
||||
if: always()
|
||||
shell: bash
|
||||
run: |
|
||||
for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer; do
|
||||
for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer pageswiki-gecko-relay; do
|
||||
ref="$REGISTRY/$IMAGE_OWNER/$image:$IMAGE_TAG"
|
||||
if docker image inspect "$ref" >/dev/null 2>&1; then
|
||||
docker image rm "$ref" || echo "Could not remove local CI tag: $ref" >&2
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# The relay image contains no browser engine. Mount the independently verified
|
||||
# fixed Gecko distribution read-only at /gecko (see docs/operations/gecko-relay.md).
|
||||
FROM golang:1.25-alpine AS build
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY internal/geckorelay ./internal/geckorelay
|
||||
COPY cmd/gecko-relay ./cmd/gecko-relay
|
||||
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /gecko-relay ./cmd/gecko-relay
|
||||
|
||||
FROM scratch
|
||||
COPY --from=build /gecko-relay /usr/local/bin/gecko-relay
|
||||
COPY --from=build /usr/local/go/LICENSE /licenses/Go.txt
|
||||
COPY --from=build /go/pkg/mod/golang.org/x/net@v0.35.0/LICENSE /licenses/golang-x-net.txt
|
||||
COPY internal/geckorelay/NOTICE.txt /licenses/NOTICE.txt
|
||||
USER 10001:10001
|
||||
EXPOSE 3012
|
||||
ENTRYPOINT ["/usr/local/bin/gecko-relay"]
|
||||
@@ -342,6 +342,12 @@ window.PagesWikiEditor = {
|
||||
}),
|
||||
];
|
||||
|
||||
if (options.preserveLineEndings) {
|
||||
// Split only at LF, keeping any CR bytes in the document. This
|
||||
// preserves mixed LF/CRLF CSV sources instead of rewriting them.
|
||||
extensions.push(EditorState.lineSeparator.of("\n"));
|
||||
}
|
||||
|
||||
if (keymapName === "vim") {
|
||||
installVimCommands();
|
||||
extensions.push(vim());
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"flag"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"pageswiki/internal/geckorelay"
|
||||
)
|
||||
|
||||
func main() {
|
||||
status := flag.Bool("status", false, "print bounded relay resource counters")
|
||||
flag.Parse()
|
||||
// File mount avoids placing the shared secret in image layers or process args.
|
||||
key, err := os.ReadFile(os.Getenv("PAGESWIKI_GECKO_KEY_FILE"))
|
||||
if err != nil {
|
||||
log.Fatal("Gecko relay key file unavailable")
|
||||
}
|
||||
secret := strings.TrimSpace(string(key))
|
||||
addr := os.Getenv("PAGESWIKI_GECKO_LISTEN")
|
||||
if addr == "" {
|
||||
addr = ":3012"
|
||||
}
|
||||
if *status {
|
||||
host, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
log.Fatal("invalid listen address")
|
||||
}
|
||||
if host == "" || host == "0.0.0.0" {
|
||||
host = "127.0.0.1"
|
||||
}
|
||||
if host == "::" {
|
||||
host = "::1"
|
||||
}
|
||||
nonce := make([]byte, 24)
|
||||
if _, err = rand.Read(nonce); err != nil {
|
||||
log.Fatal("random source unavailable")
|
||||
}
|
||||
req, _ := http.NewRequest("GET", "http://"+net.JoinHostPort(host, port)+"/status", nil)
|
||||
req.Header.Set(geckorelay.GrantHeader, geckorelay.Sign(secret, geckorelay.Grant{Subject: "operator:status", Nonce: hex.EncodeToString(nonce), Expires: time.Now().Add(30 * time.Second).Unix()}))
|
||||
client := http.Client{Timeout: 5 * time.Second, Transport: &http.Transport{Proxy: nil}, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal("relay status unavailable")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
log.Fatal("relay status denied")
|
||||
}
|
||||
if _, err = io.Copy(os.Stdout, io.LimitReader(resp.Body, 4096)); err != nil {
|
||||
log.Fatal("relay status read failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
assets := os.Getenv("PAGESWIKI_GECKO_ASSETS")
|
||||
if assets == "" {
|
||||
assets = "/gecko"
|
||||
}
|
||||
if err := geckorelay.VerifyAssets(assets); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
distribution, err := geckorelay.VerifyDistribution(assets)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
relay, err := geckorelay.New(secret, assets)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
relay.Distribution = distribution
|
||||
s := &http.Server{Addr: addr, Handler: relay, ReadHeaderTimeout: 5 * time.Second, IdleTimeout: 30 * time.Second, MaxHeaderBytes: 16 << 10}
|
||||
log.Printf("Gecko relay listening; authenticated TCP 80/443 only")
|
||||
log.Fatal(s.ListenAndServe())
|
||||
}
|
||||
+2
-2
@@ -1398,13 +1398,13 @@ class PagesWikiCLI:
|
||||
if not args:
|
||||
for extension_id, enabled in sorted(states.items()):
|
||||
print(f"{extension_id}\t{'enabled' if enabled else 'disabled'}")
|
||||
print("(extensions not listed here use the default: enabled)")
|
||||
print("(unlisted extensions use their manifest default; viewer.gecko: disabled, others: enabled)")
|
||||
return
|
||||
extension_id = args[0].strip()
|
||||
if not re.fullmatch(r"[a-z][a-z0-9._-]{1,63}", extension_id):
|
||||
raise CLIError("invalid extension ID")
|
||||
if len(args) == 1:
|
||||
print(f"{extension_id}\t{'enabled' if states.get(extension_id, True) else 'disabled'}")
|
||||
print(f"{extension_id}\t{'enabled' if states.get(extension_id, extension_id != 'viewer.gecko') else 'disabled'}")
|
||||
return
|
||||
value = args[1].lower()
|
||||
if value not in {"on", "off"}:
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
import sqlite3
|
||||
import io
|
||||
from contextlib import redirect_stdout
|
||||
from types import SimpleNamespace
|
||||
|
||||
|
||||
SCRIPT = Path(__file__).with_name("pageswiki-cli")
|
||||
@@ -43,5 +47,23 @@ class ContentTypeDetectionTest(unittest.TestCase):
|
||||
self.assertEqual(content_type, "text/plain; charset=shift_jis")
|
||||
|
||||
|
||||
class ExtensionDefaultTest(unittest.TestCase):
|
||||
def test_gecko_is_opt_in(self) -> None:
|
||||
db = sqlite3.connect(":memory:")
|
||||
self.addCleanup(db.close)
|
||||
db.execute("CREATE TABLE config(domain_uuid TEXT,key TEXT,value TEXT,updated_at INTEGER,UNIQUE(domain_uuid,key))")
|
||||
# Exercise the CLI command without reading any deployment database.
|
||||
owner = next(value for value in vars(pageswiki_cli).values() if isinstance(value, type) and hasattr(value, "command_extension"))
|
||||
fixture = SimpleNamespace(db=db, domain_uuid="synthetic")
|
||||
output = io.StringIO()
|
||||
with redirect_stdout(output):
|
||||
owner.command_extension(fixture, ["viewer.gecko"])
|
||||
owner.command_extension(fixture, ["viewer.gecko", "on"])
|
||||
owner.command_extension(fixture, ["viewer.gecko"])
|
||||
owner.command_extension(fixture, ["viewer.gecko", "off"])
|
||||
owner.command_extension(fixture, ["viewer.gecko"])
|
||||
self.assertEqual(output.getvalue().splitlines(), ["viewer.gecko\tdisabled", "viewer.gecko\ton", "viewer.gecko\tenabled", "viewer.gecko\toff", "viewer.gecko\tdisabled"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,47 @@
|
||||
# Optional development/pilot overlay, never selected by the production recipe.
|
||||
# Requires host egress rules; an isolated bridge alone is not an egress firewall.
|
||||
services:
|
||||
app:
|
||||
environment:
|
||||
PAGESWIKI_GECKO_RELAY: http://gecko-relay:3012
|
||||
PAGESWIKI_GECKO_KEY_FILE: /run/secrets/gecko-key
|
||||
volumes:
|
||||
- ${PAGESWIKI_GECKO_KEY_PATH:?Set absolute relay key path}:/run/secrets/gecko-key:ro
|
||||
networks:
|
||||
default: {}
|
||||
gecko-front: {}
|
||||
gecko-relay:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.gecko-relay
|
||||
image: ${PAGESWIKI_GECKO_IMAGE:-pageswiki-gecko-relay:dev}
|
||||
environment:
|
||||
PAGESWIKI_GECKO_KEY_FILE: /run/secrets/gecko-key
|
||||
volumes:
|
||||
- ${PAGESWIKI_GECKO_KEY_PATH:?Set absolute relay key path}:/run/secrets/gecko-key:ro
|
||||
- ${PAGESWIKI_GECKO_ASSETS_DIR:?Set verified complete Gecko bundle directory}:/gecko:ro
|
||||
networks:
|
||||
gecko-front: {}
|
||||
gecko-egress: {}
|
||||
read_only: true
|
||||
cap_drop: [ALL]
|
||||
security_opt: [no-new-privileges:true]
|
||||
mem_limit: 256m
|
||||
cpus: 0.5
|
||||
pids_limit: 64
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: [CMD, /usr/local/bin/gecko-relay, --status]
|
||||
interval: 30s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
networks:
|
||||
gecko-front:
|
||||
internal: true
|
||||
ipam:
|
||||
config:
|
||||
- subnet: ${PAGESWIKI_GECKO_FRONT_SUBNET:-172.24.0.0/27}
|
||||
gecko-egress:
|
||||
ipam:
|
||||
config:
|
||||
- subnet: ${PAGESWIKI_GECKO_EGRESS_SUBNET:-172.24.0.32/27}
|
||||
@@ -70,7 +70,7 @@
|
||||
- `+` は挿入・下書き、`文` は言語の編集・分岐、`↶` は旧リビジョンを作業バッファへ
|
||||
読み込む。復元は明示保存で新 Revision を追加し、旧 Revision を書き換えない。
|
||||
履歴は50件ずつ追加取得し、現在言語で絞り込む。分岐は翻訳生成ではなく本文のコピー。
|
||||
- 挿入は子ページ・表・画像キャプション・補足・コード・引用の6種の初期パレット。
|
||||
- 挿入は子ページ・表・画像キャプション・補足・コード・引用・CSV macroの初期パレット。
|
||||
画像 URL 等のプレースホルダーは編集が必要。ファイルピッカー、図形・外部 widget の
|
||||
パラメータ編集、プラグインによる挿入パーツ登録は既存の HTML editor 設計に残る。
|
||||
- touch/coarse pointer + hover 不可の端末ではデスクトップの Vim 設定を上書きせず、
|
||||
@@ -78,6 +78,8 @@
|
||||
|
||||
## 次段階の実装順序
|
||||
|
||||
CSVの表編集は既存保存・下書き・履歴の契約へ接続済みです。CSVはHTML変換と文字列自動マージを行わず、競合時は比較して採否を決めます。BOMと混在改行を保持するため、CSV初期値はHTMLのtextarea解析を通さず安全なJS文字列として渡し、CodeMirrorはLFのみで分割します。初期フォーカスの遅延処理も、表セルなどへ移ったフォーカスを奪いません。詳細な上限と残件は[表設計](extensions.md)を参照してください。
|
||||
|
||||
1. **E6a presence**:編集中リースの共有ストアと認可付き API、別端末を含む表示。
|
||||
管理者にだけ見える監視ではなく、同じ Page/language を編集できる参加者に限定する。
|
||||
2. **E6b realtime**:下記 CRDT 詳細設計・採用ライブラリ・同時変換ルールを確定した後に
|
||||
|
||||
@@ -48,11 +48,25 @@ IPアドレス管理(IPAM)、DNSゾーン/レコード管理、機器・
|
||||
|
||||
## CSV/表・スライド拡張(設計TODO)
|
||||
|
||||
CSVをPage本文へ複製せず、認可済みの別Documentをテーブルとして投影するmacroを用意します。候補構文は `{{csv:/data/items.csv range=A1:H200 header=true}}` とし、Path、Revision(またはasset hash)、列・行上限、表示モードを正規化してキャッシュキーに含めます。macroは表示時にboundedなProjectionを作るだけで、結果HTMLを正本へ逆流させません。CSV Editorは元Revisionを編集し、表投影とは別の操作・競合・権限として扱います。
|
||||
初期CSV macroは実装済みです。`{{csv:/data/items.csv range=A1:H200 header=true}}` を認証済みProjectionで展開し、`rev=` で同じObjectのRevisionへ固定できます。現在のPath閲覧権限を毎回検査し、外部URL、匿名公開、asset指定、共有キャッシュはこの段階に含めません。入力256 KiB・UTF-8、表示200行×32列、走査2,000行・100列、セル16 KiB、Projection当たり4種類のCSVまでに制限します。引用符・改行・BOMに対応し、セルはHTML escapeしてmacroや数式を実行しません。処理不能時は内容を漏らさない警告に置き換えます。Authoringでは元のmacroを保持します。
|
||||
|
||||
既存CSVの編集は `/e/-/{path}` の組み込みエディタで行います。デスクトップはソースと表を並べ、700px以下では表を全幅表示してソースへ切り替えます。セル編集、行・列追加/削除、20操作までの表のUndo/Redoに対応。表は200行・32列・セル16 KiB以内を25行ずつ描画し、先頭行を自動でヘッダ扱いしません。矩形でない行の欠落セルは表示だけでは補わず、列追加・貼り付けで必要になった部分だけ空セルを補います。全体256 KiB・UTF-8以内を対象とし、超過・不正形式の表を部分編集可能にして保存することはありません。表上限を超えても全体上限内ならソースで編集できます。
|
||||
|
||||
表計算ソフトからの複数セル貼り付けは、フォーカス中のセルを左上として反映します。クリップボードの `text/plain` にタブまたは改行があればタブ区切り表として解析し、引用符内の改行・タブ・二重引用符を保持します。カンマは列区切りにせずセル値として扱い、単一行の通常テキストはセル内への貼り付けです。複数行を一つのセルへ貼る場合は引用符で囲むかソースを編集します。HTML形式のクリップボードは使いません。必要な行・セルの拡張を含めて1操作でUndo/Redoでき、構文・行列・セル・変換後CSV全体の上限を検査してから一括反映します。失敗時は部分反映せず、既存のUndo履歴も変更しません。貼り付け範囲外のセルと改行形式は維持します。
|
||||
|
||||
CSV正本をHTMLへ変換せず、未変更fieldの引用符、BOM、混在LF/CRLFを保持します。セル内のHTML、macro、数式は実行しません。表編集も既存の下書き・認証切れ検出・言語別Revision CAS・履歴復元を使用し、他の保存と競合したCSVは文字列の自動マージをせず比較画面へ送ります。原文と編集済み表の両方を別正本として保存しません。DBスキーマ変更はありません。CSV新規作成ウィザード、TSVファイル/文字コード変換、大容量表のwindow編集、矩形選択/範囲コピー、列型/数式、ODSは残件です。
|
||||
|
||||
CSVをPage本文へ複製せず、認可済みの別Documentをテーブルとして投影します。共有キャッシュを将来追加する際は、Path、Revision(またはasset hash)、列・行上限、表示モードと権限を考慮します。macroは表示時にboundedなProjectionを作るだけで、結果HTMLを正本へ逆流させません。CSV Editorは元Revisionを編集し、表投影とは別の操作・競合・権限として扱います。
|
||||
|
||||
交換形式はRFC 4180互換CSV(UTF-8、CRLF、引用符・改行を含むfield、BOMの扱いを明示)を第一正本とします。複数シート、型、数式、結合セル、書式が必要な場合はODSを別アダプタ/Assetとして扱い、CSVへの不可逆変換を黙って行いません。行数、列数、セル長、総バイト、ネストmacroを制限し、malformed inputは安全なテキスト表示へfallbackします。
|
||||
|
||||
スライドは、Markdown/HTMLの正本からReveal.js互換のProjectionを生成する連携アダプタを設けます。HedgeDoc、Slidevは外部originのホスト型アダプタとして、保存・公開・ユーザー情報をPages Wikiの権限へ自動昇格させず、read-only preview→明示的なimport/saveの順にします。JSを使用できない環境向けには、CSS scroll-snap/`:target`/print CSSだけでページ送りできるCSS-only Slide Editorを別実装します。外部ランタイム停止時は静的HTML/Markdownへ安全にfallbackし、任意script、remote import、iframe権限を本文から許可しません。
|
||||
スライドはローカル同梱のReveal.js 6.0.2で表示します。`/v/slides/{path}` は通常のPath閲覧権限でHTML/Markdownの最新Revisionを取得し、HTMLページのスライドアイコンや「連携アダプタで開く」から移動できます。組み込みHTML/Markdownエディタのスライドアイコンは、未保存の本文を通常プレビューと同じ変換経路で投影します。表示DOMを保存せず、保存・下書き・競合処理は既存エディタに任せます。Markdownの空行で囲んだ `---`、HTMLの直下の `<hr>` が横方向の区切りで、直下の `<section>` も1枚として扱います。コードブロック内の区切りは分割しません。
|
||||
|
||||
Reveal実行は `allow-scripts allow-popups` のsandbox iframeに隔離し、`allow-same-origin` は付けません。本文のscript・CSS・iframe・フォーム・任意data属性を渡さず、独自プラグインや外部Markdownを読み込みません。画像は同一originだけ、リンクはHTTP(S)だけです。矢印キー・タッチ・画面内コントロールで移動し、履歴やURL hashを変更しません。ビューアは全画面に対応し、背景・文字色はテーマから引き継ぎます。ライブラリ読込失敗時は静的なサニタイズ済み本文へfallbackします。本文256 KiB・100枚・DOM 10,000ノード/深さ64を上限とし、常時バックグラウンド生成や共有キャッシュは持ちません。`viewer.slides` は拡張設定でドメイン単位に停止でき、停止後のページではビューア・編集切替・アダプタ候補を表示しません。MITライセンス・固定版・配布元・hashは `static/vendor/reveal/` に同梱します。DBスキーマ変更はありません。
|
||||
|
||||
700px以下の編集画面ではスライドプレビューを全幅表示し、既存のプレビュー非表示ボタンでソースへ戻ります。小画面で自動スクロール形式に変わらないよう `scrollActivationWidth: null` を指定します([Reveal.js公式仕様](https://revealjs.com/scroll-view/))。
|
||||
|
||||
縦方向のスライド、fragments、発表者ノート、macroの非同期展開、スライド専用印刷、外部画像の承認連携は残件です。HedgeDoc、Slidevは外部originのホスト型アダプタとして、保存・公開・ユーザー情報をPages Wikiの権限へ自動昇格させず、read-only preview→明示的なimport/saveの順にします。JSを使用できない環境向けには、CSS scroll-snap/`:target`/print CSSだけでページ送りできるCSS-only Slide Editorを別実装します。
|
||||
|
||||
ネットワーク図ではnwdiagを追加候補とします。ソースをbounded parserで検証し、renderer version/theme/document hashをキーに静的SVGをキュー生成します。include、外部画像・font、未知directive、危険なSVG属性は拒否し、renderer停止時はescaped sourceまたは最後に検証済みの静的画像へfallbackします。編集アダプタの保存はone-use ticketと楽観的Revision競合を使い、Kroki経由の場合もorigin、timeout、quotaを明示します。
|
||||
|
||||
|
||||
+68
-1
@@ -50,7 +50,7 @@ newsboat/neomuttを参考に、デスクトップは左から購読元・一
|
||||
tooltipに残します。タブ名は「RSS」、原文リンクはアイコンです。件数・保持上限・操作の説明は常設せず、
|
||||
キー案内は`?`で表示します。設定と保存フォームは本文ペイン内に置き、モーダルを増やしません。
|
||||
|
||||
`j/k`・上下矢印で移動、`Enter/l`で本文、`Esc/h`で一覧、`/`で件名・配信元検索、`n`で次の未読、
|
||||
`j/k`・上下矢印で記事移動、`Shift+j/k`で次/前のFreshRSSフォルダ、`Enter/l`で本文、`Esc/h`で一覧、`/`で件名・配信元検索、`n`で次の未読、
|
||||
`m`で既読切替、`*`でstar、`r`で背景更新予約、`?`でキー案内です。フォーム入力・IME変換中は
|
||||
一覧ショートカットを抑止します。FreshRSSでは書戻し許可時だけ`m`と`*`で操作を予約します。
|
||||
|
||||
@@ -151,6 +151,15 @@ source指定と組み合わせ、既存の未読・star・検索・keysetペー
|
||||
絞り込み対象は最新200記事のcache内に限られ、購読を選んでも履歴全件を外部取得しません。
|
||||
購読の追加・削除やカテゴリの編集はFreshRSS側で行います。
|
||||
|
||||
`Shift+j`/`Shift+k`は、選択中のFreshRSS接続内のフォルダを表示順に選び直します。
|
||||
空フォルダと未分類も含め、先頭・末尾では停止します。「すべての購読」からは、下方向なら先頭、
|
||||
上方向なら末尾を選びます。購読元を選択中なら、その所属フォルダを起点とします。
|
||||
記事検索・未読/starフィルタ・フォルダ開閉状態は維持し、個別購読元の絞り込みは解除します。
|
||||
購読・フォルダの検索でツリーが隠れている場合は、そのナビゲータ検索だけを解除します。
|
||||
前の本文と本文リクエストは破棄して一覧へ戻し、連打では最後の選択だけを反映します。
|
||||
フォーム・編集可能領域・モーダル・IME入力中、およびCtrl/Alt/Commandとの併用では実行しません。
|
||||
source自体の切替、分類の移動・書換え、外部再取得、未読/既読変更は行いません。
|
||||
|
||||
ショートカットヘルプは`?`で開閉し、`Esc`または閉じるボタンでも閉じます。
|
||||
ヘルプだけを閉じる操作では閲覧中の記事や入力フォームを変更せず、エラー等のstatus表示も保持します。
|
||||
|
||||
@@ -171,6 +180,54 @@ iframeは`allow-scripts`だけのsandboxと`no-referrer`を使い、親画面へ
|
||||
表示できないページやログイン・フォーム操作が必要な場合は、dialog内の別タブアイコンを使います。
|
||||
表示可否をcross-origin DOMの読取で判定したり、失敗を装って自動で別タブへ遷移したりはしません。
|
||||
|
||||
### Geckoと自前Wispによる原文閲覧
|
||||
|
||||
通信中継方式を採用する。実装は独立した実験的ビューアとして段階導入し、現行の`tab`/`embedded`を
|
||||
自動置換しない。Geckoビューア・中継・個人設定の接続を実装した。`viewer.gecko`は既定無効で、
|
||||
管理者による有効化と中継の構成が揃った場合だけ選択できる。本番への配備は別途行う。
|
||||
|
||||
端末上の`gecko.js`で1ページを描画し、外部HTTP(S)通信だけを管理者が配置したWispサービスへ中継する。
|
||||
サーバー上でFirefoxを起動したり画面をストリーミングしたりはしない。Firefox全体の操作画面は含めず、
|
||||
既存の記事上dialogにcanvas、戻る・進む・再読込・閉じる・別タブの操作を置く。
|
||||
自前中継を必須とし、Puter等の公開中継への自動fallbackは設けない。
|
||||
|
||||
現行upstreamはGeckoのソケット通信をWispへ接続する。通常のWebページの`fetch`へ単純に置き換えて
|
||||
任意のサイトを直接取得することは前提にしない。GeckoとWisp実装は検証したrevision・プロトコルで固定し、
|
||||
更新時にサイト互換性とセキュリティ修正を再評価する。
|
||||
[gecko.js v0.0.1](https://github.com/HeyPuter/firefox-wasm/releases/tag/v0.0.1)、
|
||||
[Wisp仕様](https://github.com/MercuryWorkshop/wisp-protocol/blob/main/protocol.md)。
|
||||
|
||||
中継はPagesWiki本体とは別コンテナ・別ネットワーク境界とする。外部から無認証で利用できる公開proxyにしない。
|
||||
既存の認証・Domain・本人に束縛した短命セッションを発行し、WebSocketのOriginを検証する。
|
||||
失効・ログアウト・拡張無効化は既存の接続にも反映する。Cookie・WikiのBearer token・FreshRSS資格情報を
|
||||
外部ページへ渡さず、中継用の秘密をURLやログに残さない。
|
||||
|
||||
接続先は公開HTTP(S)用のTCPポートに限定し、UDPや任意の管理用ポートは許可しない。
|
||||
DNS解決後の実接続先でloopback・private・link-local・metadata等を拒否し、IPv4/IPv6・DNS rebindingを
|
||||
含めて検査する。接続検査だけでなくコンテナの外向き通信制限を併用し、Wiki・DB・管理ネットワークへ到達させない。
|
||||
同時セッション・ソケット・帯域・idle/接続timeoutの上限を設ける。ログは通信量・失敗分類・処理時間に限り、
|
||||
記事本文や資格情報を記録しない。HTTPSの証明書検証を無効化せず、HTML改変やTLS終端による閲覧制限回避は行わない。
|
||||
|
||||
原文クリック時だけエンジンを遅延ロードする。静的WASM資産はversion付きでキャッシュするが、
|
||||
記事本文・Cookieの永続化は初期対象外とし、上限付きのメモリプロファイルを渡す。
|
||||
固定版の`destroy()`はWASMの完全終了を保証しないため、初期実装では短時間保持を行わず、
|
||||
閉じるとiframeごと破棄する。タブ非表示が60秒続いた場合も閉じる。
|
||||
戻る/進むは最大64件のビューア内URL履歴から再読み込みし、フォームやスクロール位置は復元しない。
|
||||
上流の最小GREではSessionStoreFunctionsがなく、標準history.back()は失敗する。
|
||||
中継の接続数・転送量・拒否数は認証付きstatus/CLIで取得できる。設定UIへの監視統合と端末側計測は残件とする。
|
||||
|
||||
pthread/SharedArrayBufferのcross-origin isolationはRSSの親documentまで含めて検証する。
|
||||
COOP/COEPをWiki全体へ一律追加せず、対象ビューだけで既存の壁紙・外部リソース・共有操作への影響を確認する。
|
||||
isolation不可・端末のメモリ不足・未対応サイトではエラーと別タブ操作を示し、黙って外部中継や別タブへ切り替えない。
|
||||
|
||||
受入条件は、合成ページでのnavigation・日本語入力・検索・コピー、私有アドレス拒否・認証失効・中継停止・
|
||||
資源上限・無効化、デスクトップとiPhone SEのSafariでの初回/再表示時間・スクロール・メモリ確認とする。
|
||||
実記事での測定は明示した対象で行い、実FreshRSSの全原文や外部カレンダー・メール内容を自動巡回しない。
|
||||
|
||||
現時点ではChromiumで合成Wisp記事の描画・クリック遷移・ビューア内の戻る・接続破棄、
|
||||
接続先制限・資格情報分離・ログアウト/拡張無効化時のWebSocket終了を自動テストした。
|
||||
導入方法、資産hash、資源上限、外向きfirewallと本番前の残件は[Gecko中継の試験導入](../../operations/gecko-relay.md)にまとめる。
|
||||
|
||||
## 既読とstarの書戻し
|
||||
|
||||
server-authoritative stateと未送信の操作を分けます。操作ごとのrequest_idで重複を防ぎ、成功応答前に確定済みと表示しません。newsboat等で同時変更された場合、古いローカルcacheをまとめて送り返しません。接続解除・認可失効時は未送信変更を勝手に再送しません。
|
||||
@@ -336,6 +393,16 @@ Wiki単独は親Path配下の `rss-{request UUID}` に新規作成します。
|
||||
- [ ] RSS-6:大規模利用時の公平性、host別並列上限、Retry-After/backoff、資格情報rotation UI。
|
||||
- [x] RSS-7:FreshRSSの購読一覧・カテゴリを使うnavigation。同名ID分離、複数カテゴリ、cache内絞り込み、背景での原子的更新、失敗時保持。
|
||||
- [x] RSS-7b:分類フォルダの継承、空フォルダ・未分類、開閉状態保存、50件ずつの購読描画、分類移動への追従。schema v6の再実行・失敗rollbackと1440px/390pxの合成試験。
|
||||
- [x] RSS-7c:Shift+j/kによるフォルダ選択。空・未分類・端・購読選択中・検索維持・入力/モーダル抑止・連打を合成試験。
|
||||
- [x] RSS-8a:Gecko端末描画+自前Wisp中継の方式決定。公開中継を使わず、独立・既定無効で導入する。
|
||||
- [x] RSS-8b1:upstream v0.0.1/hash固定、最小埋め込みと親documentのisolation、Chromiumで合成記事の描画・遷移確認。
|
||||
- [ ] RSS-8b2:Safari/iPhone SE実機、IME・コピー・実サイト互換性。固定配布物のlicense/notice整備、HTTPSと証明書エラー、日本語findの合成試験は実施済み。
|
||||
- [x] RSS-8c1:認証付きWisp TCP profile、公開IP/port制限、失効・資源上限・管理者/CLI無効化・内部status。
|
||||
- [ ] RSS-8c2:運用ホストの外向きfirewall、設定UIへの中継監視統合、負荷時の長時間受入。
|
||||
- [x] RSS-8d1:個人設定の選択、1ページのpopup閲覧、戻る/進む/再読込/別タブ/終了。
|
||||
- [ ] RSS-8d2:初回/再表示・低メモリ端末の性能評価、実行中の切断・複数タブのUX、本番配備。起動上限と起動失敗時のiframe破棄・原文リンクへの退避は実装済み。
|
||||
|
||||
一覧には配信日と配信時刻(HH:mm)を分けて表示します。Domainの設定タイムゾーンを使い、tooltipには年・秒・タイムゾーンを含めます。配信日時不明は「—」とし、取得日時で補いません。モバイルでも時刻欄を残します。
|
||||
|
||||
隔離試験はRSS/Atom・FreshRSS login/read、欠落ID・巨大/不正feed、条件付きGET、失敗時cache保持、
|
||||
本人分離・失効・readonly、二重送信・版競合・旧worker拒否、migration再実行/失敗rollback、
|
||||
|
||||
@@ -103,15 +103,15 @@ P0は認可・整合性・復旧の安全条件、P1は日常利用の回復性
|
||||
| SHARE-01 / P2 | 未実装:委譲share URL、期限/失効/監査、説明可能な権限総覧 | AUTH-01、PUB-01。login/adapter/federation資格情報と別目的、単一Page投影、caveat・依存物の失効を検証 | [公開](publication.md)、[Schutzaria](schutzaria.md) |
|
||||
| COLLAB-01 / P2 | 一部実装:Page等の変更購読、最近閲覧/編集、集約通知。コメント/反応/評価は未実装 | OUT-01。現在権限で再投影、private履歴のopt-in/保持。inline commentはRevision変更時の孤立・再接続を扱う | [拡張](extensions.md) |
|
||||
| BLOG-01 / P2 | 一部実装:安全なtDiary import、最近コメント、遠隔ブログ射影 | COLLAB-01、遠隔はFED-01。importは再開/重複抑止/dry-run。同一instance射影を再実装しない | [ブログ・日記](blog-diary.md) |
|
||||
| CSV-01 / P2 | viewerのみ実装:別Documentを投影するCSV macro/editor、ODS境界 | 行列・セル・総量上限、Revision固定、権限、CSV引用/改行fixture。表示HTMLをCSV正本へ逆流させない | [表設計](extensions.md) |
|
||||
| DIAGRAM-01 / P2 | 一部実装:nwdiag/Draw.io provider、slide preview/editor | RENDER-01。安全なSVG・include拒否・renderer版固定、ticket/CAS保存、print。既存Excalidraw/Krokiとは分ける | [Kunstzeal](kunstzeal.md) |
|
||||
| CSV-01 / P2 | viewer・有界CSV macro・既存CSVの表編集/複数セル貼り付けを実装。残件:新規作成UI、大容量編集、矩形選択/範囲コピー、匿名投影、asset指定、ODS境界 | BOM/改行保持、25行描画、行列・セル・総量上限、貼り付けの一括検証/Undo、Revision CAS、権限、競合確認/履歴復元fixture。表示HTMLをCSV正本へ逆流させない | [表設計](extensions.md) |
|
||||
| DIAGRAM-01 / P2 | Reveal.jsビューア/編集プレビューを実装。残件:nwdiag/Draw.io provider、縦スライド・notes・専用print | RENDER-01。有界入力、sandbox、固定版ローカル同梱、ドメイン単位停止、Path認可。SVG・include拒否・ticket/CAS保存はprovider別に検証 | [Kunstzeal](kunstzeal.md)、[スライド](extensions.md) |
|
||||
| RECIPE-01 / P2 | 未実装:構造化レシピmetadataとPage投影の初期slice | 材料・数量・未知単位を保持、人数変更は派生値、Asset認可、版競合、出典・公開確認 | [料理レシピ](recipe-management.md) |
|
||||
|
||||
## D. 選定・別サブプロジェクト
|
||||
|
||||
| ID / 優先 | 状態・次の作業 | 着手ゲート・最初の検証 | 詳細 |
|
||||
| --- | --- | --- | --- |
|
||||
| RSS-01 / P2 | 一部実装:内蔵簡易正本、FreshRSS読取connector、3ペインUI・HTML本文、Wiki保存・タスク化・dashboard、OPML確認付き入出力 | 残件はFreshRSS既読/star書戻し、購読/カテゴリnavigation、実接続受入、公平性/backoff。managed schema feeds v3・隔離fixture。本番未反映。二重正本・停止時の自動切替なし | [RSS](feeds.md) |
|
||||
| RSS-01 / P2 | 一部実装:内蔵簡易正本、FreshRSS読取・既読/star書戻し、購読/カテゴリnavigation、3ペインUI・HTML本文、Wiki保存・タスク化・dashboard、OPML、配信時刻 | 残件は実接続受入、公平性/backoff、Gecko実機・運用受入。個別の実装/受入状況はRSS設計を参照。二重正本・停止時の自動切替なし | [RSS](feeds.md) |
|
||||
| IMAP-01 / P3 | 未実装・選定待ち:IMAP読取同期 | provider/認証/保持を決める。UIDVALIDITY/UID、添付量、外部画像、失効をfixture化。neomutt captureは実装済みで別 | [メール](mail.md) |
|
||||
| TICKET-01 / P3 | 未実装:queue/番号/workflow/外部依頼者 | 共有範囲と状態遷移を定義、同時採番・失効・監査。既存個人タスクをticketと呼び替えない | [タスクとticket](tasks-tickets.md) |
|
||||
| EXT-01 / P3 | built-inのみ:第三者manifest/署名/隔離runtime、停止・rollback・観測 | capability・secret・host・予算・export契約。任意コードをGoプロセス内へ直接ロードしない | [拡張](extensions.md) |
|
||||
@@ -126,7 +126,7 @@ P0は認可・整合性・復旧の安全条件、P1は日常利用の回復性
|
||||
- **HOLD-01**:`/tasks/` 配下のメールWikiルーティング調査。利用者の棚上げ指定を維持。関連未コミットファイルを今回の実装・文書コミットへ混ぜない。
|
||||
- **HOLD-02**:vim.wasm runtime改善とnativeアプリ起動。既存設定UIは残すが、自動的に再開しない。
|
||||
- **HOLD-03**:全面WYSIWYG、E6 CRDT/OT共同編集。まずEDIT-01と認可/presence契約、保存量・オフライン・競合モデルを確定する。
|
||||
- **HOLD-04**:本番への反映。作業履歴/日次メールのv3/v4移行を含む同世代保全と隔離復元試験、容量確認、SMTP副作用照合が必要。古いbinaryを新schemaへ向ける切戻しは禁止。
|
||||
- **HOLD-04**:本番反映は実装と別ゲート。[v0.15.0までの配備](../../operations/releases/2026-11-08-v0.15.0.md)は完了。追加変更には同世代保全と隔離復元試験、容量確認、外部副作用照合が必要。古いbinaryを新schemaへ向ける切戻しは禁止。
|
||||
|
||||
## 実装と分けて管理する受入
|
||||
|
||||
|
||||
@@ -111,7 +111,8 @@ Cache-Control: private, no-store
|
||||
- [ ] ディスクcacheの容量・TTL・清掃、renderer更新時の不整合、障害後の一時ファイル残留を管理する。
|
||||
- [ ] provider宛通信と描画サービス内の外部参照を分け、送信許可・接続先・ネットワーク隔離・バージョン固定を契約化する。
|
||||
- [ ] nwdiagの有界parser・安全なSVG出力・編集preview、Draw.io等のproviderを追加する。現在のregistryにnwdiagは実装されていない。
|
||||
- [ ] Reveal互換・HedgeDoc・Slidev・CSS-onlyスライドのimport/save/printを独立providerとして設計する。
|
||||
- [x] Reveal.jsの有界ビューア・既存HTML/Markdownエディタ内previewをローカル固定版で接続する。Path認可・sandbox・ドメイン停止を持ち、正本への保存は既存エディタを利用する([スライド設計](extensions.md))。
|
||||
- [ ] Revealの縦スライド・発表者notes・専用print、HedgeDoc・Slidev・CSS-onlyスライドのimport/save/printを独立providerとして設計する。
|
||||
- [ ] Excalidrawのhosted/browser実行とPDF/動画サムネイル・metadata subprocessを、各々の安全境界を維持したまま段階的に接続する。
|
||||
|
||||
## 検証と反映
|
||||
|
||||
@@ -14,6 +14,14 @@ childrenは現在Pathを既定にし、表示形式は本文macroの `view` 引
|
||||
|
||||
`/v/tree/{path}` は範囲を限定します。展開・全展開・全折りたたみ状態の保持、複数選択、rename・移動・削除はPath操作と一致させます。一般の子一覧から予約ユーザー領域を混入させません。再帰操作は事前の全対象確認と競合検出が必要です。
|
||||
|
||||
## Browserのアップロード
|
||||
|
||||
`/v/browser/{path}` の一覧へファイルをドロップすると、現在のPath配下へアップロードします。フォルダ行へのドロップではそのフォルダが宛先になります。既存の内部Path移動・選択操作とは区別します。
|
||||
|
||||
右下のフローティングカードに待機・送信中・完了・失敗・取消と進捗を表示します。追加ドロップは同じキューへ積み、送信は1件ずつ、最大100件・各256 MiBまで。待機中の取消、折りたたみ、終了分のクリアに対応します。終了後は一覧だけを再取得し、キューは残します。
|
||||
|
||||
既存の認可付き `/v/upload` を使用し、`If-None-Match: *` で同名Pathの上書きを防ぎます。通信断は保存結果不明として扱い、自動再送しません。キューはページ内のみで、ページ離脱・再起動後の再開やフォルダの再帰アップロードには未対応です。新規オブジェクト・Path・初回Revisionの一体的なトランザクション化は残課題です。
|
||||
|
||||
## ホームとブックマーク
|
||||
|
||||
通常トップバー型、中央検索型、検索+セクションカード型を選びます。セクションは手動URL/Path、または指定親の子リンクを表示します。設定は歯車のポップアップで、閲覧画面を編集フォームで埋めません。カード列はviewportに適応します。
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
|
||||
### 3. テーマ・アカウント・連絡先
|
||||
|
||||
- [x] 信頼できる端末の長期ログイン(2026-11-08ローカル実装、本番未反映):ログイン画面の明示選択で最大30日。Domain管理者は設定→セッションで0〜30日(0で無効)を指定する。通常ログインは既存の絶対期限を維持。パスワード/TOTP、LDAP、OIDC、SMTPマジックリンクに適用し、選択は認証challengeに固定する。CookieとBearerの期限はDBの発行期限と一致し、ログアウト・管理者失効・アカウント停止で無効になる。既存セッションの延長、TOTPの省略、アクセスによる期限延長は行わない。
|
||||
- [x] 独立CLIの `pages login --remember` / `pages login --oidc --no-browser --remember`。S256 grantに選択を保存し、ブラウザ側のクエリで上書きできない。APIセッションは承認元ブラウザの残存期限を超えない。期限切れ後はlogoutなしで再認証でき、同一アカウントのcwdと未送信タスク下書きを保持する。別アカウントへの下書き移動は拒否する。旧サーバーは選択を無視する場合があるため、実際の期限は応答のexpires_inを正とする。
|
||||
- [x] タスク編集フッターの関連ページ導線(2026-11-08ローカル実装、本番未反映):アーカイブ・削除・保存と同じ並びに関連ページリンクを表示。新規タブで開き、編集中の内容を保持する。保存済みの関連Pageがない場合、解除した場合、Path変更が未保存の場合は非表示。デスクトップ/モバイル4幅のブラウザテストを追加。
|
||||
|
||||
長期ログインのDB変更はmanaged component `cli-auth` v2の `remember` 列追加のみ。既存行はfalse、既存セッションと文書・タスクデータは変更しない。端末名・一覧・個別端末の信頼登録、refresh token rotationは別設計とし、今回は既存セッション管理から失効する。
|
||||
|
||||
- [x] 共通ナビの◐からプリセットを選択、リロードせず切替。host限定Cookieに保持し、Domain既定に戻せる。登録済みテーマのみ許可。Domain設定/アカウントの全端末設定ではなくブラウザ上書き。失敗時は現在テーマを保持する。
|
||||
- [x] 絶対セッション期限:設定→セッション、5〜43200分、既定1440分。Domain単位で新規ブラウザ/APIログイン(OIDC/LDAPを含む)に適用。発行時にDBの期限を固定し、Cookie/APIのexpires_inにも反映。既存セッションの期限とCalDAVアプリパスワードは変更しない。管理者認可とサーバ側失効をfixture検証。
|
||||
- [ ] 無操作タイムアウトとアカウント別の短縮上書き:background pollingを人間の操作とみなさないactivity契約、再認証、既存セッションへの即時適用を別途設計する。
|
||||
|
||||
@@ -26,6 +26,14 @@ v0.3.0のOIDCログインは利用者の動作確認済み。v0.4.0ではOIDC承
|
||||
|
||||
## 利用方法
|
||||
|
||||
### 信頼できる端末でのログイン継続
|
||||
|
||||
2026-11-08ローカル実装、未リリース。独立CLIと対応サーバーを更新すると、`pages login --remember` または `pages login --oidc --no-browser --remember` で最長30日のセッションを要求できる。管理者の `auth_trusted_session_days`(既定30、0で無効)に従い、応答の `expires_in` を期限として保存する。旧サーバーでは通常の期限になる場合がある。
|
||||
|
||||
パスワードログインは必要なTOTPを維持する。選択はTOTP challenge/OIDC grantへ固定し、認証完了時の追加パラメーターで変更できない。CLI grantはmanaged component `cli-auth` v2で `remember` 列を追加し、既存行をfalseとして保持する。承認済みgrantの交換とセッション発行は従来どおり単一トランザクションで処理し、期限は承認元ブラウザの期限を超えない。
|
||||
|
||||
ローカル期限切れ後は `logout` を挟まず再ログインできる。同一アカウントならcwdと未送信タスク下書きを保持し、認証失敗時は従来のローカル状態を変更しない。ログアウト・管理者による失効・アカウント停止は長期セッションにも適用する。共有端末では使用しない。
|
||||
|
||||
```sh
|
||||
# 初回設定。パスワードはlogin時の非表示プロンプト、必要ならTOTPを続けて入力。
|
||||
pages configure --origin https://pages.example.test --username anya
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
- 見直し:見直す日を迎えたもの、または30日間変更されていない未完了タスク。
|
||||
- プロジェクト:名前とメモ、関連Wiki、所属タスクの一覧。タスクは一つのプロジェクトへ所属、または未所属。
|
||||
- タスク:件名、プレーンテキストのメモ、状態、優先度、分単位の見積もり、期限、取り組む日、見直す日、関連Wiki。
|
||||
- 完了/再開、アーカイブ/復元。完了取消でも過去の版は残る。初版は物理削除を提供しない。
|
||||
- 完了/再開、アーカイブ/復元。完了取消でも過去の版は残る。タスクの削除はアーカイブとは別の操作(下記)。
|
||||
- タイトル絞り込みとカーソルページング、変更履歴の版番号・日時表示。
|
||||
- 日本語/英語、既存テーマ、デスクトップの左ナビとモバイルの横ナビ・全画面編集モーダル。
|
||||
|
||||
@@ -34,6 +34,39 @@
|
||||
|
||||
一覧GETは `kind=task|project`、`view`、`project`、`q`、`limit`、`before` を受け付けます。既定60件、上限100件。作成はPOST、更新はPUT、`If-Match: "{version}"` 必須。ヘッダーなしは428、古い版は412。UUIDをクライアントで生成し、同内容の作成再送は同じ版を返します。異内容の再送は競合です。成功時は `item` と現在読める `page_path`、ETagを返します。一覧はメモ本文を省略するため、編集やクイック完了前に必ず詳細を取得します。
|
||||
|
||||
## タスクの削除
|
||||
|
||||
2026-11-08、v0.14.0で本番反映済み。[配備記録](../../operations/releases/2026-11-08-task-deletion.md)。
|
||||
|
||||
UUID検索は追加せず、既存のタスク編集画面で「アーカイブ/復元」の隣に「削除」を置きます。未保存の新規タスク、readonly、プロジェクト編集には表示しません。件名と削除範囲を確認してから実行し、削除失敗時は編集内容を保持します。アーカイブ済みタスクも同じ操作で削除できます。
|
||||
|
||||
- `DELETE /_/api/v1/extension/organizer.tasks/items/{uuid}`。PUTと同じ厳密な `If-Match: "{version}"` を要求し、成功204、未指定428、古い版412。成功応答を失った場合、同じ所有者・同じ削除前の版で再送できます。
|
||||
- 所有者・Domain・active状態・システム拡張の有効状態を同一writer transactionで再検査。他人の対象/削除記録は404。プロジェクトの削除は提供しません。
|
||||
- サブタスクがあれば409 `has_children`(アーカイブ済みも対象)。先に移動または削除します。実行中/一時停止中の集中セッション、実行中の作業記録があれば409 `working`。再帰削除・自動停止はしません。
|
||||
- head・版参照・期限通知予約・達成度メトリクスを削除し、カレンダー時間枠との関連は解除します。Wiki本文、カレンダーの予定、記録済みの作業時間は独立した記録として残します。削除タスクは通常/アーカイブ一覧・詳細・変更履歴から取得できず、復元操作もありません。
|
||||
- `organizer_task_deletions` にDomain、所有者、UUID、collectionで修飾したDAV名/UID、削除版、削除時刻だけを保持します。件名・本文は複写しません。DBとDocument Storeを一緒に保全する既存方針は変わりません。CASファイルや既存バックアップの安全消去を意味せず、保持期間・GCは別課題です。
|
||||
- 削除記録・head除去・関連索引の更新・変更ジャーナル/共通outboxは原子的にコミット。履歴移行ジョブは削除記録から種類を解決し、head欠落で停止しません。
|
||||
- DAVの一覧/REPORTから対象を除き、GETは404、multigetは対象ごとに404。旧ETagでのPUTは412。同じcollectionの同じUIDまたはhrefを使う新規/無条件PUTは既存の `no-uid-conflict` で拒否し、古い端末からの復活を防ぎます。削除済みUUIDへのJSON再作成は410。同名の件名を持つ**新しいUUID/DAV UID・href**のタスクは作成できます。DAV識別子の予約は索引再構築後も保持します。
|
||||
- 従来の「DAV DELETEをアーカイブへ変換する」互換動作は変更しません。今回追加した不可逆操作はWeb/APIからの明示的な削除です。クライアント固有の同期/競合UIの挙動まで保証するものではありません。
|
||||
|
||||
`internal/server/task_delete_test.go` で条件付き削除・権限・再送・DBロールバック・通知取消・作業履歴保全・DAV索引再構築/再送拒否を検証します。既存のChromiumテストに、削除ボタンの位置、確認キャンセル、版競合、成功後の一覧更新を追加しています。本番データの削除は実施しません。
|
||||
|
||||
### 削除済みメール取り込みの再作成
|
||||
|
||||
PagesWiki v0.14.1/pages-cli v0.4.2で実装、2026-11-08 19:42 JSTに本番反映済み。[配備記録](../../operations/releases/2026-11-08-task-capture-recovery.md)。サーバーとCLIの両方の更新が必要です。DBスキーマ変更や既存データの削除はありません。
|
||||
|
||||
`POST /_/api/v1/extension/organizer.tasks/capture` は、受付記録に対応するタスクの状態を本文ハッシュより先に確認します。削除済みなら同じ内容・異なる内容とも410 `deleted`。タスクと削除記録が両方欠落していれば409 `capture_missing` とし、自動修復・再作成はしません。存続中のタスクへの異内容再送は従来どおり412です。
|
||||
|
||||
削除済み要求の保留下書きは `pages task retry REQUEST_UUID --recreate-deleted` で明示的に再取り込みできます。CLIは新しい要求を送る前に保存し、以降の再送用IDを表示します。通信失敗後は表示された新IDで通常の `task retry NEW_REQUEST_UUID` を使います。メール本文・Wiki suffixは保持し、以前のタスクの状態・作業時間・子タスクを復元する操作ではありません。
|
||||
|
||||
- APIには `replaces_deleted` に元のrequest UUIDを渡します。新しい `request_id` はURL名前空間のUUIDv5で、名前は `pages:task-recreate:` と元のrequest UUIDを連結したもの。任意の後継IDを拒否し、同じ再取り込みの二重作成を防ぎます。
|
||||
- 同じDomain・所有者の受付記録と削除記録を要求し、元タスクが存続中なら412、他人の受付記録や不存在の要求は404。writer transaction内でも検査します。受付記録のない直接作成タスクには使えません。
|
||||
- 新しいタスク・受付記録・変更履歴・通知予約を原子的に保存します。旧受付記録、削除記録、DAV識別子の予約は残し、旧端末の再送による復活を防ぎます。
|
||||
- Wiki保存先にページが残っていれば、そのUUIDを新しいタスクに関連付けます。本文・リビジョンは上書きしません。存在しなければ保留本文から作成します。read/create/writeの現在権限と入力上限を検査し、ファイルなどページ以外との衝突は409です。保存先は保留要求と現在の既定値から解決するため、移動済みのWikiや既定Path変更を追跡して復元する機能ではありません。
|
||||
- 再作成済み要求の再送は同じ新タスクを返します。そのタスクも削除済みなら410で停止し、さらに復活させません。元のメールを再入力しただけでは削除済み状態を解除しません。
|
||||
|
||||
`internal/server/task_capture_recreate_test.go` でライフサイクル・並行再送・所有者境界・ロールバック・Wiki保持を検証し、CLIの単体テストとHTTP結合テストでも再送IDの保持を検証します。
|
||||
|
||||
## 保存と復旧の境界
|
||||
|
||||
`organizer_items` はDomain・所有者・UUID・種類・検索用メタデータ・現在版を保持します。本文を含む型付きJSONは既存Document StoreへSHA-256で保存し、同じJSONをDBにも保持します。`organizer_revisions` は版からDocumentへの参照、`organizer_changes` は後続処理用の小さな変更ジャーナルです。head更新・履歴・変更ジャーナルは同じSQLiteトランザクションです。
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
# Gecko連携の再配布条件
|
||||
|
||||
PagesWiki v0.13.0ではGeckoエンジンの配布を保留しました。
|
||||
現在は固定版のエンジン、対応ソース、第三者NOTICE、日本語フォントを含む配布bundleを生成できます。
|
||||
実験機能`viewer.gecko`は既定無効のままです。relayイメージとbundleは別物で、
|
||||
起動時にbundle全体を検証してから資産を配信します。
|
||||
本書は今回追加した部品の配布判断と残件を整理するもので、プロジェクト全体の法務監査ではありません。
|
||||
|
||||
## 部品と適用条件
|
||||
|
||||
| 部品 | 固定する出典・版 | ライセンスと配布時の扱い |
|
||||
| --- | --- | --- |
|
||||
| PagesWiki連携・Go relay | このリポジトリのリリースcommit | 自作コード。上流の実装をコピーせずWispフレーム仕様に対応。GeckoのライセンスをWiki全体へ一律適用しない |
|
||||
| Go runtime / 標準ライブラリ | relayのビルドに使うGo 1.25系 | BSD-3-Clause。実ビルド環境のLICENSEを専用イメージ内`/licenses/Go.txt`へ収録 |
|
||||
| golang.org/x/net | v0.35.0、WebSocket実装 | BSD-3-Clause。モジュールのLICENSEを`/licenses/golang-x-net.txt`へ収録 |
|
||||
| Gecko / Mozillaの第三者コード | Firefox fork `2e1e835a5da5907e5ceef19aade58a7493f1e34d` | 主にMPL-2.0。ただし多数の個別licenseがあり、MPLだけの表示では不足。固定commitの総合noticeと該当sourceを扱う |
|
||||
| gecko.js wrapper / WASM追加コード | v0.0.1 `eadcb5fa828d7e8b54ae2df13b6b3208f6553944` | 後述のMPL追加commitを確認。固定配布物にはLICENSE一式がないため、tarをそのまま再公開しない |
|
||||
| Emscripten runtime / WasmFS | 6.0.1と上流のpatch | Emscripten本体はMITまたはUIUC/NCSA。libc等のruntime依存には別noticeがあるため、ツールチェーンの最上位LICENSEだけでは棚卸し完了としない |
|
||||
| zstddec | 0.2.0 | npm metadataは`MIT AND BSD-3-Clause`。JS wrapperと組み込まれたdecoderの両noticeを保持 |
|
||||
| Liberation fonts | 上記Firefox commit内のPDF.js standard_fonts | SIL OFL 1.1。著作権表示・OFL本文・Reserved Font Namesを保持 |
|
||||
| Rust standard libraryと依存crate | 1.95.0と`library/Cargo.lock` | RustのMIT/Apache-2.0と各crateの個別条件。lockに記載された全registry crateのsource・noticeを保持 |
|
||||
| Noto Sans CJK JP | Sans2.004、`523d033d6cb47f4a80c58a35753646f5c3608a78` | SIL OFL 1.1。未改変OTF、Adobeの埋込著作権表示、OFL本文を保持 |
|
||||
|
||||
relayのruntimeイメージは`FROM scratch`とし、Goバイナリとlicenseだけを含めます。
|
||||
Alpine/BusyBoxを新たに再配布する構成にはしません。`go list -deps`でrelayにリンクされる外部Go moduleは
|
||||
`golang.org/x/net v0.35.0`のみと確認しています。ビルド用イメージと配布用runtimeイメージは区別します。
|
||||
|
||||
## 固定版とMPL宣言の関係
|
||||
|
||||
上流v0.0.1のcommitにはルートLICENSEがなく、翌日の
|
||||
[`ac40f56c85060bd49dfc36ca60490f97dd270c50`](https://github.com/HeyPuter/firefox-wasm/commit/ac40f56c85060bd49dfc36ca60490f97dd270c50)
|
||||
でMPL-2.0のLICENSEが追加されています。
|
||||
[固定版からの比較](https://github.com/HeyPuter/firefox-wasm/compare/eadcb5fa828d7e8b54ae2df13b6b3208f6553944...ac40f56c85060bd49dfc36ca60490f97dd270c50)
|
||||
の変更はLICENSE、Makefile、README、chrome demoの2ファイルです。
|
||||
`gecko.js/js`、`gecko.js/src`、`gecko.js/lib`、`gecko.js/emsdk-patches`はこの間に変更されていません。
|
||||
この事実を追加コードのMPL宣言の根拠として記録しますが、生成された全バイナリの第三者noticeを代替するものではありません。
|
||||
|
||||
v0.0.1の[Makefile](https://github.com/HeyPuter/firefox-wasm/blob/eadcb5fa828d7e8b54ae2df13b6b3208f6553944/Makefile)
|
||||
はFirefox forkのcommit `2e1e835a5da5907e5ceef19aade58a7493f1e34d`とEmscripten 6.0.1を指定しています。
|
||||
後続Makefileの参照先変更を混ぜず、再現には固定版側を使います。
|
||||
|
||||
固定版の[GRE縮小スクリプト](https://github.com/HeyPuter/firefox-wasm/blob/eadcb5fa828d7e8b54ae2df13b6b3208f6553944/gecko.js/stage-gre-min.sh)
|
||||
は`chrome/toolkit/content/global/license.html`を明示的に除外し、LiberationのTTFをコピーします。
|
||||
そのため、配布tarの存在やSHA-256一致だけでnoticeの充足を判断しません。
|
||||
|
||||
Wispのwire protocolは独立実装しています。固定版エンジンは独自の`gecko.js/lib/wisp-net.js`を使います。
|
||||
pnpm-lockにある`@mercuryworkshop/wisp-js`はdemo側依存で、lockfileに記載があることだけを根拠に
|
||||
PagesWiki relayの依存物・ライセンスとは扱いません。
|
||||
|
||||
## エンジンを配布する場合に必要な作業
|
||||
|
||||
MPLはファイル単位の義務であり、別実装のWiki全体をMPLへ変更するという意味ではありません。
|
||||
一方、WASMやJavaScriptを閲覧者のブラウザへ送信することも配布として扱う必要があります。
|
||||
**「イメージへ入れず、外部mountから配信すれば再配布ではない」という整理はしません。**
|
||||
[Mozilla MPL FAQ Q8・Q10・Q11・Q16・Q17](https://www.mozilla.org/en-US/MPL/2.0/FAQ/)、
|
||||
[MPL 2.0本文の3章](https://www.mozilla.org/en-US/MPL/2.0/)。
|
||||
|
||||
エンジンの本番有効化・再公開前に次を完了します。
|
||||
|
||||
1. 実際の配布WASM/JS/埋め込みGREと、対応するsource・patch・依存版を照合する。
|
||||
2. Mozillaの固定commitの総合notice、MPL本文、Emscripten/runtime、zstddec、fontの各著作権・licenseを収録する。
|
||||
Mozillaの総合noticeはbuild条件による表示があるため、未処理のHTMLを置くだけで完了としない。
|
||||
3. 受領者がnoticeと対応sourceの取得先を閲覧できる画面/ファイルを用意する。
|
||||
ソースは固定commitで指し、PagesWiki側でエンジンを変更した場合は変更も含める。
|
||||
4. 提供するsourceとnoticeの可用性・保全、配布物とのhash対応を検査する。
|
||||
5. Mozillaの商標はコードlicenseとは別に扱い、Firefoxの公式配布であるとの表現やロゴの流用をしない。
|
||||
|
||||
### 配布bundle
|
||||
|
||||
`tools/gecko/sources.lock.json`に取得元とSHA-256を固定し、`tools/gecko/bundle.py`で組み立てます。
|
||||
生成物は98ファイル、合計1,196,102,561 bytes(manifest自身を除く)です。
|
||||
manifestのSHA-256は`84953114f5e393dd97d9f948a5bc51c95b9355b58461dd3355e068a96cb2e381`。
|
||||
同じ値をrelay側で固定し、列挙された全ファイルのサイズ・hash・通常ファイルであることを起動時に検査します。
|
||||
不足、改変、symlink、別版混入を許可しません。
|
||||
|
||||
元のsource archiveを変更せず保存し、license/copying/copyright/notice/authorsファイルを別の閲覧用テキストにも集約します。
|
||||
Mozillaの条件付きnoticeは**全分岐を含む保守的な上位集合**としてテキスト化し、元のHTMLはsource archiveに保持します。
|
||||
Rustの追加依存はCargo.lockのチェックサムで検証します。crateから欠けていたFortanixのMPLヘッダと
|
||||
vex-sdkのMIT本文も、元ソース・固定commitから補完しています。
|
||||
Notoの未改変フォントには`© 2014-2021 Adobe (http://www.adobe.com/).`が埋め込まれ、READMEにも保持します。
|
||||
|
||||
閲覧画面のⓘは`/_/api/v1/extension/organizer.feeds/browser/distribution/v0.0.1/index.html`を開きます。
|
||||
同じ入口からNOTICE、manifest、ソース一式を取得できます。認証は必要ですが、RSS・Geckoを無効化した後も、
|
||||
認証済みの受領者はソースを取得できます。readonly利用者も取得可能です。
|
||||
relay自体を撤去する場合は、先にbundleと取得先を保全・移設してください。無効化はソース提供の撤回を意味しません。
|
||||
|
||||
CIは中継バイナリの4番目のイメージを配布しますが、約1.2GBのbundleを通常イメージへ重複同梱しません。
|
||||
検証済みbundleをread-onlyでmountする運用です。再配布条件の充足はこの固定版・未改変バイナリ・
|
||||
保持したsource/noticeを前提とします。依存更新時はlockとnoticeを再確認し、公開済みbundleを上書きしません。
|
||||
|
||||
## 一次資料
|
||||
|
||||
- [Gecko forkのLICENSEと商標注意](https://github.com/MercuryWorkshop/firefox/blob/2e1e835a5da5907e5ceef19aade58a7493f1e34d/LICENSE)
|
||||
- [同commitのMozilla総合notice](https://github.com/MercuryWorkshop/firefox/blob/2e1e835a5da5907e5ceef19aade58a7493f1e34d/toolkit/content/license.html)
|
||||
- [Liberationの著作権とOFL](https://github.com/MercuryWorkshop/firefox/blob/2e1e835a5da5907e5ceef19aade58a7493f1e34d/toolkit/components/pdfjs/content/web/standard_fonts/LICENSE_LIBERATION)
|
||||
- [Emscripten 6.0.1 LICENSE](https://github.com/emscripten-core/emscripten/blob/6.0.1/LICENSE)
|
||||
- [zstddec 0.2.0 metadata](https://registry.npmjs.org/zstddec/0.2.0)
|
||||
- [Go LICENSE](https://go.dev/LICENSE)
|
||||
- [golang.org/x/net v0.35.0 LICENSE](https://go.googlesource.com/net/+/refs/tags/v0.35.0/LICENSE)
|
||||
- [Noto CJK固定版OFL](https://github.com/notofonts/noto-cjk/blob/523d033d6cb47f4a80c58a35753646f5c3608a78/LICENSE)
|
||||
- [vex-sdk固定版MIT](https://github.com/vexide/vex-sdk/blob/6c0b83d35b6fc31a7607efe456e387df45476314/LICENSE.md)
|
||||
@@ -0,0 +1,175 @@
|
||||
# RSS Gecko中継の試験導入
|
||||
|
||||
RSS本文上で原文を読むための、端末側Gecko WASMと自前Wisp中継の実験機能です。
|
||||
通常の新規タブ・iframe表示は変更しません。DBスキーマ変更はありません。
|
||||
本番への自動導入・自動有効化は行いません。
|
||||
|
||||
## 構成と有効化条件
|
||||
|
||||
PagesWikiのログイン済み・activeな利用者だけが、
|
||||
`/_/api/v1/extension/organizer.feeds/browser/`以下を使います。
|
||||
同じDomainで`organizer.feeds`と`viewer.gecko`の両方が有効で、
|
||||
本体に中継URLと共有鍵ファイルが設定されていることが必要です。
|
||||
`viewer.gecko`はmanifestで既定無効です。個人設定の「RSSの記事リンクの開き方」で
|
||||
Geckoを選ぶと、RSS画面だけにCOOP/COEPを追加します。選択済みでも管理者が無効化した場合は新規タブへ戻ります。
|
||||
|
||||
ブラウザには中継の鍵を渡しません。本体が認証後に30秒の署名付きgrantを発行して内部HTTP要求へ追加します。
|
||||
WebSocketではOriginも検査し、grantは一回限りです。既存接続の認証・利用者状態・拡張の有効状態は5秒間隔で再検査します。
|
||||
中継はCookie、WikiのBearer token、FreshRSSの資格情報を受け取りません。
|
||||
|
||||
## 固定するエンジン
|
||||
|
||||
[HeyPuter/firefox-wasm v0.0.1](https://github.com/HeyPuter/firefox-wasm/releases/tag/v0.0.1)を使います。
|
||||
対応commitは`eadcb5fa828d7e8b54ae2df13b6b3208f6553944`です。
|
||||
|
||||
配布物`gecko.js-v0.0.1.tar.gz`のSHA-256:
|
||||
|
||||
```text
|
||||
bac28056a00ef6e5fb4345117e73d3629e75aca00dac71389fabbce39c018a73
|
||||
```
|
||||
|
||||
エンジン単体の`dist/`ではなく、後述するsource/notice付きbundleをread-onlyで`/gecko`へmountします。
|
||||
起動時に次の両ファイルに加え、manifestに列挙された全ソース・NOTICE・フォントをhash検査し、
|
||||
欠損・改変・異なる版の混在があれば中継は起動しません。
|
||||
|
||||
| ファイル | SHA-256 |
|
||||
| --- | --- |
|
||||
| gecko.js | e5aeebffd21106eccf23b1219316221add5e95085bc5a1bfb941117cfcd75ef7 |
|
||||
| gecko.wasm.zst | ebd6c75179152624d9644865e11792ed25cadc714d9e0985f412baf9c637a086 |
|
||||
|
||||
資産URLにも`assets/v0.0.1/`を含め、版をまたいだJS/WASMのcache混在を避けます。
|
||||
初回にはJS・圧縮WASM・日本語フォントの合計54,643,095 bytes(約52.1MiB)の転送とWASMの展開・compileが必要です。
|
||||
約1.2GBの対応ソースは閲覧の起動時には取得せず、ⓘから明示的にダウンロードするときだけ配信します。
|
||||
本体のDocker buildにFirefoxのソースビルドを加えません。
|
||||
|
||||
`Dockerfile.gecko-relay`は自前の中継バイナリだけを含みます。エンジンは同梱・再配布しません。
|
||||
**エンジンをイメージへ同梱する場合だけでなく、mountした資産を利用者へ配信する前にもnoticeと対応sourceの提供が必要です。**
|
||||
固定版のMPL宣言、第三者依存物、今回の配布範囲は[再配布条件](gecko-redistribution.md)を参照してください。
|
||||
v0.13.0の本番配備ではエンジンを配信していません。新しいrelayは完成したbundleを必須とします。
|
||||
|
||||
### bundle生成
|
||||
|
||||
Python 3.11以降を使い、十分な空き容量のあるディスク上で実行します。ソースarchiveは展開せず保持します。
|
||||
|
||||
```sh
|
||||
python tools/gecko/bundle.py --cache /srv/gecko-cache --output /srv/gecko/v0.0.1-bundle1
|
||||
# 同一入力からの再生成。出力先はまだ存在しない新しいディレクトリを指定する。
|
||||
python tools/gecko/bundle.py --cache /srv/gecko-cache --output /srv/gecko/rebuilt --offline
|
||||
```
|
||||
|
||||
出力manifestのSHA-256が`84953114f5e393dd97d9f948a5bc51c95b9355b58461dd3355e068a96cb2e381`と一致することを確認します。
|
||||
稼働中のmount先を上書きせず、source/noticeの提供を含めて不変の単位で保全します。
|
||||
|
||||
## 配置
|
||||
|
||||
任意の追加ファイル`docker-compose.gecko.yml`を通常のCompose定義に重ねます。
|
||||
このoverlayは`app`だけへ接続設定を追加し、`app2`は自動変更しません。
|
||||
|
||||
必要な環境変数:
|
||||
|
||||
| 変数 | 内容 |
|
||||
| --- | --- |
|
||||
| PAGESWIKI_GECKO_KEY_PATH | 32文字以上の十分ランダムな共有鍵のファイル絶対Path。appとrelayへ同じread-only mount |
|
||||
| PAGESWIKI_GECKO_ASSETS_DIR | 全ファイルを検証したbundleの絶対Path。engineだけのdistは禁止 |
|
||||
| PAGESWIKI_GECKO_IMAGE | Giteaで配布した`pageswiki-gecko-relay:sha-...`またはrelease tag。省略時は開発用image |
|
||||
| PAGESWIKI_GECKO_FRONT_SUBNET | 内部接続網。既定`172.24.0.0/27`。既存LANとの重複を避ける |
|
||||
| PAGESWIKI_GECKO_EGRESS_SUBNET | 中継の外向き網。既定`172.24.0.32/27` |
|
||||
|
||||
鍵はイメージ、Git、コマンド引数、ログへ含めません。relayはUID/GID `10001:10001`で動きます。
|
||||
mount元ファイルをこのUIDまたはGIDで読み取り可能にし、他の利用者から読めない権限にしてください。
|
||||
本体の`PAGESWIKI_GECKO_RELAY`は内部の固定URL、`PAGESWIKI_GECKO_KEY_FILE`はmount先です。
|
||||
これらは初回参照時に読み込むため、変更・鍵ローテーション時は本体とrelayを再起動します。
|
||||
|
||||
設定確認・試験起動の例:
|
||||
|
||||
```sh
|
||||
docker compose -f docker-compose.yml -f docker-compose.gecko.yml config --quiet
|
||||
docker compose -f docker-compose.yml -f docker-compose.gecko.yml build gecko-relay
|
||||
docker compose -f docker-compose.yml -f docker-compose.gecko.yml up -d gecko-relay app
|
||||
```
|
||||
|
||||
本体も今回の実装を含むイメージに更新する必要があります。既存のregistry/deploy用overrideがある場合は
|
||||
それも指定し、意図せず旧イメージや開発ビルドを本番へ適用しないでください。
|
||||
|
||||
### 外向き通信の制限
|
||||
|
||||
relayは公開ポートを持たず、通常のWikiネットワークやDBデータをmountしません。
|
||||
ただしDocker bridgeの分離だけでは外向き通信を制限できません。試験導入前にホストまたは外部firewallで、
|
||||
relayのegressから管理網・社内網・metadata・Wiki/DBホストへの到達を拒否し、公開TCP 80/443と管理されたDNSだけを許可します。
|
||||
rootless Dockerとrootful Dockerでは適用点が異なるため、ホスト固有のiptablesをこのoverlayから自動変更しません。
|
||||
|
||||
アプリケーション側でもIPv4/IPv6のprivate、loopback、link-local、特殊用途アドレスを拒否します。
|
||||
名前解決で返された全アドレスを検証してから、そのIPを直接dialします。検証後の再名前解決はしません。
|
||||
UDP、80/443以外のTCP、単一ラベルのホスト名は拒否します。
|
||||
これはWisp v1フレームを用いた**制限付きTCP profile**であり、Wispの全機能互換サーバーではありません。
|
||||
|
||||
## 上限と監視
|
||||
|
||||
| 対象 | 上限 |
|
||||
| --- | --- |
|
||||
| 同時セッション | Domain+本人ごとに1、サービス全体4 |
|
||||
| 同時TCP stream | セッションごと16 |
|
||||
| 接続試行 | セッションごと256 |
|
||||
| 合計転送量 | セッションごと送受信合計256MiB |
|
||||
| 帯域 | セッションごと送受信合計2MiB/s、初期burst 2MiB |
|
||||
| セッション期限 | 15分 |
|
||||
| WebSocket受信idle | 90秒 |
|
||||
| 宛先接続 | 名前解決込み8秒、個別dial 2秒 |
|
||||
| relayコンテナ | 256MiB、0.5 CPU、64 PIDs、read-only、capabilitiesなし |
|
||||
| 閲覧プロファイル | 日本語フォントを含むvolatileな32MiB・2,048 entries、端末のOPFSへ永続化しない |
|
||||
| source/noticeダウンロード | 全体2接続まで。ETag・Range対応。閲覧streamの枠とは分離 |
|
||||
|
||||
relayの稼働状態・接続数・送受信bytes・拒否数は、コンテナ内の次の操作でJSON取得できます。
|
||||
鍵はファイルから読み、標準出力には含めません。counterは再起動でリセットします。
|
||||
|
||||
```sh
|
||||
docker compose -f docker-compose.yml -f docker-compose.gecko.yml exec gecko-relay gecko-relay --status
|
||||
```
|
||||
|
||||
`/health`は内容なしの死活確認、`/status`は署名付き内部要求だけに応答します。
|
||||
CPU・メモリはコンテナ監視を使います。設定画面の資源グラフへの統合は未完了です。
|
||||
記事URL、本文、プロファイル内容、資格情報はrelayログに記録しません。
|
||||
|
||||
## 無効化と切り戻し
|
||||
|
||||
管理画面の拡張一覧で`viewer.gecko`を無効化できます。UIが使えない場合は、対象Domainを選択した
|
||||
ローカル`data/pageswiki-cli`で次を実行します。
|
||||
|
||||
```text
|
||||
extension viewer.gecko off
|
||||
```
|
||||
|
||||
既存WebSocketは次の認証再検査時に終了します。新たな閲覧も拒否し、RSSの原文リンクは新規タブへ戻ります。
|
||||
緊急時はrelayコンテナを停止します。DB移行の巻き戻しは不要です。
|
||||
|
||||
## 受入と制約
|
||||
|
||||
自動テストでは外部アクセスしない合成Wisp応答を使い、実際のGecko WASMで描画、canvasクリックによる遷移、
|
||||
ビューア内の「戻る」、iframe削除後の接続終了を確認します。実FreshRSS、外部カレンダー、メール本文は使いません。
|
||||
専用イメージのbuildと、`--network none`・非root・read-only・資源制限付きの一時コンテナで、
|
||||
固定資産の起動時検査と`--status`も確認済みです。本番の中継・ネットワーク設定は変更していません。
|
||||
|
||||
```sh
|
||||
go test -race ./internal/geckorelay ./internal/server -run 'TestGrant|TestDestinations|TestRelay|TestAssets|TestFeedGeckoAuthorization|TestFeedGeckoWebsocket'
|
||||
PAGESWIKI_BROWSER_TEST=1 PAGESWIKI_GECKO_TEST_ASSETS=/verified/bundle go test ./internal/server -run '^TestFeedGeckoChromium$' -count=1
|
||||
PAGESWIKI_GECKO_TEST_BUNDLE=/verified/bundle go test ./internal/geckorelay -run TestDistribution
|
||||
# 公開テストサイトへの実通信。実RSS・外部カレンダー・メールは使用しない。
|
||||
PAGESWIKI_BROWSER_TEST=1 PAGESWIKI_GECKO_TEST_ASSETS=/verified/bundle PAGESWIKI_GECKO_PUBLIC_HTTPS_TEST=1 go test ./internal/server -run '^TestFeedGeckoChromium$' -count=1
|
||||
node internal/server/testdata/feed-gecko-profile.mjs
|
||||
```
|
||||
|
||||
原文クリック時にだけ起動し、閉じるとiframe・worker・接続を破棄します。タブを60秒非表示にした場合も閉じます。
|
||||
再表示では静的資産のHTTP cacheを使えますが、エンジンは再起動します。
|
||||
戻る/進むは最大64件のURLを再読み込みする方式です。上流の最小GREにはSessionStoreFunctionsがなく、
|
||||
標準のhistory.back()が失敗するため、フォーム内容やスクロール位置を復元する履歴ではありません。
|
||||
画面のcanvasは最大1920×1080、experimental WASM JITとGPUは無効です。
|
||||
|
||||
HTTPSの実描画と期限切れ証明書の拒否を確認しました。上流最小GREはエラーページの部品が不足するため、
|
||||
`about:neterror`/`about:certerror`を検知してcanvasを隠し、PagesWiki側で説明します。証明書の無視・例外追加は提供しません。
|
||||
Noto CJKをメモリプロファイルのfontsに置き、エンジンを改変せず日本語描画も確認しています。
|
||||
|
||||
検索アイコンまたはCtrl/Cmd+Fからページ内検索できます。検索語は256文字まで、前後検索と一致なしの表示に対応し、合成記事で日本語検索を確認しています。起動失敗または120秒の起動上限到達時はiframeを破棄し、元記事を別タブで開く導線を残します。上流のdestroy呼出しだけではWASM資源の解放にならないため、親側のiframe破棄まで行います。`TestFeedGeckoStartupFailureChromium` はフォント取得失敗時の破棄と代替導線を検証します。
|
||||
|
||||
本番の標準機能に昇格する前に、Safari/iPhone SE、IME、コピー、実サイト互換性、
|
||||
複数タブ・低メモリ端末の測定、コンテナ外向きfirewallを検証します。
|
||||
外部ページのiframe拒否とは別の仕組みですが、すべてのサイトでの動作や軽さを保証するものではありません。
|
||||
@@ -11,6 +11,9 @@ runner の環境構築や Gitea の事前疎通診断は行わず、本番へ自
|
||||
| `pageswiki-app`(app / app2 共通) | `Dockerfile` |
|
||||
| `pageswiki-adaptor-gateway` | `Dockerfile.adapter-gateway` |
|
||||
| `pageswiki-excalidraw-viewer` | `Dockerfile.excalidraw-viewer` |
|
||||
| `pageswiki-gecko-relay`(任意) | `Dockerfile.gecko-relay` |
|
||||
|
||||
v0.15.0以降はGecko relayを含む4イメージをビルド・昇格します。以下の「3イメージ」は通常配備するapp・gateway・Excalidrawの組を指します。Gecko relayは別overlayで明示的に配備するもので、通常の本番更新では起動しません。
|
||||
|
||||
Kroki、Mermaid、code-server は upstream の配布イメージを使用する。
|
||||
`main` / `mk_district` への push、手動実行でビルド・公開する。
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# RSSフォルダと取り込み操作のリリース
|
||||
|
||||
## 対象
|
||||
|
||||
v0.12.0は`f4869c7c8bd2fd48523eec2e1868d3d0750bbdf7`。
|
||||
2026-11-08 14:55 JSTに本番検証を完了し、注釈付きGitタグとイメージを公開した。
|
||||
既存v0.11.0タグは移動していない。
|
||||
独立pages-cliと未コミットのメール保存先調査は含めない。
|
||||
|
||||
- [ビルドCI run 64](https://git.anya.jp/anya/pages/actions/runs/64): success。
|
||||
- [リリースCI run 65](https://git.anya.jp/anya/pages/actions/runs/65): success。
|
||||
- [Gitea Release v0.12.0](https://git.anya.jp/anya/pages/releases/tag/v0.12.0)。
|
||||
|
||||
本番`.env.release`は同コミットの`sha-`タグに固定している。
|
||||
`v0.12.0`は再ビルドせず同一manifestを昇格し、3イメージすべてのdigestとrevisionを照合済み。
|
||||
|
||||
## 変更
|
||||
|
||||
- FreshRSSの分類フォルダ・購読元をツリー表示し、空フォルダ・未分類・開閉状態保存に対応。
|
||||
- 記事・購読元・分類を背景で原子的に更新し、一部失敗時は前回cacheを保持。
|
||||
- 既読・star書戻しの操作履歴、結果不明の再確認、JSON記録保存。
|
||||
- ショートカットヘルプを`?`・`Esc`・閉じるボタンで閉じ、元の記事とstatus表示を保持。
|
||||
- Wiki・タスク追加を本文上のdialogへ整理し、個人設定のWiki親Pathを初期表示。
|
||||
- `{YYYY}`・`{MM}`・`{DD}`・`{Subject}`を親Pathで使用可能。日付はドメインのタイムゾーン。
|
||||
- 件名を安全な単一Path要素へ整形し、保存先プレビューと公開範囲確認を表示。
|
||||
- `sharing.x`の有効・無効に従うRSS記事のX共有。件名と原文URLを別タブのintentへ渡す。
|
||||
- 個人設定からRSS原文・本文リンクを別タブまたは大きなiframeプレビューで開く方式を選択。
|
||||
|
||||
個人設定は`/-/sys/config?panel=organizer`。Wiki親Pathはメール取り込みと共通。
|
||||
リンクの開き方は既定で別タブとし、設定変更はRSS画面の再読込後に反映する。
|
||||
iframeはsandbox付きで、外部サイトの埋め込み禁止は回避しない。表示できない場合は別タブへ開く。
|
||||
本番利用者の既定値やFreshRSS書戻し許可を自動変更しない。
|
||||
詳細は[RSS設計](../../design/ja/feeds.md)を参照。
|
||||
|
||||
## 移行と保全
|
||||
|
||||
今回の本番schema差分はfeeds v5→v6。`feed_sources.remote_folders`の列追加であり、
|
||||
既存記事・購読設定・送信待ちreceipt・source versionを変更しない。
|
||||
Wiki親Pathとリンク表示モードは既存preferences JSONを使うため追加DDLはない。
|
||||
旧版がv6を理解するとは仮定せず、単なる旧イメージへの切戻しを自動実行しない。
|
||||
|
||||
保全先は`.deployment-backups/release-rss-folders-20261108/`。
|
||||
旧構成を`config/`、停止時点のデータを`cutover/data`・`cutover/data2`に保存した。
|
||||
14:53:29 JSTに停止を開始し、14:54:38 JSTにchecksum付き同期・差分ゼロ・DBの一致を確認した。
|
||||
事前コピーだけでは整合バックアップと扱っていない。
|
||||
稼働元とはinodeを共有せず、既存の不変バックアップとのみ変更のないファイルを共有する。
|
||||
旧イメージは`rollback-before-rss-folders-20261108`タグで保全した。
|
||||
|
||||
## 検証
|
||||
|
||||
手元のGo全体テスト・go vet、RSS関連のrace検査、1440px/390pxのChromium試験を実施。
|
||||
分類の空・未分類・移動・同名ID、失敗時cache保持、schema v6のrollback・再実行を検査した。
|
||||
親Pathの日付境界・日本語件名・階層逸脱防止・不正トークン拒否を検査した。
|
||||
リンクプレビューは別originのローカルfixtureを実際に読み込み、sandboxと復帰を検査した。
|
||||
実FreshRSS・Xへの投稿・外部カレンダー・実メール本文を検証のために取得・操作していない。
|
||||
|
||||
停止済みの前回バックアップから独立コピーを作り、両DBの移行前integrity_checkはok。
|
||||
配備イメージをネットワーク遮断・workers無効で実際に起動し、両DBでfeeds v6への移行、
|
||||
ヘルス、管理対象13コンポーネントのschema check、移行後integrity_checkのokを確認した。
|
||||
schema check単体ではlegacy領域を網羅しないため、起動・SQLite検査と組み合わせた。
|
||||
|
||||
本番切替後は以下を確認した。
|
||||
|
||||
- app・app2・adaptor-gateway・excalidraw-viewerが対象revisionで稼働、restart countは0。
|
||||
- 両アプリの`/health`、schema checkが正常。feeds v6、task-productivity v4。
|
||||
- HTTPSの`/health`とログインは200、匿名のRSS・タスク・設定画面は303、RSS APIは401。
|
||||
- 配信中の`feeds.js`・`feeds.css`・`task-productivity.js`のSHA-256がリポジトリと一致。
|
||||
- 起動後ログのpanic・fatal・DB locked・event job failed・schema errorは各0件。
|
||||
|
||||
## 配布イメージのdigest
|
||||
|
||||
| イメージ(`git.anya.jp/anya/`、タグ`v0.12.0`) | manifest digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:46251f9b869e47d456def4d285c3f076e0d375f2a11d69121885fca08997e6a7` |
|
||||
| pageswiki-adaptor-gateway | `sha256:ee98889018f8389a655126c6a5d1046640be22cae169d97c4b27a7efa08f86c6` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:e7a577a8f178f625f6b13da93b046afda57c5c4c67e5e3b86cab0daf5c5f14ee` |
|
||||
@@ -0,0 +1,92 @@
|
||||
# PagesWiki v0.13.0
|
||||
|
||||
RSSフォルダのキーボード移動と、既定無効のGecko原文ビューア基盤を追加するminor releaseです。
|
||||
エンジン配布を含まない範囲でリリースします。通常のRSS表示・新規タブ・sandbox iframeは維持します。
|
||||
|
||||
## 変更
|
||||
|
||||
- Shift+j/kでFreshRSSの前後の分類フォルダを選択。検索条件、未読/star絞り込みを維持。
|
||||
- 認証付きの独立Wisp TCP relayと、Gecko用の本文上popup、個人設定を実装。
|
||||
- relayは公開TCP 80/443限定、DNS解決後の全IP検査、固定IPへの接続、接続数・帯域・通信量・期限の制限。
|
||||
- ログアウト・利用者状態・拡張無効化を既存WebSocketにも反映。
|
||||
- upstream v0.0.1をhash固定。閲覧プロファイルはメモリのみ、終了時はiframeを破棄。
|
||||
- 戻る/進むは最大64件のビューア内URL履歴を再読み込み。通常ブラウザのフォーム状態復元ではない。
|
||||
- 拡張manifestの既定無効をサーバーとローカルCLIへ反映。
|
||||
- 専用relayはscratch runtimeとし、実ビルドのGo・x/netのBSD licenseを収録。
|
||||
|
||||
## 再配布と本番の範囲
|
||||
|
||||
[再配布条件](../gecko-redistribution.md)にGecko、WASM用追加コード、Emscripten、zstddec、フォントを整理しました。
|
||||
GeckoのJS/WASM/フォントをGit、通常3イメージ、release assetへ同梱しません。
|
||||
relay Dockerfileと試験用Compose overlayは提供しますが、CIの配布イメージは従来の3種類です。
|
||||
|
||||
固定版生成物にはMozillaの総合noticeが含まれないため、エンジン配布用notice/source bundleは残件です。
|
||||
外部mountからのブラウザ配信も再配布として扱い、今回の本番では鍵・asset mount・relay起動・
|
||||
`viewer.gecko`の有効化を追加しません。
|
||||
通常のRSSフォルダショートカットは利用できます。
|
||||
|
||||
## 互換性と検証
|
||||
|
||||
DBスキーマ変更はありません。RSSリンクモード`gecko`は既存preferences JSONの追加値です。
|
||||
未構成・無効時は新規タブ表示に戻り、既存利用者の設定を自動変更しません。
|
||||
旧版でpreferencesを保存する際、新しい値が残っていれば`tab`または`embedded`へ戻す必要があります。
|
||||
|
||||
Go全体テスト、関連race検査、CLI、配布ツール、Chromiumでの1440/390px RSS回帰と実Geckoによる
|
||||
合成Wisp記事の描画・クリック遷移・戻る・終了を検証対象とします。実FreshRSS・外部カレンダー・メール本文は検証に使いません。
|
||||
Safari、IME/copy/find、実HTTPSの互換性と証明書エラー、低メモリ・長時間負荷、監視UI統合、
|
||||
本番の外向きfirewallは実験機能の昇格前の残件です。
|
||||
|
||||
構成・上限・切り戻しは[Gecko中継の試験導入](../gecko-relay.md)、機能の進捗は[RSS設計](../../design/ja/feeds.md)を参照してください。
|
||||
|
||||
## リリース・本番反映記録
|
||||
|
||||
対象commitは`5321d613b40db36238235ff68e256caa6d4e4cf1`。
|
||||
2026-11-08 16:31:51 JSTに本番の外部HTTPS検証を完了しました。
|
||||
|
||||
- [ビルドCI run 66](https://git.anya.jp/anya/pages/actions/runs/66): success。
|
||||
- [リリースCI run 67](https://git.anya.jp/anya/pages/actions/runs/67): success。
|
||||
- [Gitea Release v0.13.0](https://git.anya.jp/anya/pages/releases/tag/v0.13.0)。
|
||||
|
||||
注釈付きGitタグ`v0.13.0`と同名の3イメージを公開しました。
|
||||
SHAタグから再ビルドせず昇格し、両タグのmanifest digest一致を確認しています。
|
||||
本番`.env.release`は`PAGESWIKI_IMAGE_TAG=v0.13.0`です。
|
||||
app・app2・adaptor-gateway・excalidraw-viewerだけを切り替え、他サービスは変更していません。
|
||||
|
||||
### DBと復旧点
|
||||
|
||||
現在の両DBをSQLiteのオンラインバックアップで独立コピーし、`integrity_check`のokと、
|
||||
新イメージをネットワーク遮断・読み取り専用で実行した`schema check`の成功を確認しました。
|
||||
13管理コンポーネントはすべてcurrentで、feeds v6・task-productivity v4のままです。
|
||||
この検査はlegacy領域の全移行を網羅するものではありません。今回のschema追加はありません。
|
||||
|
||||
最初に選んだ前回切替前バックアップにはfeeds v5が残っていたため、現在のDBのコピーへ検査対象を変更しました。
|
||||
`/tmp`上の検査コピー作成はI/Oエラーで中断し、その一時コピーだけを除去して、
|
||||
空き容量のあるディスク上でコピー・整合性検査を完了しています。本番DBへの検査用書き込みはしていません。
|
||||
|
||||
復旧点は`.deployment-backups/release-v0.13.0-20261108/`です。
|
||||
`config/`に旧構成、`cutover/data`・`cutover/data2`に停止時点の全データを保存しました。
|
||||
16:29:32 JSTに停止を開始し、16:31:01 JSTにchecksum同期・再走査の差分ゼロ・DB一致を確認しました。
|
||||
稼働元とはinodeを共有せず、不変の旧バックアップとのみ未変更ファイルを共有しています。
|
||||
旧3イメージは`rollback-before-v0.13.0-20261108`タグで保持しています。
|
||||
旧版へ戻す場合も更新後の書き込みを失わないよう、データの自動巻き戻しは行いません。
|
||||
|
||||
### 配備後検証
|
||||
|
||||
- 4サービスのrevisionが対象commitと一致、再起動回数0。
|
||||
- app・app2の`/health`と管理スキーマ検査が正常。
|
||||
- 外部HTTPSでhealth・ログイン・カレンダーHTML枠は200、匿名のRSS・設定は303、RSS APIとGecko proxyは401。
|
||||
カレンダーHTML枠の200は既存の仕様で、実予定データの取得・閲覧は検証していません。
|
||||
- `feeds.js`・`task-productivity.js`・`feed-gecko.js`・`feed-gecko-profile.mjs`・`feed-gecko.css`の配信SHA-256がソースと一致。
|
||||
- 起動直後のpanic/fatal・database locked・event job failed・schema errorは各0件。
|
||||
- 本番へのGecko環境変数・asset mount追加なし、Gecko relayの起動なし。
|
||||
|
||||
手元ではGo全体テスト、go vet、関連race検査、CLI、配布ツール、ChromiumによるRSSと合成Gecko記事の試験を通しています。
|
||||
ライセンス同梱を含め専用scratch relayのビルド・起動・statusも確認しましたが、配布イメージへの追加や本番起動はしていません。
|
||||
|
||||
### 配布イメージ
|
||||
|
||||
| イメージ(`git.anya.jp/anya/`、タグ`v0.13.0`) | manifest digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:87e9a2761c136aff734761f296c9dbe34fc391ad5687eaf332d3c9ba15b03ab5` |
|
||||
| pageswiki-adaptor-gateway | `sha256:b82bb2184d21ea692b63fa2f9a70f15392474719e444e8d2b7618723cc80c7f1` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:2fff1ac0191e2fc7d8ad21aba365c82e0500f81d78da3672c030e77cb6a418af` |
|
||||
@@ -0,0 +1,77 @@
|
||||
# PagesWiki v0.14.1とpages-cli v0.4.2
|
||||
|
||||
削除済みタスクの受付記録が残り、変更した下書きの再送で412になっていた問題を修正します。
|
||||
削除済みなら410、受付記録に対応するタスクと削除記録が両方欠落していれば409 `capture_missing` で停止します。
|
||||
存続中のタスクを異内容のcaptureで上書きすることは許可しません。
|
||||
|
||||
2026-11-08 19:42:51 JSTに本番配備後の確認を完了しました。
|
||||
DBスキーマ変更・既存データの削除・実タスクの再取り込みは行っていません。
|
||||
Gecko等の未コミット変更は含みません。
|
||||
|
||||
## 再取り込み
|
||||
|
||||
サーバーをv0.14.1、利用するCLIをv0.4.2に更新してから実行します。
|
||||
別インスタンスへ接続している場合は、その接続先サーバーの更新も必要です。
|
||||
|
||||
```sh
|
||||
pages --version
|
||||
pages task retry REQUEST_UUID --recreate-deleted
|
||||
```
|
||||
|
||||
保持した下書きから、新UUIDのタスクを作成します。旧UUIDの削除記録とDAV識別子予約を残し、
|
||||
通常の再送で古いタスクが復活するのを防ぎます。再取り込み用IDは決定的で、応答消失や並行再送でも重複作成しません。
|
||||
既存Wikiが保存先にあれば本文・リビジョンは変更せず、新タスクから関連付けます。
|
||||
ページがなければ保留本文から作ります。移動済みページの自動探索や旧作業記録の復元ではありません。
|
||||
|
||||
通信失敗時はCLIが表示する新IDで `pages task retry NEW_REQUEST_UUID` を実行します。
|
||||
セッションファイルや受付記録を手動で消さないでください。
|
||||
詳細は[実装契約](../../design/ja/tasks-implementation.md#削除済みメール取り込みの再作成)と
|
||||
[CLIのNeoMutt手順](https://git.anya.jp/anya/pages-cli/src/tag/v0.4.2/docs/neomutt.md)を参照してください。
|
||||
|
||||
## リリースと検証
|
||||
|
||||
| 対象 | タグ | commit | CI |
|
||||
| --- | --- | --- | --- |
|
||||
| PagesWiki | [v0.14.1](https://git.anya.jp/anya/pages/releases/tag/v0.14.1) | `4049acf76e36c12b8f3c506de5eaf1e920ac7e86` | [build 72](https://git.anya.jp/anya/pages/actions/runs/72)、[release 75](https://git.anya.jp/anya/pages/actions/runs/75) success |
|
||||
| pages-cli | [v0.4.2](https://git.anya.jp/anya/pages-cli/releases/tag/v0.4.2) | `e27c023d66a61b73d3fe47e982daa6f34213c41f` | [build 73](https://git.anya.jp/anya/pages-cli/actions/runs/73)、[release 74](https://git.anya.jp/anya/pages-cli/actions/runs/74) success |
|
||||
|
||||
- 正確なリリースソースで `go test ./...`。server/storeのgo vet、削除・再取り込み・並行再送のrace検査が成功。
|
||||
- CLIの52単体テスト、サーバーとCLIのHTTP結合テストが成功。Wiki本文・版の保全、他所有者拒否、readonly、kill switch、入力上限、保存途中のロールバックを検証。
|
||||
- 公開されたCLIの4配布ファイルをSHA256SUMSで照合し、Pythonソースとcommitを照合。
|
||||
- 配布Linux ELFでバージョン、メール取り込み、下書き差し替え、削除済み再取り込み、認証・ファイル権限のスモークテストとTLS関連6テストが成功。
|
||||
- Linux ELFはglibc 2.36以降。macOS/Windowsの未検証バイナリは配布していません。
|
||||
|
||||
## 本番切り替えと復旧点
|
||||
|
||||
app・app2・adaptor-gateway・excalidraw-viewerを同じv0.14.1へ更新しました。
|
||||
`.env.release` の選択は `PAGESWIKI_IMAGE_TAG=v0.14.1` です。
|
||||
|
||||
- 19:40:36 JSTに停止開始。
|
||||
- 19:42:17 JSTに、停止時点のdata/data2についてchecksum同期、再走査の差分ゼロ、DBファイル一致を確認。
|
||||
- 19:42:23 JSTに新版の起動と両アプリのhealth応答を確認。
|
||||
- 設定と停止時データは `.deployment-backups/release-v0.14.1-20261108/` の `config/` と `cutover/data`、`cutover/data2` に保存。DBのinodeは稼働元と独立しています。
|
||||
- 旧3イメージを `rollback-before-v0.14.1-20261108` タグで保持。旧バックアップも残しています。
|
||||
|
||||
v0.14.0への切り戻しはイメージ選択のみで行い、DBを過去へ戻しません。
|
||||
その場合は再取り込みAPIが利用できなくなるため、CLIの再取り込み操作を止めてください。
|
||||
v0.14.0より前への切り戻しは削除記録の扱いが異なり、[v0.14.0の注意点](2026-11-08-task-deletion.md#dbと切り戻し)が引き続き適用されます。
|
||||
|
||||
## 配備後確認
|
||||
|
||||
- 4サービスのrevisionが対象commitと一致、running、再起動回数0。
|
||||
- app/app2のhealth正常。管理対象13スキーマはcurrent。これはlegacy領域を含む全移行検証ではありませんが、今回の変更にスキーマ移行はありません。
|
||||
- 両DBの `quick_check` はok。
|
||||
- 外部HTTPSのhealth・ログイン画面200。匿名のタスク/ダッシュボード/RSS画面303、タスクAPI401。匿名DELETEとcapture POSTも401。
|
||||
- tasks.js、tasks.css、organizer-dashboard.js、feeds.js、feed-gecko.jsのSHA-256がリリースcommitと一致。
|
||||
- 起動直後のfatal/panic、DB lock、schema/migration failure、event job failureは両アプリとも0件。
|
||||
- 実際のメール本文・利用者の保留下書きを使った再取り込みは実施していません。
|
||||
|
||||
## 配布イメージ
|
||||
|
||||
SHAタグから再ビルドせず昇格。本番で取得したdigestとCI結果は一致しています。
|
||||
|
||||
| イメージ(`git.anya.jp/anya/`、タグ`v0.14.1`) | manifest digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:11488fb958db12ec5a25aa265fc8179a31ab5728800f47605759822a44eb81e6` |
|
||||
| pageswiki-adaptor-gateway | `sha256:ca17704eb5e88a4e73827ff2a5fafda7c4bb7d9be3987b5a83a3a5ae0c780098` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:a2b692c3864b8c4f13412e746fcea7cd9a2c03d49e0d5ead252432f37930c4c4` |
|
||||
@@ -0,0 +1,70 @@
|
||||
# PagesWiki v0.14.0
|
||||
|
||||
タスク編集画面に、アーカイブと独立した削除操作を追加するminor releaseです。
|
||||
本日の達成率ウィジェットは説明文を除き、グラフと完了数/総数を表示します。
|
||||
Geckoの追加整備やRSSの追加ショートカットなど、並行作業中の変更は含めません。
|
||||
|
||||
## 変更と削除範囲
|
||||
|
||||
- タスク編集画面の「アーカイブ/復元」の隣に「削除」。確認後に実行し、アーカイブ済みタスクにも対応。
|
||||
- DELETE APIは所有者・Domain・active状態を検査し、If-Matchを要求。更新競合時は入力を保持。
|
||||
- サブタスクが残る場合や作業/集中セッションが実行中の場合は削除を拒否。
|
||||
- タスクhead、版参照、通知予約、達成度メトリクスを削除。カレンダー時間枠との関連は解除。
|
||||
- Wikiメモ、カレンダー予定、記録済みの作業時間は保持。CASファイル・既存バックアップの安全消去ではありません。
|
||||
- CalDAV一覧/REPORTから削除対象を除外。削除済みのUUIDとcollection内のDAV UID/hrefを予約し、古い端末からの再作成を拒否。
|
||||
- 従来のDAV DELETEをアーカイブへ変換する動作は維持。
|
||||
|
||||
詳細は[タスクの実装契約](../../design/ja/tasks-implementation.md#タスクの削除)を参照してください。
|
||||
|
||||
## DBと切り戻し
|
||||
|
||||
`organizer_task_deletions` を追加します。起動時の移行は既存タスクを削除せず、
|
||||
既存のタスクデータや版参照を変更しません。DAV索引再構築は削除記録の識別子予約にも対応します。
|
||||
|
||||
旧版は削除記録を認識しません。削除機能を使用した後の旧版への切り戻しでは、
|
||||
クライアントの再送で同じDAVタスクが作成されるおそれがあります。
|
||||
切り戻す場合は書き込み・DAV同期を停止してから判断し、DBを無断で過去へ戻さないでください。
|
||||
|
||||
## 検証と配備
|
||||
|
||||
対象commitは `38a4fcf5301e0c7c6cad12070e040dc62a03d41b`。
|
||||
2026-11-08 18:20:25 JSTに配備後の検証を完了しました。
|
||||
|
||||
- [ビルドCI run 68](https://git.anya.jp/anya/pages/actions/runs/68)、[リリースCI run 69](https://git.anya.jp/anya/pages/actions/runs/69)はともにsuccess。
|
||||
- [Gitea Release v0.14.0](https://git.anya.jp/anya/pages/releases/tag/v0.14.0)と注釈付きGitタグを公開。
|
||||
- リリース対象だけの独立ソースで `go test -p 1 ./...`、server/storeのgo vet、配布ツール等15テスト、PC・モバイル幅のChromium回帰試験が成功。
|
||||
- 両本番DBのオンラインバックアップを隔離し、`EnsureTasksSchema`を各2回実行。task head・版参照・DAV resource/collection識別子のdigestが移行前後で一致し、削除記録は0件、`integrity_check`はok。
|
||||
- app・app2・adaptor-gateway・excalidraw-viewerを同じv0.14.0へ更新。他サービス・Gecko設定・利用者設定は変更なし。
|
||||
|
||||
本番のタスク削除や外部カレンダー本文を用いた検証は行っていません。
|
||||
|
||||
### 復旧点
|
||||
|
||||
`.deployment-backups/release-v0.14.0-20261108/` の `config/` に旧構成、
|
||||
`cutover/data`・`cutover/data2`に停止時点のデータを保存しています。
|
||||
18:18:53 JSTに停止を開始、18:19:57 JSTにchecksum同期・再走査の差分ゼロ・DB一致を確認しました。
|
||||
稼働元とinodeを共有しません。旧バックアップは削除していません。
|
||||
旧3イメージは `rollback-before-v0.14.0-20261108` タグで保持しています。
|
||||
|
||||
`.env.release` は `PAGESWIKI_IMAGE_TAG=v0.14.0`。
|
||||
新版の4サービスは18:20:12〜18:20:18 JSTに起動しました。
|
||||
|
||||
### 配備後検証
|
||||
|
||||
- 4サービスのrevisionが対象commitと一致、running、再起動回数0。
|
||||
- app・app2のhealthと管理スキーマ検査が正常。legacy task領域は上記の隔離コピー移行試験で別途確認。
|
||||
- 両DBの `quick_check` がok、削除記録0件。
|
||||
- 外部HTTPSのhealth・ログイン画面200。匿名のタスク/ダッシュボード/RSS画面は303、タスクAPIは401。
|
||||
- 実在しないUUIDへの匿名DELETEを401で拒否。
|
||||
- tasks.js、tasks.css、organizer-dashboard.js、feeds.js、feed-gecko.jsの配信SHA-256がリリースcommitと一致。未完了Gecko変更の混入なし。
|
||||
- 起動直後のfatal/panic、DB lock、event job failed、schema/migration errorは両アプリとも各0件。
|
||||
|
||||
### 配布イメージ
|
||||
|
||||
SHAタグから再ビルドせず昇格し、本番ホストで取得したdigestとCIの昇格結果が一致しています。
|
||||
|
||||
| イメージ(`git.anya.jp/anya/`、タグ`v0.14.0`) | manifest digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:46edb2640bfda3be73d8bed354bb1e014b050d68b6c17af8036d65d7732378af` |
|
||||
| pageswiki-adaptor-gateway | `sha256:696f2d0bcdf1a3dce8821c061a78ad9f3d6fcaadda32cc1cb4e5d5a117028fc0` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:4d72abb4c1964553458af2b95e19722e18ae05fcfa2b02ff086407ad962ca62c` |
|
||||
@@ -0,0 +1,48 @@
|
||||
# PagesWiki v0.15.0とpages-cli v0.5.0
|
||||
|
||||
ブラウザアップロード、信頼端末ログイン、RSSの配信時刻、CSV投影とタスクの関連ページ導線を追加します。Geckoの整備コードと配布イメージも含みますが、専用relayの本番有効化は行いません。
|
||||
|
||||
## 変更内容
|
||||
|
||||
- `/v/browser` のファイルドロップと右下のキュー。逐次送信、待機取消、折りたたみ、同名保護、一覧だけの更新。ページを閉じた後の再開とフォルダ再帰アップロードは未対応。
|
||||
- ログイン時の信頼端末選択。管理者指定の最大30日・絶対期限で、既存セッションは延長しません。パスワード/TOTP、OIDC、LDAP、マジックリンクに選択を引き継ぎます。
|
||||
- CLIの `login --remember` と期限切れ再ログイン時の作業パス/保留下書き保持。
|
||||
- RSS一覧の配信時刻とDomainタイムゾーン。本文の日付表示も同じタイムゾーンへ統一。
|
||||
- 保存済みタスクの関連Wikiページを開くボタン。
|
||||
- 認証済み閲覧者の権限を確認する有界CSV macro。`{{csv:/data/items.csv range=A1:H200 header=true}}` と同じObjectのRevision固定に対応。CSV編集・匿名投影・外部URL取得は含みません。
|
||||
- Geckoの日本語ページ内検索、起動上限・失敗時のiframe破棄、固定ソース/notice付き配布物検査。Safari実機、IME・コピー、運用firewallと低メモリ受入は残件。
|
||||
|
||||
## リリースと検証
|
||||
|
||||
本体commitは `b90aef79d03c21332cd49a47aba015a30f6de1a0`。Gitea [build 76](https://git.anya.jp/anya/pages/actions/runs/76)、[release 79](https://git.anya.jp/anya/pages/actions/runs/79) が成功し、SHAイメージを再ビルドせず `v0.15.0` へ昇格しました。
|
||||
|
||||
CLI commitは `bee03094f3bf2fa0c2dab80313d2f4bd15452c3d`。[v0.5.0](https://git.anya.jp/anya/pages-cli/releases/tag/v0.5.0) のCIと55単体テストが成功。公開した4ファイルのSHA256SUMS照合、Pythonソース一致、取得したLinux ELFのバージョン・ログイン・タスク/メール取り込み・下書き回復等の合成スモークテストを確認しました。未検証のmacOS/Windowsバイナリは追加していません。
|
||||
|
||||
本体は `go test ./...`、`go vet ./...`、リリースツールと壁紙テスト、Gecko配布ツールのテストが成功。Chromiumで認証・タスク・RSS・Gecko・アップロードの合成試験を実施しました。アップロードキューは1280px/390px幅、逐次送信、同名保護、取消、一覧更新を検証しています。
|
||||
|
||||
## DBと復旧
|
||||
|
||||
`cli-auth` v1→v2で `auth_cli_requests.remember` を既定0・0/1制約付きで追加します。他の管理対象componentのversionは変わりません。両インスタンスの独立コピーで、ネットワークを遮断しworkerを停止して新イメージを起動し、schema checkとSQLite integrity_checkが成功しました。実外部カレンダーやメール内容は検証に使用していません。
|
||||
|
||||
保全先は `.deployment-backups/release-v0.15.0-20261108/`。`config/` に旧設定、`cutover/data` と `cutover/data2` に停止時点のデータを保存します。旧3イメージの `rollback-before-v0.15.0-20261108` タグと既存バックアップを保持します。
|
||||
|
||||
新しいmigration履歴を旧版が受け付けるとは限らないため、旧イメージだけのダウングレードは行いません。切戻しが必要ならwriterを止め、切替後データも保全し、停止時バックアップとの変更差分を扱ってからDB・ファイル・設定・イメージを同じ復旧点へ戻します。運用開始後の書き込みを黙って破棄しません。
|
||||
|
||||
## 本番反映
|
||||
|
||||
2026-11-08 20:41:33 JSTに配備後確認を完了しました。20:40:05に停止し、20:41:10に停止時バックアップを検証、20:41:16に新版の起動とhealthを確認しています。
|
||||
|
||||
- app・app2・adaptor-gateway・excalidraw-viewerはすべて対象commitと一致し、running・再起動回数0。
|
||||
- 両DBのquick_checkはok、管理対象13componentはcurrent。legacy領域全体の検証を意味するものではありません。
|
||||
- 外部HTTPSのhealth・ログイン画面200。匿名タスク/dashboard/RSS画面303、タスクAPI・DELETE・captureは401。
|
||||
- tasks、RSS、Gecko、アップロードキュー、信頼端末UIの配信JS/CSSはリリースcommitとSHA-256一致。公開ログイン画面の信頼端末選択も確認。
|
||||
- 起動直後のfatal/panic、DB/schema failure、event job failureは両アプリとも0件。
|
||||
- `.env.release` は `PAGESWIKI_IMAGE_TAG=v0.15.0`。Gecko relayコンテナは起動せず、通常3イメージ・4サービスだけを更新。
|
||||
|
||||
配備イメージのmanifest digest:
|
||||
|
||||
| イメージ(`git.anya.jp/anya/`) | digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:43c398f2c294c7802987aaae1bfdf27b3d0c7ea24fa73df912ac03ea312366b0` |
|
||||
| pageswiki-adaptor-gateway | `sha256:aebc515c3b3e36b58b03ecab1646e6d95b0dd21074a1a863ca5806cb7fde4df1` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:4a80354aa4567abe52ff17e32a6f224e85d8cd2e0f1a466e5690b4b353d901cc` |
|
||||
@@ -12,6 +12,14 @@ require (
|
||||
modernc.org/sqlite v1.32.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/nftables v0.3.0 // indirect
|
||||
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 // indirect
|
||||
github.com/mdlayher/socket v0.5.0 // indirect
|
||||
golang.org/x/sync v0.11.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Azure/go-ntlmssp v0.1.1 // indirect
|
||||
github.com/SherClockHolmes/webpush-go v1.4.0
|
||||
|
||||
@@ -27,7 +27,10 @@ github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17w
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df h1:Mwihr/o+v4L5h56rwHLOE20+hh7Okhwno5BHz3zDuao=
|
||||
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/nftables v0.3.0 h1:bkyZ0cbpVeMHXOrtlFc8ISmfVqq5gPJukoYieyVmITg=
|
||||
github.com/google/nftables v0.3.0/go.mod h1:BCp9FsrbF1Fn/Yu6CLUc9GGZFw/+hsxfluNXXmxBfRM=
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo=
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -55,6 +58,10 @@ github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZ
|
||||
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
|
||||
github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
|
||||
github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
|
||||
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 h1:A1Cq6Ysb0GM0tpKMbdCXCIfBclan4oHk1Jb+Hrejirg=
|
||||
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42/go.mod h1:BB4YCPDOzfy7FniQ/lxuYQ3dgmM2cZumHbK8RpTjN2o=
|
||||
github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI=
|
||||
github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI=
|
||||
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
|
||||
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
|
||||
@@ -21,6 +21,8 @@ type Manifest struct {
|
||||
|
||||
func Catalog() []Manifest {
|
||||
return []Manifest{
|
||||
{ID: "viewer.slides", APIVersion: 1, Version: "0.1.0", Kind: "viewer", Scope: "domain", NameKey: "slides.title", DescriptionKey: "slides.help", Capabilities: []string{"path.read"}, Events: []string{}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "client-compute+bounded-read"},
|
||||
{ID: "viewer.gecko", APIVersion: 1, Version: "0.1.0", Kind: "viewer", Scope: "domain", NameKey: "feeds.gecko", DescriptionKey: "feeds.gecko_help", Capabilities: []string{"feeds.own.read"}, Events: []string{}, SettingsPanel: "extensions", Builtin: true, Enabled: false, ResourceClass: "client-compute+relay-network"},
|
||||
{ID: "organizer.feeds", APIVersion: 1, Version: "0.1.0", Kind: "feeds", Scope: "domain", NameKey: "feeds.title", DescriptionKey: "feeds.help", Capabilities: []string{"feeds.own.read", "feeds.own.write"}, Events: []string{"feed.source.sync"}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "background+network+index"},
|
||||
{ID: "organizer.contacts", APIVersion: 1, Version: "0.2.0", Kind: "contacts", Scope: "domain", NameKey: "contacts.title", DescriptionKey: "contacts.help", Capabilities: []string{"contacts.own.read", "contacts.own.write"}, Events: []string{}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "foreground+index"},
|
||||
{ID: "organizer.tasks", APIVersion: 1, Version: "0.14.0", Kind: "tasks", Scope: "domain", NameKey: "tasks.title", DescriptionKey: "tasks.help", Capabilities: []string{"tasks.own.read", "tasks.own.write"}, Events: []string{"organizer.task.changed", "organizer.project.changed", "task.digest.deliver"}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "foreground+background+index"},
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
PagesWiki Gecko relay
|
||||
|
||||
This image contains the PagesWiki TCP relay, not Firefox/Gecko, gecko.js,
|
||||
gecko.wasm.zst, Mozilla runtime assets or browser fonts.
|
||||
|
||||
Third-party code linked into the relay binary:
|
||||
- Go standard library and runtime, Copyright The Go Authors.
|
||||
BSD-3-Clause; full license: /licenses/Go.txt
|
||||
Source and release archives: https://go.dev/dl/
|
||||
- golang.org/x/net v0.35.0 (WebSocket transport), Copyright The Go Authors.
|
||||
BSD-3-Clause; full license: /licenses/golang-x-net.txt
|
||||
Source: https://go.googlesource.com/net/+/refs/tags/v0.35.0/
|
||||
|
||||
The licenses are copied from the exact toolchain/module used at build time.
|
||||
The scratch runtime image does not contain Alpine, BusyBox or apk.
|
||||
The PagesWiki integration source and engine redistribution assessment are in:
|
||||
https://git.anya.jp/anya/pages
|
||||
docs/operations/gecko-redistribution.md
|
||||
|
||||
Mounting and serving an independently obtained browser engine requires a
|
||||
separate assessment and delivery of its applicable notices and source offer.
|
||||
This relay notice is not a license grant for that engine.
|
||||
@@ -0,0 +1,137 @@
|
||||
// Package geckorelay provides a bounded TCP-only Wisp transport for Gecko.
|
||||
// It is not a public general-purpose proxy: the PagesWiki frontend authenticates
|
||||
// the user and signs each backend request, and every destination is checked here.
|
||||
package geckorelay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const GrantHeader = "X-PagesWiki-Gecko-Grant"
|
||||
|
||||
type Grant struct {
|
||||
Subject string `json:"subject"`
|
||||
Nonce string `json:"nonce"`
|
||||
Expires int64 `json:"expires"`
|
||||
}
|
||||
|
||||
func Sign(key string, grant Grant) string {
|
||||
data, _ := json.Marshal(grant)
|
||||
body := base64.RawURLEncoding.EncodeToString(data)
|
||||
h := hmac.New(sha256.New, []byte(key))
|
||||
h.Write([]byte(body))
|
||||
return body + "." + base64.RawURLEncoding.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func Verify(key, token string, now time.Time) (Grant, error) {
|
||||
var grant Grant
|
||||
parts := strings.Split(token, ".")
|
||||
if len(key) < 32 || len(token) > 2048 || len(parts) != 2 {
|
||||
return grant, errors.New("invalid grant")
|
||||
}
|
||||
sig, err := base64.RawURLEncoding.DecodeString(parts[1])
|
||||
if err != nil {
|
||||
return grant, errors.New("invalid grant")
|
||||
}
|
||||
h := hmac.New(sha256.New, []byte(key))
|
||||
h.Write([]byte(parts[0]))
|
||||
if !hmac.Equal(sig, h.Sum(nil)) {
|
||||
return grant, errors.New("invalid grant")
|
||||
}
|
||||
data, err := base64.RawURLEncoding.DecodeString(parts[0])
|
||||
if err != nil {
|
||||
return grant, errors.New("invalid grant")
|
||||
}
|
||||
if json.Unmarshal(data, &grant) != nil || grant.Subject == "" || len(grant.Subject) > 160 || len(grant.Nonce) < 16 || len(grant.Nonce) > 80 || grant.Expires <= now.Unix() || grant.Expires > now.Add(time.Minute).Unix() {
|
||||
return Grant{}, errors.New("invalid grant")
|
||||
}
|
||||
return grant, nil
|
||||
}
|
||||
|
||||
var denied = func() []netip.Prefix {
|
||||
var result []netip.Prefix
|
||||
for _, p := range []string{"0.0.0.0/8", "100.64.0.0/10", "192.0.0.0/24", "192.0.2.0/24", "192.88.99.0/24", "198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "240.0.0.0/4", "2001::/23", "2001:db8::/32", "2002::/16", "3fff::/20"} {
|
||||
result = append(result, netip.MustParsePrefix(p))
|
||||
}
|
||||
return result
|
||||
}()
|
||||
|
||||
func PublicIP(ip netip.Addr) bool {
|
||||
ip = ip.Unmap()
|
||||
if !ip.IsValid() || ip.Zone() != "" || !ip.IsGlobalUnicast() || ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast() {
|
||||
return false
|
||||
}
|
||||
// Only globally allocated IPv6 unicast; excludes NAT64, mapped/private and
|
||||
// future address classes rather than treating unknown ranges as public.
|
||||
if ip.Is6() && !netip.MustParsePrefix("2000::/3").Contains(ip) {
|
||||
return false
|
||||
}
|
||||
for _, p := range denied {
|
||||
if p.Contains(ip) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func ValidDestination(host string, port uint16) bool {
|
||||
if port != 80 && port != 443 {
|
||||
return false
|
||||
}
|
||||
if ip, err := netip.ParseAddr(host); err == nil {
|
||||
return PublicIP(ip)
|
||||
}
|
||||
host = strings.TrimSuffix(strings.ToLower(host), ".")
|
||||
if len(host) == 0 || len(host) > 253 || host == "localhost" || strings.HasSuffix(host, ".localhost") || !strings.Contains(host, ".") {
|
||||
return false
|
||||
}
|
||||
for _, label := range strings.Split(host, ".") {
|
||||
if len(label) == 0 || len(label) > 63 || label[0] == '-' || label[len(label)-1] == '-' {
|
||||
return false
|
||||
}
|
||||
for _, c := range label {
|
||||
if !(c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '-') {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type lookupFunc func(context.Context, string, string) ([]netip.Addr, error)
|
||||
type dialFunc func(context.Context, string, string) (net.Conn, error)
|
||||
|
||||
func dialPublic(ctx context.Context, host string, port uint16, lookup lookupFunc, dial dialFunc) (net.Conn, error) {
|
||||
if !ValidDestination(host, port) {
|
||||
return nil, errors.New("blocked destination")
|
||||
}
|
||||
ips, err := lookup(ctx, "ip", host)
|
||||
if err != nil || len(ips) == 0 || len(ips) > 16 {
|
||||
return nil, errors.New("destination lookup failed")
|
||||
}
|
||||
for _, ip := range ips {
|
||||
if !PublicIP(ip) {
|
||||
return nil, errors.New("blocked destination")
|
||||
}
|
||||
}
|
||||
for _, ip := range ips {
|
||||
conn, e := dial(ctx, "tcp", net.JoinHostPort(ip.Unmap().String(), strconv.Itoa(int(port))))
|
||||
if e == nil {
|
||||
return conn, nil
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil, errors.New("destination unavailable")
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package geckorelay
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const AssetsPrefix = "/assets/v0.0.1/"
|
||||
|
||||
// Hashes of the two unmodified files in upstream v0.0.1. The release archive
|
||||
// itself is pinned in docs/operations/gecko-relay.md. Refuse mixed engine/glue.
|
||||
func VerifyAssets(dir string) error {
|
||||
for name, want := range map[string]string{
|
||||
"gecko.js": "e5aeebffd21106eccf23b1219316221add5e95085bc5a1bfb941117cfcd75ef7",
|
||||
"gecko.wasm.zst": "ebd6c75179152624d9644865e11792ed25cadc714d9e0985f412baf9c637a086",
|
||||
} {
|
||||
f, err := os.Open(filepath.Join(dir, name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("required Gecko asset unavailable: %s", name)
|
||||
}
|
||||
h := sha256.New()
|
||||
_, err = io.Copy(h, io.LimitReader(f, 64<<20))
|
||||
f.Close()
|
||||
if err != nil || hex.EncodeToString(h.Sum(nil)) != want {
|
||||
return fmt.Errorf("Gecko asset checksum mismatch: %s", name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package geckorelay
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const DistributionPrefix = "/distribution/v0.0.1/"
|
||||
|
||||
// Updated only after the reproducible source/notice bundle has been reviewed.
|
||||
const DistributionManifestSHA256 = "84953114f5e393dd97d9f948a5bc51c95b9355b58461dd3355e068a96cb2e381"
|
||||
|
||||
type DistributionFile struct {
|
||||
File string `json:"file"`
|
||||
SHA256 string `json:"sha256"`
|
||||
Size int64 `json:"size"`
|
||||
Kind string `json:"kind"`
|
||||
}
|
||||
|
||||
var distributionName = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9._+-]{0,150}$`)
|
||||
|
||||
func VerifyDistribution(dir string) (map[string]DistributionFile, error) {
|
||||
return verifyDistribution(dir, DistributionManifestSHA256)
|
||||
}
|
||||
|
||||
func verifyDistribution(dir, expected string) (map[string]DistributionFile, error) {
|
||||
path := filepath.Join(dir, "manifest.json")
|
||||
info, err := os.Lstat(path)
|
||||
if err != nil || !info.Mode().IsRegular() || info.Size() > 1<<20 {
|
||||
return nil, fmt.Errorf("Gecko distribution manifest missing or invalid")
|
||||
}
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sum := sha256.Sum256(raw)
|
||||
if hex.EncodeToString(sum[:]) != expected {
|
||||
return nil, fmt.Errorf("Gecko distribution manifest checksum mismatch")
|
||||
}
|
||||
var manifest struct {
|
||||
Format string `json:"format"`
|
||||
Version string `json:"version"`
|
||||
Files []DistributionFile `json:"files"`
|
||||
}
|
||||
if json.Unmarshal(raw, &manifest) != nil || manifest.Format != "pageswiki.gecko-distribution.v1" || manifest.Version != "v0.0.1" || len(manifest.Files) > 512 {
|
||||
return nil, fmt.Errorf("invalid Gecko distribution format")
|
||||
}
|
||||
files := map[string]DistributionFile{}
|
||||
for _, entry := range manifest.Files {
|
||||
if !distributionName.MatchString(entry.File) || entry.File == "manifest.json" || entry.Size < 1 || entry.Size > 2<<30 || len(entry.SHA256) != 64 {
|
||||
return nil, fmt.Errorf("invalid distribution entry")
|
||||
}
|
||||
if _, exists := files[entry.File]; exists {
|
||||
return nil, fmt.Errorf("duplicate distribution entry")
|
||||
}
|
||||
info, err := os.Lstat(filepath.Join(dir, entry.File))
|
||||
if err != nil || !info.Mode().IsRegular() || info.Size() != entry.Size {
|
||||
return nil, fmt.Errorf("distribution file missing or invalid: %s", entry.File)
|
||||
}
|
||||
file, err := os.Open(filepath.Join(dir, entry.File))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash := sha256.New()
|
||||
_, err = io.Copy(hash, io.LimitReader(file, entry.Size+1))
|
||||
file.Close()
|
||||
if err != nil || hex.EncodeToString(hash.Sum(nil)) != entry.SHA256 {
|
||||
return nil, fmt.Errorf("distribution file checksum mismatch: %s", entry.File)
|
||||
}
|
||||
files[entry.File] = entry
|
||||
}
|
||||
for _, name := range []string{"index.html", "README.txt", "gecko.js", "gecko.wasm.zst", "firefox.tar.gz", "firefox.tar.gz.notices.txt", "wrapper.tar.gz", "wrapper-MPL.txt", "emscripten.tar.gz", "emscripten.tar.gz.notices.txt", "rust-src.tar.xz", "rust-src.tar.xz.notices.txt", "zstddec.tgz", "zstddec.tgz.notices.txt", "NotoSansCJKjp-Regular.otf", "NotoSansCJK-LICENSE.txt"} {
|
||||
if _, ok := files[name]; !ok {
|
||||
return nil, fmt.Errorf("distribution incomplete: %s", name)
|
||||
}
|
||||
}
|
||||
files["manifest.json"] = DistributionFile{File: "manifest.json", SHA256: expected, Size: int64(len(raw)), Kind: "manifest"}
|
||||
return files, nil
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package geckorelay
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDistribution(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if _, err := VerifyDistribution(dir); err == nil {
|
||||
t.Fatal("missing distribution accepted")
|
||||
}
|
||||
names := []string{"index.html", "README.txt", "gecko.js", "gecko.wasm.zst", "firefox.tar.gz", "firefox.tar.gz.notices.txt", "wrapper.tar.gz", "wrapper-MPL.txt", "emscripten.tar.gz", "emscripten.tar.gz.notices.txt", "rust-src.tar.xz", "rust-src.tar.xz.notices.txt", "zstddec.tgz", "zstddec.tgz.notices.txt", "NotoSansCJKjp-Regular.otf", "NotoSansCJK-LICENSE.txt"}
|
||||
content := []byte("synthetic source and notice")
|
||||
hash := sha256.Sum256(content)
|
||||
var entries []DistributionFile
|
||||
for _, name := range names {
|
||||
if err := os.WriteFile(filepath.Join(dir, name), content, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
entries = append(entries, DistributionFile{File: name, Size: int64(len(content)), SHA256: hex.EncodeToString(hash[:])})
|
||||
}
|
||||
raw, _ := json.Marshal(map[string]any{"format": "pageswiki.gecko-distribution.v1", "version": "v0.0.1", "files": entries})
|
||||
if err := os.WriteFile(filepath.Join(dir, "manifest.json"), raw, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sum := sha256.Sum256(raw)
|
||||
want := hex.EncodeToString(sum[:])
|
||||
files, err := verifyDistribution(dir, want)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
relay, _ := New(testKey, dir)
|
||||
relay.Distribution = files
|
||||
for _, name := range []string{"index.html", "firefox.tar.gz", "manifest.json", "unknown", "../manifest.json"} {
|
||||
req := httptest.NewRequest("GET", DistributionPrefix+name, nil)
|
||||
req.Header.Set(GrantHeader, Sign(testKey, Grant{Subject: "test:user", Nonce: "download-test-0123456789", Expires: time.Now().Add(30 * time.Second).Unix()}))
|
||||
rec := httptest.NewRecorder()
|
||||
relay.ServeHTTP(rec, req)
|
||||
expected := 200
|
||||
if strings.Contains(name, "unknown") || strings.Contains(name, "../") {
|
||||
expected = 404
|
||||
}
|
||||
if rec.Code != expected {
|
||||
t.Fatalf("%s: %d", name, rec.Code)
|
||||
}
|
||||
if expected == 200 && rec.Header().Get("ETag") == "" {
|
||||
t.Fatal("no ETag")
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "README.txt"), []byte("tampered"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := verifyDistribution(dir, want); err == nil {
|
||||
t.Fatal("tampered notice accepted")
|
||||
}
|
||||
if err := os.Remove(filepath.Join(dir, "README.txt")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(filepath.Join(dir, "gecko.js"), filepath.Join(dir, "README.txt")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := verifyDistribution(dir, want); err == nil {
|
||||
t.Fatal("symlink accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistributionRealBundle(t *testing.T) {
|
||||
dir := os.Getenv("PAGESWIKI_GECKO_TEST_BUNDLE")
|
||||
if dir == "" {
|
||||
t.Skip("opt-in complete distribution")
|
||||
}
|
||||
if _, err := VerifyDistribution(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,396 @@
|
||||
package geckorelay
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
const (
|
||||
window = 8
|
||||
maxFrame = 256 << 10
|
||||
maxStreams = 16
|
||||
maxBytes = 256 << 20
|
||||
bytesPerSecond = 2 << 20
|
||||
)
|
||||
|
||||
type Relay struct {
|
||||
Key, Assets string
|
||||
Distribution map[string]DistributionFile
|
||||
downloads chan struct{}
|
||||
mu sync.Mutex
|
||||
active map[string]bool
|
||||
used map[string]int64
|
||||
rx, tx, rejected atomic.Int64
|
||||
// Overridden only by package tests; deployment always resolves and pins public IPs.
|
||||
dial func(context.Context, string, uint16) (net.Conn, error)
|
||||
}
|
||||
|
||||
func New(key, assets string) (*Relay, error) {
|
||||
if len(key) < 32 {
|
||||
return nil, errors.New("relay key must contain at least 32 bytes")
|
||||
}
|
||||
r := &Relay{Key: key, Assets: assets, active: map[string]bool{}, used: map[string]int64{}, downloads: make(chan struct{}, 2)}
|
||||
r.dial = func(ctx context.Context, host string, port uint16) (net.Conn, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, 8*time.Second)
|
||||
defer cancel()
|
||||
return dialPublic(ctx, host, port, net.DefaultResolver.LookupNetIP, (&net.Dialer{Timeout: 2 * time.Second}).DialContext)
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (r *Relay) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
if req.URL.Path == "/health" && req.Method == "GET" {
|
||||
io.WriteString(w, "ok")
|
||||
return
|
||||
}
|
||||
grant, err := Verify(r.Key, req.Header.Get(GrantHeader), time.Now())
|
||||
if err != nil {
|
||||
http.Error(w, "forbidden", 403)
|
||||
return
|
||||
}
|
||||
if req.Method != "GET" || req.URL.RawQuery != "" {
|
||||
http.Error(w, "invalid request", 400)
|
||||
return
|
||||
}
|
||||
if req.URL.Path == "/status" {
|
||||
r.mu.Lock()
|
||||
active := len(r.active)
|
||||
r.mu.Unlock()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]any{"active_sessions": active, "received_bytes": r.rx.Load(), "sent_bytes": r.tx.Load(), "rejected": r.rejected.Load(), "profile": "tcp-80-443", "max_sessions": 4, "max_streams": maxStreams, "bytes_per_second": bytesPerSecond, "max_session_bytes": maxBytes})
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(req.URL.Path, DistributionPrefix) {
|
||||
name := strings.TrimPrefix(req.URL.Path, DistributionPrefix)
|
||||
entry, ok := r.Distribution[name]
|
||||
if !ok {
|
||||
http.NotFound(w, req)
|
||||
return
|
||||
}
|
||||
select {
|
||||
case r.downloads <- struct{}{}:
|
||||
defer func() { <-r.downloads }()
|
||||
default:
|
||||
http.Error(w, "download limit", 429)
|
||||
return
|
||||
}
|
||||
w.Header().Set("ETag", `"`+entry.SHA256+`"`)
|
||||
w.Header().Set("Cache-Control", "private, max-age=86400, immutable")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Header().Set("Content-Security-Policy", "default-src 'none'; base-uri 'none'; frame-ancestors 'self'")
|
||||
w.Header().Set("Referrer-Policy", "no-referrer")
|
||||
switch {
|
||||
case name == "index.html":
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
case strings.HasSuffix(name, ".txt"):
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
case name == "manifest.json":
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
default:
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="`+name+`"`)
|
||||
}
|
||||
// ServeContent avoids ServeFile's /index.html -> ./ redirect, which
|
||||
// would escape the explicit file allowlist at the proxy boundary.
|
||||
file, err := os.Open(filepath.Join(r.Assets, name))
|
||||
if err != nil {
|
||||
http.NotFound(w, req)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
http.ServeContent(w, req, name, time.Time{}, file)
|
||||
return
|
||||
}
|
||||
if req.URL.Path == AssetsPrefix+"gecko.js" || req.URL.Path == AssetsPrefix+"gecko.wasm.zst" {
|
||||
w.Header().Set("Cross-Origin-Resource-Policy", "same-origin")
|
||||
w.Header().Set("Cache-Control", "private, max-age=86400, immutable")
|
||||
if strings.HasSuffix(req.URL.Path, ".js") {
|
||||
w.Header().Set("Content-Type", "text/javascript")
|
||||
} else {
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
}
|
||||
http.ServeFile(w, req, filepath.Join(r.Assets, filepath.Base(req.URL.Path)))
|
||||
return
|
||||
}
|
||||
if req.URL.Path != "/wisp/" {
|
||||
http.NotFound(w, req)
|
||||
return
|
||||
}
|
||||
r.mu.Lock()
|
||||
now := time.Now().Unix()
|
||||
for nonce, expires := range r.used {
|
||||
if expires <= now {
|
||||
delete(r.used, nonce)
|
||||
}
|
||||
}
|
||||
if r.active[grant.Subject] || len(r.active) >= 4 || r.used[grant.Nonce] > now || len(r.used) >= 256 {
|
||||
r.mu.Unlock()
|
||||
r.rejected.Add(1)
|
||||
http.Error(w, "session limit", 429)
|
||||
return
|
||||
}
|
||||
r.active[grant.Subject] = true
|
||||
r.used[grant.Nonce] = grant.Expires
|
||||
r.mu.Unlock()
|
||||
defer func() { r.mu.Lock(); delete(r.active, grant.Subject); r.mu.Unlock() }()
|
||||
wsServer := websocket.Server{Handshake: func(c *websocket.Config, req *http.Request) error {
|
||||
// Only the authenticated PagesWiki proxy can sign a grant. It validates
|
||||
// the browser Origin before forwarding, not the untrusted client header.
|
||||
if req.Header.Get("Origin") == "" {
|
||||
return errors.New("origin required")
|
||||
}
|
||||
return nil
|
||||
}, Handler: func(ws *websocket.Conn) { r.serve(ws) }}
|
||||
wsServer.ServeHTTP(w, req)
|
||||
}
|
||||
|
||||
type stream struct {
|
||||
data chan []byte
|
||||
done chan struct{}
|
||||
once sync.Once
|
||||
mu sync.Mutex
|
||||
conn net.Conn
|
||||
}
|
||||
|
||||
func (s *stream) close() {
|
||||
s.once.Do(func() {
|
||||
close(s.done)
|
||||
s.mu.Lock()
|
||||
if s.conn != nil {
|
||||
s.conn.Close()
|
||||
}
|
||||
s.mu.Unlock()
|
||||
})
|
||||
}
|
||||
func packet(kind byte, id uint32, data []byte) []byte {
|
||||
b := make([]byte, 5+len(data))
|
||||
b[0] = kind
|
||||
binary.LittleEndian.PutUint32(b[1:], id)
|
||||
copy(b[5:], data)
|
||||
return b
|
||||
}
|
||||
func credit() []byte { b := make([]byte, 4); binary.LittleEndian.PutUint32(b, window); return b }
|
||||
|
||||
func (r *Relay) serve(ws *websocket.Conn) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
|
||||
defer cancel()
|
||||
defer ws.Close()
|
||||
ws.MaxPayloadBytes = maxFrame + 5
|
||||
var mu, sendMu, budgetMu sync.Mutex
|
||||
streams := map[uint32]*stream{}
|
||||
var workers sync.WaitGroup
|
||||
var spent int64
|
||||
tokens := float64(bytesPerSecond)
|
||||
last := time.Now()
|
||||
account := func(n int) bool {
|
||||
budgetMu.Lock()
|
||||
defer budgetMu.Unlock()
|
||||
spent += int64(n)
|
||||
if spent > maxBytes {
|
||||
return false
|
||||
}
|
||||
now := time.Now()
|
||||
tokens += now.Sub(last).Seconds() * bytesPerSecond
|
||||
if tokens > bytesPerSecond {
|
||||
tokens = bytesPerSecond
|
||||
}
|
||||
last = now
|
||||
tokens -= float64(n)
|
||||
if tokens < 0 {
|
||||
timer := time.NewTimer(time.Duration(-tokens / bytesPerSecond * float64(time.Second)))
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case <-timer.C:
|
||||
tokens = 0
|
||||
last = time.Now()
|
||||
case <-ctx.Done():
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
send := func(kind byte, id uint32, data []byte) error {
|
||||
sendMu.Lock()
|
||||
defer sendMu.Unlock()
|
||||
ws.SetWriteDeadline(time.Now().Add(10 * time.Second))
|
||||
return websocket.Message.Send(ws, packet(kind, id, data))
|
||||
}
|
||||
defer func() {
|
||||
cancel()
|
||||
mu.Lock()
|
||||
for _, s := range streams {
|
||||
s.close()
|
||||
}
|
||||
mu.Unlock()
|
||||
workers.Wait()
|
||||
}()
|
||||
go func() { <-ctx.Done(); ws.Close() }()
|
||||
if send(3, 0, credit()) != nil {
|
||||
return
|
||||
}
|
||||
connections := 0
|
||||
for {
|
||||
ws.SetReadDeadline(time.Now().Add(90 * time.Second))
|
||||
var b []byte
|
||||
if websocket.Message.Receive(ws, &b) != nil {
|
||||
return
|
||||
}
|
||||
if len(b) < 5 || !account(len(b)) {
|
||||
return
|
||||
}
|
||||
r.rx.Add(int64(len(b)))
|
||||
kind, id := b[0], binary.LittleEndian.Uint32(b[1:])
|
||||
if id == 0 {
|
||||
return
|
||||
}
|
||||
mu.Lock()
|
||||
s := streams[id]
|
||||
mu.Unlock()
|
||||
switch kind {
|
||||
case 1:
|
||||
connections++
|
||||
if s != nil || len(b) < 9 || len(b) > 261 || connections > 256 {
|
||||
return
|
||||
}
|
||||
port := binary.LittleEndian.Uint16(b[6:8])
|
||||
host := string(b[8:])
|
||||
if b[5] != 1 || !ValidDestination(host, port) {
|
||||
r.rejected.Add(1)
|
||||
if send(4, id, []byte{0x48}) != nil {
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
mu.Lock()
|
||||
full := len(streams) >= maxStreams
|
||||
mu.Unlock()
|
||||
if full {
|
||||
r.rejected.Add(1)
|
||||
if send(4, id, []byte{0x49}) != nil {
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
s = &stream{data: make(chan []byte, window), done: make(chan struct{})}
|
||||
mu.Lock()
|
||||
streams[id] = s
|
||||
mu.Unlock()
|
||||
workers.Add(1)
|
||||
go func(id uint32, s *stream, host string, port uint16) {
|
||||
defer workers.Done()
|
||||
defer func() { s.close(); mu.Lock(); delete(streams, id); mu.Unlock() }()
|
||||
dialCtx, stop := context.WithCancel(ctx)
|
||||
defer stop()
|
||||
go func() {
|
||||
select {
|
||||
case <-s.done:
|
||||
stop()
|
||||
case <-dialCtx.Done():
|
||||
}
|
||||
}()
|
||||
conn, e := r.dial(dialCtx, host, port)
|
||||
if e != nil {
|
||||
r.rejected.Add(1)
|
||||
send(4, id, []byte{0x48})
|
||||
return
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.conn = conn
|
||||
s.mu.Unlock()
|
||||
select {
|
||||
case <-s.done:
|
||||
conn.Close()
|
||||
return
|
||||
default:
|
||||
}
|
||||
readerDone := make(chan struct{})
|
||||
defer func() { conn.Close(); <-readerDone }()
|
||||
go func() {
|
||||
defer close(readerDone)
|
||||
defer s.close()
|
||||
buffer := make([]byte, 64<<10)
|
||||
for {
|
||||
conn.SetReadDeadline(time.Now().Add(60 * time.Second))
|
||||
n, e := conn.Read(buffer)
|
||||
if n > 0 {
|
||||
if !account(n) {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
r.tx.Add(int64(n))
|
||||
if send(2, id, buffer[:n]) != nil {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
}
|
||||
if e != nil {
|
||||
send(4, id, []byte{2})
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
count := 0
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-s.done:
|
||||
return
|
||||
case data := <-s.data:
|
||||
conn.SetWriteDeadline(time.Now().Add(10 * time.Second))
|
||||
if _, e = io.Copy(conn, bytes.NewReader(data)); e != nil {
|
||||
send(4, id, []byte{3})
|
||||
return
|
||||
}
|
||||
count++
|
||||
if count == window {
|
||||
count = 0
|
||||
if send(3, id, credit()) != nil {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}(id, s, host, port)
|
||||
case 2:
|
||||
if s == nil {
|
||||
continue
|
||||
}
|
||||
select {
|
||||
case <-s.done:
|
||||
case s.data <- b[5:]:
|
||||
default:
|
||||
r.rejected.Add(1)
|
||||
s.close()
|
||||
if send(4, id, []byte{0x49}) != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
case 4:
|
||||
if len(b) != 6 {
|
||||
return
|
||||
}
|
||||
if s != nil {
|
||||
s.close()
|
||||
}
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
package geckorelay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
const testKey = "synthetic-relay-key-at-least-32-bytes-long"
|
||||
|
||||
func TestAssetsPin(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if VerifyAssets(dir) == nil {
|
||||
t.Fatal("missing assets accepted")
|
||||
}
|
||||
for _, name := range []string{"gecko.js", "gecko.wasm.zst"} {
|
||||
if err := os.WriteFile(filepath.Join(dir, name), []byte("untrusted"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if VerifyAssets(dir) == nil {
|
||||
t.Fatal("unverified assets accepted")
|
||||
}
|
||||
if assets := os.Getenv("PAGESWIKI_GECKO_TEST_ASSETS"); assets != "" {
|
||||
if err := VerifyAssets(assets); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrant(t *testing.T) {
|
||||
now := time.Now()
|
||||
g := Grant{"domain:actor", "0123456789abcdef", now.Add(30 * time.Second).Unix()}
|
||||
token := Sign(testKey, g)
|
||||
if got, e := Verify(testKey, token, now); e != nil || got != g {
|
||||
t.Fatal(got, e)
|
||||
}
|
||||
for _, bad := range []string{token + "x", "", strings.Repeat("x", 2049), Sign(testKey, Grant{g.Subject, g.Nonce, now.Add(2 * time.Minute).Unix()}), Sign(testKey, Grant{g.Subject, g.Nonce, now.Unix()})} {
|
||||
if _, e := Verify(testKey, bad, now); e == nil {
|
||||
t.Fatal("accepted invalid grant")
|
||||
}
|
||||
}
|
||||
if _, e := Verify("other-key-at-least-32-bytes-long!!", token, now); e == nil {
|
||||
t.Fatal("wrong key")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestinations(t *testing.T) {
|
||||
for _, host := range []string{"127.0.0.1", "localhost", "host.localhost", "10.0.0.1", "169.254.169.254", "100.64.0.1", "192.0.2.2", "198.19.0.1", "::1", "::ffff:127.0.0.1", "64:ff9b::808:808", "2002:808:808::1", "2001:db8::1", "3fff::1", "fd00::1", "fe80::1%eth0", "bad/host", "example.org\x00.evil", "singlelabel"} {
|
||||
if ValidDestination(host, 443) {
|
||||
t.Fatalf("allowed %q", host)
|
||||
}
|
||||
}
|
||||
for _, host := range []string{"example.org", "EXAMPLE.org.", "8.8.8.8", "2606:4700:4700::1111"} {
|
||||
if !ValidDestination(host, 443) {
|
||||
t.Fatal("blocked", host)
|
||||
}
|
||||
}
|
||||
if ValidDestination("example.org", 22) {
|
||||
t.Fatal("port allowed")
|
||||
}
|
||||
called := false
|
||||
dial := func(_ context.Context, _, addr string) (net.Conn, error) {
|
||||
called = true
|
||||
if addr != "8.8.8.8:443" {
|
||||
t.Fatal("unvalidated DNS re-resolution", addr)
|
||||
}
|
||||
a, b := net.Pipe()
|
||||
b.Close()
|
||||
return a, nil
|
||||
}
|
||||
lookup := func(_ context.Context, _, _ string) ([]netip.Addr, error) {
|
||||
return []netip.Addr{netip.MustParseAddr("8.8.8.8"), netip.MustParseAddr("127.0.0.1")}, nil
|
||||
}
|
||||
if _, err := dialPublic(context.Background(), "example.org", 443, lookup, dial); err == nil || called {
|
||||
t.Fatal("mixed DNS allowed")
|
||||
}
|
||||
lookup = func(_ context.Context, _, _ string) ([]netip.Addr, error) {
|
||||
return []netip.Addr{netip.MustParseAddr("8.8.8.8")}, nil
|
||||
}
|
||||
c, err := dialPublic(context.Background(), "example.org", 443, lookup, dial)
|
||||
if err != nil || !called {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
|
||||
func TestRelayFramesAndLimits(t *testing.T) {
|
||||
r, _ := New(testKey, t.TempDir())
|
||||
r.dial = func(ctx context.Context, host string, port uint16) (net.Conn, error) {
|
||||
a, b := net.Pipe()
|
||||
go func() { defer b.Close(); io.Copy(b, b) }()
|
||||
return a, nil
|
||||
}
|
||||
s := httptest.NewServer(r)
|
||||
defer s.Close()
|
||||
grant := Sign(testKey, Grant{"domain:actor", "nonce-first-connection", time.Now().Add(30 * time.Second).Unix()})
|
||||
dial := func(token string) (*websocket.Conn, error) {
|
||||
cfg, _ := websocket.NewConfig("ws"+strings.TrimPrefix(s.URL, "http")+"/wisp/", "https://pages.example")
|
||||
cfg.Header.Set(GrantHeader, token)
|
||||
return websocket.DialConfig(cfg)
|
||||
}
|
||||
if c, e := dial(""); e == nil {
|
||||
c.Close()
|
||||
t.Fatal("anonymous websocket")
|
||||
}
|
||||
c, err := dial(grant)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
c.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
receive := func() []byte {
|
||||
var p []byte
|
||||
if e := websocket.Message.Receive(c, &p); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
return p
|
||||
}
|
||||
p := receive()
|
||||
if p[0] != 3 || binary.LittleEndian.Uint32(p[1:]) != 0 || binary.LittleEndian.Uint32(p[5:]) != window {
|
||||
t.Fatal(p)
|
||||
}
|
||||
if second, e := dial(grant); e == nil {
|
||||
second.Close()
|
||||
t.Fatal("duplicate actor/replayed grant")
|
||||
}
|
||||
connect := func(id uint32, host string, port uint16, kind byte) {
|
||||
body := []byte{kind, byte(port), byte(port >> 8)}
|
||||
body = append(body, host...)
|
||||
if e := websocket.Message.Send(c, packet(1, id, body)); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
connect(1, "127.0.0.1", 80, 1)
|
||||
if p = receive(); p[0] != 4 || p[5] != 0x48 {
|
||||
t.Fatal(p)
|
||||
}
|
||||
connect(2, "example.org", 443, 2)
|
||||
if p = receive(); p[0] != 4 {
|
||||
t.Fatal("UDP accepted")
|
||||
}
|
||||
connect(3, "example.org", 443, 1)
|
||||
for n := 0; n < window; n++ {
|
||||
if e := websocket.Message.Send(c, packet(2, 3, []byte("hello"))); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
got := 0
|
||||
creditSeen := false
|
||||
for got < window*5 || !creditSeen {
|
||||
p = receive()
|
||||
switch p[0] {
|
||||
case 2:
|
||||
got += len(p) - 5
|
||||
case 3:
|
||||
creditSeen = true
|
||||
default:
|
||||
t.Fatal(p)
|
||||
}
|
||||
}
|
||||
// Wisp credits count DATA frames, including empty payloads.
|
||||
for n := 0; n < window; n++ {
|
||||
if e := websocket.Message.Send(c, packet(2, 3, nil)); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
if p = receive(); p[0] != 3 || binary.LittleEndian.Uint32(p[1:]) != 3 {
|
||||
t.Fatal("empty frame credit", p)
|
||||
}
|
||||
websocket.Message.Send(c, packet(4, 3, []byte{2}))
|
||||
websocket.Message.Send(c, packet(9, 4, nil))
|
||||
var b []byte
|
||||
if websocket.Message.Receive(c, &b) == nil && b[0] != 4 {
|
||||
t.Fatal("invalid packet accepted")
|
||||
}
|
||||
resp, e := http.Get(s.URL + "/status")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != 403 {
|
||||
t.Fatal("unprotected metrics")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelayStreamBoundAndCancellation(t *testing.T) {
|
||||
r, _ := New(testKey, t.TempDir())
|
||||
var dialing atomic.Int64
|
||||
r.dial = func(ctx context.Context, host string, port uint16) (net.Conn, error) {
|
||||
dialing.Add(1)
|
||||
defer dialing.Add(-1)
|
||||
<-ctx.Done()
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
server := httptest.NewServer(r)
|
||||
defer server.Close()
|
||||
cfg, _ := websocket.NewConfig("ws"+strings.TrimPrefix(server.URL, "http")+"/wisp/", "https://pages.example")
|
||||
cfg.Header.Set(GrantHeader, Sign(testKey, Grant{"domain:actor", "stream-bound-nonce", time.Now().Add(30 * time.Second).Unix()}))
|
||||
c, err := websocket.DialConfig(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
c.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
var frame []byte
|
||||
if err = websocket.Message.Receive(c, &frame); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for id := 1; id <= maxStreams+1; id++ {
|
||||
if err = websocket.Message.Send(c, packet(1, uint32(id), append([]byte{1, 80, 0}, []byte("example.org")...))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err = websocket.Message.Receive(c, &frame); err != nil || len(frame) != 6 || frame[0] != 4 || binary.LittleEndian.Uint32(frame[1:]) != maxStreams+1 || frame[5] != 0x49 {
|
||||
t.Fatal("stream cap", frame, err)
|
||||
}
|
||||
c.Close()
|
||||
for n := 0; n < 100; n++ {
|
||||
r.mu.Lock()
|
||||
active := len(r.active)
|
||||
r.mu.Unlock()
|
||||
if active == 0 && dialing.Load() == 0 {
|
||||
return
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
t.Fatal("closing session did not cancel pending dials")
|
||||
}
|
||||
|
||||
func TestRelaySessionBoundAndReplay(t *testing.T) {
|
||||
r, _ := New(testKey, t.TempDir())
|
||||
server := httptest.NewServer(r)
|
||||
defer server.Close()
|
||||
dial := func(subject, nonce string) (*websocket.Conn, error) {
|
||||
cfg, _ := websocket.NewConfig("ws"+strings.TrimPrefix(server.URL, "http")+"/wisp/", "https://pages.example")
|
||||
cfg.Header.Set(GrantHeader, Sign(testKey, Grant{subject, nonce, time.Now().Add(30 * time.Second).Unix()}))
|
||||
return websocket.DialConfig(cfg)
|
||||
}
|
||||
var conns []*websocket.Conn
|
||||
for _, subject := range []string{"one", "two", "three", "four"} {
|
||||
c, e := dial(subject, "unique-session-nonce-"+subject)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
conns = append(conns, c)
|
||||
defer c.Close()
|
||||
}
|
||||
if c, e := dial("five", "unique-session-nonce-five"); e == nil {
|
||||
c.Close()
|
||||
t.Fatal("global cap exceeded")
|
||||
}
|
||||
conns[0].Close()
|
||||
for n := 0; n < 100; n++ {
|
||||
r.mu.Lock()
|
||||
active := len(r.active)
|
||||
r.mu.Unlock()
|
||||
if active == 3 {
|
||||
break
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
if c, e := dial("one", "unique-session-nonce-one"); e == nil {
|
||||
c.Close()
|
||||
t.Fatal("replayed after close")
|
||||
}
|
||||
c, e := dial("five", "unique-session-nonce-retry")
|
||||
if e != nil {
|
||||
t.Fatal("slot not released", e)
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
@@ -227,4 +227,9 @@ func textMediaType(descriptor Descriptor) bool {
|
||||
}
|
||||
|
||||
// Catalog returns a copy; callers cannot reorder or disable the shared registry.
|
||||
func Catalog() []Adapter { return append([]Adapter(nil), projectionAdapters...) }
|
||||
func Catalog() []Adapter {
|
||||
items := append([]Adapter(nil), projectionAdapters...)
|
||||
// Explicitly selected projection. It must not replace normal HTML/text
|
||||
// viewing in the automatic MIME classifier.
|
||||
return append(items, Adapter{ID: "reveal", Kind: "slides", Delivery: DeliveryRawFrame, Match: func(Descriptor) bool { return false }})
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func TestAdapterCatalogIsCopyAndConcurrent(t *testing.T) {
|
||||
for _, a := range catalog {
|
||||
ids = append(ids, a.ID)
|
||||
}
|
||||
if strings.Join(ids, ",") != "html,excalidraw,csv,archive,debian-package,eml,pe,json,text,image,audio,video,pdf,download" {
|
||||
if strings.Join(ids, ",") != "html,excalidraw,csv,archive,debian-package,eml,pe,json,text,image,audio,video,pdf,download,reveal" {
|
||||
t.Fatal("catalog order changed", ids)
|
||||
}
|
||||
catalog[0].ID = "corrupt"
|
||||
|
||||
@@ -185,6 +185,9 @@ func (s *Server) adapterActionsForPath(r *http.Request, semanticPath string) ([]
|
||||
{ID: "download", Name: "download", Mode: "viewer", Builtin: true,
|
||||
OpenURL: rawProjectionURL("rev:" + revision.UUID)},
|
||||
}
|
||||
if (mediaType == "text/html" || mediaType == "text/markdown" || mediaType == "text/x-markdown") && s.systemExtensionEnabled(domainUUID, "viewer.slides") {
|
||||
actions = append(actions, adapterAction{ID: "reveal", Name: "Reveal.js", Mode: "viewer", Builtin: true, OpenURL: "/v/slides" + semanticPath})
|
||||
}
|
||||
if selected.NeedsText || selected.ID == "html" || selected.ID == "excalidraw" {
|
||||
actions = append(actions, adapterAction{
|
||||
ID: "editor", Name: "Pages Wiki Editor", Mode: "editor",
|
||||
|
||||
@@ -35,6 +35,17 @@ func (s *Server) handleAuthAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
panel := "auth"
|
||||
switch r.FormValue("action") {
|
||||
case "save_trusted_session_policy":
|
||||
panel = "auth-sessions"
|
||||
days, err := strconv.Atoi(r.PostForm.Get("trusted_session_days"))
|
||||
if err != nil || days < 0 || days > 30 {
|
||||
http.Error(w, "trusted session lifetime must be between 0 and 30 days", 400)
|
||||
return
|
||||
}
|
||||
if err := s.store.SetConfigInDomain(domainUUID, "auth_trusted_session_days", strconv.Itoa(days)); err != nil {
|
||||
http.Error(w, "could not save session policy", 500)
|
||||
return
|
||||
}
|
||||
case "save_session_policy":
|
||||
panel = "auth-sessions"
|
||||
minutes, err := strconv.Atoi(r.FormValue("session_minutes"))
|
||||
|
||||
@@ -51,4 +51,8 @@ func TestBrowserCookieLoginLogoutChromium(t *testing.T) {
|
||||
if err := s.store.DB.QueryRow(`SELECT count(*) FROM auth_sessions WHERE revoked_at_ms>0`).Scan(&revoked); err != nil || revoked != 1 {
|
||||
t.Fatalf("browser revocations=%d %v", revoked, err)
|
||||
}
|
||||
var lifetime int64
|
||||
if err := s.store.DB.QueryRow(`SELECT expires_at_ms-auth_time_ms FROM auth_sessions WHERE revoked_at_ms>0`).Scan(&lifetime); err != nil || lifetime != (30*24*time.Hour).Milliseconds() {
|
||||
t.Fatalf("trusted browser lifetime=%d %v", lifetime, err)
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (s *Server) handleCLIAuth(w http.ResponseWriter, r *http.Request, action st
|
||||
writeEventJSON(w, 400, map[string]string{"error": "invalid_request"})
|
||||
return
|
||||
}
|
||||
id, device, code, err := s.store.StartCLIAuth(ctx, domain, cliOrigin(r), challenge)
|
||||
id, device, code, err := s.store.StartCLIAuthForLogin(ctx, domain, cliOrigin(r), challenge, r.PostForm.Get("remember") == "1")
|
||||
if err != nil {
|
||||
cliAuthError(w, err)
|
||||
return
|
||||
@@ -140,6 +140,9 @@ func (s *Server) verifyCLIAuth(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
data := map[string]any{"CLIAuth": true, "CLIOrigin": grant.Origin, "CLIRequest": id}
|
||||
if grant.Remember {
|
||||
data["CLIRememberDays"] = s.store.TrustedSessionDays(domain)
|
||||
}
|
||||
if grant.State != "pending" {
|
||||
data["CLIDone"] = true
|
||||
s.renderAuthPage(w, r, data)
|
||||
|
||||
@@ -28,6 +28,14 @@ func cliForm(s *Server, path string, form url.Values, cookie, origin string) *ht
|
||||
}
|
||||
|
||||
func TestCLIAuthOIDCFlow(t *testing.T) {
|
||||
for _, remember := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "normal", true: "trusted"}[remember], func(t *testing.T) {
|
||||
testCLIAuthOIDCFlow(t, remember)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testCLIAuthOIDCFlow(t *testing.T, remember bool) {
|
||||
s, api, domain := configFixture(t)
|
||||
principal := s.mustCLIPrincipal(t, domain, api)
|
||||
// An enrolled local factor must not add a second challenge to OIDC consent.
|
||||
@@ -43,7 +51,13 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
|
||||
}
|
||||
verifier := strings.Repeat("x", 43)
|
||||
sum := sha256.Sum256([]byte(verifier))
|
||||
start := cliForm(s, "/_/auth/cli/start", url.Values{"code_challenge": {base64.RawURLEncoding.EncodeToString(sum[:])}, "code_challenge_method": {"S256"}}, "", "")
|
||||
startForm := url.Values{"code_challenge": {base64.RawURLEncoding.EncodeToString(sum[:])}, "code_challenge_method": {"S256"}}
|
||||
expectedSeconds := 24 * 60 * 60
|
||||
if remember {
|
||||
startForm.Set("remember", "1")
|
||||
expectedSeconds *= 30
|
||||
}
|
||||
start := cliForm(s, "/_/auth/cli/start", startForm, "", "")
|
||||
if start.Code != 200 {
|
||||
t.Fatalf("start %d %s", start.Code, start.Body.String())
|
||||
}
|
||||
@@ -63,7 +77,12 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
|
||||
t.Fatalf("verify landing: %d %s", verify.Code, verify.Body.String())
|
||||
}
|
||||
begin := httptest.NewRecorder()
|
||||
s.beginOIDC(begin, httptest.NewRequest("GET", "https://localhost/_/auth/oidc?cli="+id, nil))
|
||||
// The browser query must not override the CLI's persisted choice.
|
||||
tamperedRemember := "1"
|
||||
if remember {
|
||||
tamperedRemember = "0"
|
||||
}
|
||||
s.beginOIDC(begin, httptest.NewRequest("GET", "https://localhost/_/auth/oidc?cli="+id+"&remember="+tamperedRemember, nil))
|
||||
if begin.Code != 302 {
|
||||
t.Fatalf("oidc begin %d %s", begin.Code, begin.Body.String())
|
||||
}
|
||||
@@ -86,6 +105,9 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
|
||||
for _, cookie := range complete.Result().Cookies() {
|
||||
if cookie.Name == authCookieName {
|
||||
browser = cookie.Value
|
||||
if cookie.MaxAge != expectedSeconds {
|
||||
t.Fatalf("cookie lifetime %d, want %d", cookie.MaxAge, expectedSeconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
if browser == "" {
|
||||
@@ -128,6 +150,7 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
|
||||
var result struct {
|
||||
Token string `json:"access_token"`
|
||||
Username string `json:"username"`
|
||||
Expires int `json:"expires_in"`
|
||||
}
|
||||
if err := json.Unmarshal(exchange.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -135,6 +158,9 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
|
||||
if !strings.HasPrefix(result.Token, "pw_api_") || result.Username != "admin" || result.Token == browser {
|
||||
t.Fatal("invalid delegated credential")
|
||||
}
|
||||
if result.Expires > expectedSeconds || result.Expires < expectedSeconds-10 {
|
||||
t.Fatalf("CLI lifetime %d, want approximately %d", result.Expires, expectedSeconds)
|
||||
}
|
||||
if _, err := s.store.PrincipalForSession(domain, result.Token); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type oidcChallenge struct{ Verifier, Nonce, Return, Issuer, ClientID, BrowserHash, CLIRequest string }
|
||||
type oidcChallenge struct {
|
||||
Verifier, Nonce, Return, Issuer, ClientID, BrowserHash, CLIRequest string
|
||||
Remember bool
|
||||
}
|
||||
|
||||
func logOIDCFailure(stage, domainUUID, issuer string, err error) {
|
||||
host := "invalid"
|
||||
@@ -57,6 +60,7 @@ func (s *Server) beginOIDC(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 8*time.Second)
|
||||
defer cancel()
|
||||
cliRequest := r.URL.Query().Get("cli")
|
||||
remember := r.URL.Query().Get("remember") == "1"
|
||||
returnPath := safeReturnPath(r.URL.Query().Get("return"))
|
||||
if cliRequest != "" {
|
||||
if !cliSecureTransport(r) || !cliProofPattern.MatchString(cliRequest) {
|
||||
@@ -68,6 +72,12 @@ func (s *Server) beginOIDC(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
returnPath = cliVerifyPath(cliRequest)
|
||||
grant, err := s.store.CLIAuthRequest(ctx, domainUUID, cliOrigin(r), cliRequest)
|
||||
if err != nil {
|
||||
http.Error(w, "invalid CLI request", 400)
|
||||
return
|
||||
}
|
||||
remember = grant.Remember
|
||||
}
|
||||
metadata, err := fetchOIDCMetadata(ctx, config.Issuer)
|
||||
if err != nil {
|
||||
@@ -77,7 +87,7 @@ func (s *Server) beginOIDC(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
verifier, nonce, browser := randomURLToken(32), randomURLToken(24), randomURLToken(32)
|
||||
browserDigest := sha256.Sum256([]byte(browser))
|
||||
state, err := s.store.CreateAuthChallenge(domainUUID, "", "oidc", oidcChallenge{Verifier: verifier, Nonce: nonce, Return: returnPath, Issuer: config.Issuer, ClientID: config.ClientID, BrowserHash: base64.RawURLEncoding.EncodeToString(browserDigest[:]), CLIRequest: cliRequest}, 5*time.Minute)
|
||||
state, err := s.store.CreateAuthChallenge(domainUUID, "", "oidc", oidcChallenge{Verifier: verifier, Nonce: nonce, Return: returnPath, Issuer: config.Issuer, ClientID: config.ClientID, BrowserHash: base64.RawURLEncoding.EncodeToString(browserDigest[:]), CLIRequest: cliRequest, Remember: remember}, 5*time.Minute)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
@@ -205,7 +215,7 @@ func (s *Server) completeOIDC(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "No local account matches the configured OIDC identity field", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
token, err := s.store.CreateBrowserAuthSession(domainUUID, principal.UUID, 0)
|
||||
token, lifetime, err := s.store.CreateLoginSession(domainUUID, principal.UUID, 0, true, challenge.Remember)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
@@ -217,7 +227,7 @@ func (s *Server) completeOIDC(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
s.setAuthCookie(w, r, token)
|
||||
s.setAuthCookieForSeconds(w, r, token, int(lifetime.Seconds()))
|
||||
http.Redirect(w, r, challenge.Return, http.StatusSeeOther)
|
||||
}
|
||||
|
||||
@@ -244,7 +254,7 @@ func (s *Server) requestMagicLink(w http.ResponseWriter, r *http.Request) {
|
||||
if principalErr == nil {
|
||||
select {
|
||||
case s.smtpSlots <- struct{}{}:
|
||||
token, err := s.store.CreateAuthChallenge(domainUUID, principal.UUID, "magic-link", magicLinkChallenge{Return: safeReturnPath(r.FormValue("return")), Email: principal.Email}, 15*time.Minute)
|
||||
token, err := s.store.CreateAuthChallenge(domainUUID, principal.UUID, "magic-link", magicLinkChallenge{Return: safeReturnPath(r.FormValue("return")), Email: principal.Email, Remember: r.PostForm.Get("remember") == "1"}, 15*time.Minute)
|
||||
if err != nil {
|
||||
<-s.smtpSlots
|
||||
break
|
||||
@@ -282,12 +292,12 @@ func (s *Server) verifyMagicLink(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "This sign-in link is invalid or expired", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
token, err := s.store.CreateBrowserAuthSession(domainUUID, principalUUID, 0)
|
||||
token, lifetime, err := s.store.CreateLoginSession(domainUUID, principalUUID, 0, true, payload.Remember)
|
||||
if err != nil {
|
||||
http.Error(w, "This sign-in link is invalid or expired", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
s.setAuthCookie(w, r, token)
|
||||
s.setAuthCookieForSeconds(w, r, token, int(lifetime.Seconds()))
|
||||
http.Redirect(w, r, safeReturnPath(payload.Return), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
@@ -306,6 +316,8 @@ func (s *Server) renderAuthPage(w http.ResponseWriter, r *http.Request, data map
|
||||
data["LDAPEnabled"] = config.Enabled
|
||||
}
|
||||
data["Locale"] = s.getLocale(domainUUID)
|
||||
data["TrustedSessionDays"] = s.store.TrustedSessionDays(domainUUID)
|
||||
data["RememberRequested"] = r.PostForm.Get("remember") == "1"
|
||||
transparency := s.homeGlassTransparency(domainUUID)
|
||||
data["HomeGlassTransparency"] = transparency
|
||||
data["HomeGlassOpacity"] = 100 - transparency
|
||||
|
||||
@@ -62,7 +62,11 @@ func requestIsHTTPS(r *http.Request) bool {
|
||||
}
|
||||
|
||||
func (s *Server) setAuthCookie(w http.ResponseWriter, r *http.Request, token string) {
|
||||
http.SetCookie(w, &http.Cookie{Name: authCookieName, Value: token, Path: "/", HttpOnly: true, Secure: requestIsHTTPS(r), SameSite: http.SameSiteLaxMode, MaxAge: s.store.AuthSessionLifetimeMinutes(s.domainUUIDForRequest(r)) * 60})
|
||||
s.setAuthCookieForSeconds(w, r, token, s.store.AuthSessionLifetimeMinutes(s.domainUUIDForRequest(r))*60)
|
||||
}
|
||||
|
||||
func (s *Server) setAuthCookieForSeconds(w http.ResponseWriter, r *http.Request, token string, seconds int) {
|
||||
http.SetCookie(w, &http.Cookie{Name: authCookieName, Value: token, Path: "/", HttpOnly: true, Secure: requestIsHTTPS(r), SameSite: http.SameSiteLaxMode, MaxAge: seconds})
|
||||
}
|
||||
|
||||
func (s *Server) authTokenFromRequest(r *http.Request) string {
|
||||
@@ -160,6 +164,7 @@ func (s *Server) handleAuth(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
var principal *store.Principal
|
||||
mfaLevel := 0
|
||||
remember := r.PostForm.Get("remember") == "1"
|
||||
if action == "setup" && setup && s.validBootstrapToken(domainUUID, r.FormValue("bootstrap_token")) {
|
||||
principal, err = s.store.BootstrapOwner(domainUUID, r.FormValue("username"), r.FormValue("password"), r.FormValue("display_name"), r.FormValue("email"))
|
||||
if err == nil {
|
||||
@@ -171,7 +176,7 @@ func (s *Server) handleAuth(w http.ResponseWriter, r *http.Request) {
|
||||
} else if action == "login" && !setup {
|
||||
principal, err = s.store.AuthenticatePassword(r.FormValue("username"), r.FormValue("password"))
|
||||
if err == nil && s.store.HasTOTP(principal.UUID) {
|
||||
challenge, challengeErr := s.store.CreateTOTPLoginChallenge(domainUUID, principal.UUID)
|
||||
challenge, challengeErr := s.store.CreateTOTPLoginChallengeForLogin(domainUUID, principal.UUID, remember)
|
||||
if challengeErr != nil {
|
||||
err = challengeErr
|
||||
} else if strings.Contains(r.Header.Get("Accept"), "application/json") {
|
||||
@@ -191,7 +196,7 @@ func (s *Server) handleAuth(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
var principalUUID string
|
||||
principalUUID, err = s.store.CompleteTOTPLoginChallenge(domainUUID, challenge, r.FormValue("code"))
|
||||
principalUUID, remember, err = s.store.CompleteTOTPLoginChallengeForLogin(domainUUID, challenge, r.FormValue("code"))
|
||||
if err == nil {
|
||||
principal = &store.Principal{UUID: principalUUID}
|
||||
mfaLevel = 1
|
||||
@@ -201,18 +206,14 @@ func (s *Server) handleAuth(w http.ResponseWriter, r *http.Request) {
|
||||
err = store.ErrAccessDenied
|
||||
}
|
||||
if err == nil {
|
||||
var token string
|
||||
if strings.Contains(r.Header.Get("Accept"), "application/json") {
|
||||
token, err = s.store.CreateAuthSessionWithMFA(domainUUID, principal.UUID, mfaLevel)
|
||||
} else {
|
||||
token, err = s.store.CreateBrowserAuthSession(domainUUID, principal.UUID, mfaLevel)
|
||||
}
|
||||
token, lifetime, issueErr := s.store.CreateLoginSession(domainUUID, principal.UUID, mfaLevel, !strings.Contains(r.Header.Get("Accept"), "application/json"), remember)
|
||||
err = issueErr
|
||||
if err == nil {
|
||||
if strings.Contains(r.Header.Get("Accept"), "application/json") {
|
||||
writeEventJSON(w, http.StatusOK, map[string]any{"access_token": token, "token_type": "Bearer", "expires_in": s.store.AuthSessionLifetimeMinutes(domainUUID) * 60})
|
||||
writeEventJSON(w, http.StatusOK, map[string]any{"access_token": token, "token_type": "Bearer", "expires_in": int(lifetime.Seconds())})
|
||||
return
|
||||
}
|
||||
s.setAuthCookie(w, r, token)
|
||||
s.setAuthCookieForSeconds(w, r, token, int(lifetime.Seconds()))
|
||||
http.Redirect(w, r, safeReturnPath(r.FormValue("return")), http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func (s *Server) handleLDAPLogin(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if s.store.HasTOTP(principal.UUID) {
|
||||
challenge, challengeErr := s.store.CreateTOTPLoginChallenge(domainUUID, principal.UUID)
|
||||
challenge, challengeErr := s.store.CreateTOTPLoginChallengeForLogin(domainUUID, principal.UUID, r.PostForm.Get("remember") == "1")
|
||||
if challengeErr != nil {
|
||||
http.Error(w, "authentication unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
@@ -234,20 +234,15 @@ func (s *Server) handleLDAPLogin(w http.ResponseWriter, r *http.Request) {
|
||||
s.renderAuthPage(w, r, map[string]any{"MFA": true, "Return": returnPath})
|
||||
return
|
||||
}
|
||||
var token string
|
||||
if strings.Contains(r.Header.Get("Accept"), "application/json") {
|
||||
token, err = s.store.CreateAuthSession(domainUUID, principal.UUID)
|
||||
} else {
|
||||
token, err = s.store.CreateBrowserAuthSession(domainUUID, principal.UUID, 0)
|
||||
}
|
||||
token, lifetime, err := s.store.CreateLoginSession(domainUUID, principal.UUID, 0, !strings.Contains(r.Header.Get("Accept"), "application/json"), r.PostForm.Get("remember") == "1")
|
||||
if err != nil {
|
||||
http.Error(w, "authentication unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
if strings.Contains(r.Header.Get("Accept"), "application/json") {
|
||||
writeEventJSON(w, http.StatusOK, map[string]any{"access_token": token, "token_type": "Bearer", "expires_in": s.store.AuthSessionLifetimeMinutes(domainUUID) * 60})
|
||||
writeEventJSON(w, http.StatusOK, map[string]any{"access_token": token, "token_type": "Bearer", "expires_in": int(lifetime.Seconds())})
|
||||
return
|
||||
}
|
||||
s.setAuthCookie(w, r, token)
|
||||
s.setAuthCookieForSeconds(w, r, token, int(lifetime.Seconds()))
|
||||
http.Redirect(w, r, returnPath, http.StatusSeeOther)
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSessionPolicyAdminUIAndCookie(t *testing.T) {
|
||||
@@ -48,3 +49,99 @@ func TestSessionPolicyAdminUIAndCookie(t *testing.T) {
|
||||
t.Fatalf("cookie policy %#v", cookies)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrustedSessionPolicyAndRevocation(t *testing.T) {
|
||||
s, admin, domain := configFixture(t)
|
||||
p := s.mustCLIPrincipal(t, domain, admin)
|
||||
for _, days := range []string{"30", "7", "0"} {
|
||||
form := url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {days}}
|
||||
w := configRequest(s, admin, "POST", "/-/sys/config/auth", form)
|
||||
if w.Code != 303 {
|
||||
t.Fatalf("policy %s: %d %s", days, w.Code, w.Body.String())
|
||||
}
|
||||
want := 24 * time.Hour
|
||||
if days == "30" {
|
||||
want *= 30
|
||||
}
|
||||
if days == "7" {
|
||||
want *= 7
|
||||
}
|
||||
for _, browser := range []bool{false, true} {
|
||||
token, lifetime, err := s.store.CreateLoginSession(domain, p, 0, browser, true)
|
||||
if err != nil || lifetime != want {
|
||||
t.Fatalf("duration %v %v", lifetime, err)
|
||||
}
|
||||
if _, err = s.store.PrincipalForSession(domain, token); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.RevokeAuthSession(token); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
|
||||
t.Fatal("revoked trusted session accepted")
|
||||
}
|
||||
}
|
||||
w = httptest.NewRecorder()
|
||||
s.handleAuth(w, httptest.NewRequest("GET", "https://localhost/_/auth/login", nil))
|
||||
if strings.Contains(w.Body.String(), `id="auth-remember"`) != (days != "0") {
|
||||
t.Fatal("login choice does not reflect policy")
|
||||
}
|
||||
}
|
||||
for _, bad := range []string{"", "-1", "31", "abc"} {
|
||||
w := configRequest(s, admin, "POST", "/-/sys/config/auth", url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {bad}})
|
||||
if w.Code != 400 {
|
||||
t.Fatalf("invalid policy %q accepted: %d", bad, w.Code)
|
||||
}
|
||||
}
|
||||
user, err := s.store.CreatePasswordAccount(domain, "trusted-reader", "a long test password", "Reader", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.SetConfigInDomain(domain, "auth_trusted_session_days", "30"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, _, err := s.store.CreateLoginSession(domain, user.UUID, 0, false, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := configRequest(s, token, "POST", "/-/sys/config/auth", url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {"7"}})
|
||||
if w.Code != 403 {
|
||||
t.Fatalf("reader changed trusted policy: %d", w.Code)
|
||||
}
|
||||
if err = s.store.SetPrincipalState(domain, user.UUID, "suspended"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
|
||||
t.Fatal("suspended trusted session accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrustedSessionExpiryIsFixed(t *testing.T) {
|
||||
s, admin, domain := configFixture(t)
|
||||
p := s.mustCLIPrincipal(t, domain, admin)
|
||||
token, lifetime, err := s.store.CreateLoginSession(domain, p, 0, false, true)
|
||||
if err != nil || lifetime != 30*24*time.Hour {
|
||||
t.Fatalf("trusted default: %v %v", lifetime, err)
|
||||
}
|
||||
var id string
|
||||
var expiry int64
|
||||
if err = s.store.DB.QueryRow(`SELECT uuid,expires_at_ms FROM auth_sessions ORDER BY rowid DESC LIMIT 1`).Scan(&id, &expiry); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.SetConfigInDomain(domain, "auth_trusted_session_days", "0"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.PrincipalForSession(domain, token); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var after int64
|
||||
if err = s.store.DB.QueryRow(`SELECT expires_at_ms FROM auth_sessions WHERE uuid=?`, id).Scan(&after); err != nil || after != expiry {
|
||||
t.Fatalf("policy/read changed expiry: %d %d %v", expiry, after, err)
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`UPDATE auth_sessions SET expires_at_ms=? WHERE uuid=?`, time.Now().Add(-time.Second).UnixMilli(), id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
|
||||
t.Fatal("expired trusted session accepted")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package server
|
||||
|
||||
func init() {
|
||||
for lang, entries := range map[string]map[string]string{
|
||||
"en": {"auth.remember": "Keep me signed in on this trusted device", "auth.days": "days", "auth.remember_cli": "Keep this CLI signed in for up to", "auth.trusted_days": "Trusted device session (days; 0 disables)"},
|
||||
"ja": {"auth.remember": "信頼できる端末でログインを維持する", "auth.days": "日間", "auth.remember_cli": "CLIのログイン継続期間(最大)", "auth.trusted_days": "信頼できる端末の有効期間(日・0で無効)"},
|
||||
} {
|
||||
for key, value := range entries {
|
||||
translations[lang][key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBrowserUploadQueueChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
for _, width := range []string{"1280", "390"} {
|
||||
t.Run(width, func(t *testing.T) { testBrowserUploadQueueChromium(t, width) })
|
||||
}
|
||||
}
|
||||
|
||||
func testBrowserUploadQueueChromium(t *testing.T, width string) {
|
||||
s, token, domain := configFixture(t)
|
||||
s.mux.HandleFunc("/v/browser/", s.handleBrowser)
|
||||
s.mux.HandleFunc("/v/upload", s.handleUpload)
|
||||
object, err := s.store.CreatePageAtPathInDomain(domain, "/drop/existing.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.SaveRevisionContent(object, []byte("original"), "", "und", "text/plain", "existing.txt"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.CreatePageAtPathInDomain(domain, "/drop/sub/seed"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
script, err := os.ReadFile("internal/server/testdata/browser-upload.js")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var active, peak atomic.Int32
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.Method == "POST" && r.URL.Path == "/v/upload" {
|
||||
n := active.Add(1)
|
||||
defer active.Add(-1)
|
||||
if n > peak.Load() {
|
||||
peak.Store(n)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
if r.URL.Path == "/v/browser/drop" && r.URL.Query().Has("fixture") {
|
||||
rec := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(rec, r)
|
||||
for key, values := range rec.Header() {
|
||||
w.Header()[key] = values
|
||||
}
|
||||
w.WriteHeader(rec.Code)
|
||||
w.Write([]byte(strings.Replace(rec.Body.String(), "</body>", "<script>"+string(script)+"</script></body>", 1)))
|
||||
return
|
||||
}
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
}))
|
||||
defer server.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
|
||||
defer cancel()
|
||||
out, err := exec.CommandContext(ctx, "node", "internal/server/testdata/vim-browser-smoke.mjs", server.URL+"/v/browser/drop?fixture=1", t.TempDir(), "/tmp/pageswiki-browser-upload-"+width+".png", width, "850").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("browser: %v %s", err, out)
|
||||
}
|
||||
if peak.Load() != 1 {
|
||||
t.Fatalf("parallel uploads: %d", peak.Load())
|
||||
}
|
||||
for _, path := range []string{"/drop/日本語 #1.txt", "/drop/sub/nested.txt"} {
|
||||
if _, err = s.store.ResolvePathInDomain(domain, path); err != nil {
|
||||
t.Fatal(path, err)
|
||||
}
|
||||
}
|
||||
if _, err = s.store.ResolvePathInDomain(domain, "/drop/cancel.txt"); err == nil {
|
||||
t.Fatal("cancelled file uploaded")
|
||||
}
|
||||
revs, err := s.store.ListRevisions(object)
|
||||
if err != nil || len(revs) != 1 {
|
||||
t.Fatal("existing file overwritten")
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (s *Server) transpileMarkdownFromPath(r *http.Request, path string, mode ma
|
||||
|
||||
html := latest.Body
|
||||
if mode == markdownProjection {
|
||||
html = s.expandMacrosForRequest(r, html, path, s.domainUUIDForRequest(r))
|
||||
html = s.safeHTMLProjection(r, html, path, true)
|
||||
} else {
|
||||
return grammaratur.HTMLToMarkdownAuthoring(html)
|
||||
}
|
||||
|
||||
@@ -1078,49 +1078,50 @@ func (s *Server) handleConfig(
|
||||
s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
||||
NavContext{},
|
||||
),
|
||||
"HomePath": homePath,
|
||||
"HomeWallpaperPath": homeWallpaperPath,
|
||||
"HomeWallpaperOpacity": homeWallpaperOpacity,
|
||||
"HomeGlassTransparency": s.homeGlassTransparency(domainUUID),
|
||||
"HomePalette": s.homePalette(domainUUID),
|
||||
"HomeLayout": s.homeLayout(s.domainUUIDForRequest(r)),
|
||||
"HomeBookmarks": s.homeBookmarksText(s.domainUUIDForRequest(r)),
|
||||
"VirtualFolderPages": s.getVirtualFolderPages(s.domainUUIDForRequest(r)),
|
||||
"WikiName": wikiName,
|
||||
"Locale": s.getLocale(s.domainUUIDForRequest(r)),
|
||||
"Timezone": s.getTimezoneName(s.domainUUIDForRequest(r)),
|
||||
"Theme": s.getTheme(s.domainUUIDForRequest(r)),
|
||||
"ThemeOptions": themeOptions(),
|
||||
"EditorKeymap": s.getEditorKeymap(s.domainUUIDForRequest(r)),
|
||||
"EditorFormat": s.getEditorFormat(s.domainUUIDForRequest(r)),
|
||||
"EditorPreviewDefault": s.getEditorPreviewDefault(s.domainUUIDForRequest(r)),
|
||||
"EditorSyntax": s.getEditorSyntaxHighlight(s.domainUUIDForRequest(r)),
|
||||
"EditorAutocomplete": s.getEditorAutocomplete(s.domainUUIDForRequest(r)),
|
||||
"ZombieGraceHours": zombieGraceHours,
|
||||
"Objects": recent,
|
||||
"ZombieObjects": zombies,
|
||||
"Domains": domains,
|
||||
"DomainEntries": domainEntries,
|
||||
"PeriodicalProjections": projections,
|
||||
"PeriodicalKinds": []string{"diary", "blog"},
|
||||
"CampusLegacyPeers": legacyPeers,
|
||||
"Campuses": campuses,
|
||||
"CampusManaged": campusManaged,
|
||||
"CampusOnline": campusOnline,
|
||||
"FederationInstances": federationInstances,
|
||||
"CampusTokens": campusTokens,
|
||||
"AuthPrincipals": authPrincipals,
|
||||
"AuthSessions": authSessions,
|
||||
"AuthSessionMinutes": s.store.AuthSessionLifetimeMinutes(s.domainUUIDForRequest(r)),
|
||||
"OIDCConfig": oidcConfig,
|
||||
"SMTPConfig": smtpConfig,
|
||||
"LDAPConfig": ldapConfig,
|
||||
"LDAPTest": r.URL.Query().Get("ldap_test"),
|
||||
"ObjectsCampusUUID": selectedCampusUUID,
|
||||
"ObjectsDomainUUID": selectedDomain.UUID,
|
||||
"ObjectsDomainHost": objectsDomainHost,
|
||||
"HomeNavItemsConfig": s.getHomeNavItems(s.domainUUIDForRequest(r)),
|
||||
"SystemNavItemsConfig": s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
||||
"HomePath": homePath,
|
||||
"HomeWallpaperPath": homeWallpaperPath,
|
||||
"HomeWallpaperOpacity": homeWallpaperOpacity,
|
||||
"HomeGlassTransparency": s.homeGlassTransparency(domainUUID),
|
||||
"HomePalette": s.homePalette(domainUUID),
|
||||
"HomeLayout": s.homeLayout(s.domainUUIDForRequest(r)),
|
||||
"HomeBookmarks": s.homeBookmarksText(s.domainUUIDForRequest(r)),
|
||||
"VirtualFolderPages": s.getVirtualFolderPages(s.domainUUIDForRequest(r)),
|
||||
"WikiName": wikiName,
|
||||
"Locale": s.getLocale(s.domainUUIDForRequest(r)),
|
||||
"Timezone": s.getTimezoneName(s.domainUUIDForRequest(r)),
|
||||
"Theme": s.getTheme(s.domainUUIDForRequest(r)),
|
||||
"ThemeOptions": themeOptions(),
|
||||
"EditorKeymap": s.getEditorKeymap(s.domainUUIDForRequest(r)),
|
||||
"EditorFormat": s.getEditorFormat(s.domainUUIDForRequest(r)),
|
||||
"EditorPreviewDefault": s.getEditorPreviewDefault(s.domainUUIDForRequest(r)),
|
||||
"EditorSyntax": s.getEditorSyntaxHighlight(s.domainUUIDForRequest(r)),
|
||||
"EditorAutocomplete": s.getEditorAutocomplete(s.domainUUIDForRequest(r)),
|
||||
"ZombieGraceHours": zombieGraceHours,
|
||||
"Objects": recent,
|
||||
"ZombieObjects": zombies,
|
||||
"Domains": domains,
|
||||
"DomainEntries": domainEntries,
|
||||
"PeriodicalProjections": projections,
|
||||
"PeriodicalKinds": []string{"diary", "blog"},
|
||||
"CampusLegacyPeers": legacyPeers,
|
||||
"Campuses": campuses,
|
||||
"CampusManaged": campusManaged,
|
||||
"CampusOnline": campusOnline,
|
||||
"FederationInstances": federationInstances,
|
||||
"CampusTokens": campusTokens,
|
||||
"AuthPrincipals": authPrincipals,
|
||||
"AuthSessions": authSessions,
|
||||
"AuthSessionMinutes": s.store.AuthSessionLifetimeMinutes(s.domainUUIDForRequest(r)),
|
||||
"AuthTrustedSessionDays": s.store.TrustedSessionDays(s.domainUUIDForRequest(r)),
|
||||
"OIDCConfig": oidcConfig,
|
||||
"SMTPConfig": smtpConfig,
|
||||
"LDAPConfig": ldapConfig,
|
||||
"LDAPTest": r.URL.Query().Get("ldap_test"),
|
||||
"ObjectsCampusUUID": selectedCampusUUID,
|
||||
"ObjectsDomainUUID": selectedDomain.UUID,
|
||||
"ObjectsDomainHost": objectsDomainHost,
|
||||
"HomeNavItemsConfig": s.getHomeNavItems(s.domainUUIDForRequest(r)),
|
||||
"SystemNavItemsConfig": s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"html"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const csvEditorFixtureBody = "\ufeff\"name\",description\r\n日本語,\"a,b\r\nnext\"\r\n"
|
||||
|
||||
func TestCSVEditorRevisionAndBounds(t *testing.T) {
|
||||
s, token, domain, _ := editorFixture(t)
|
||||
object, err := s.store.CreatePageAtPathInDomain(domain, "/table.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
first, err := s.store.SaveRevisionContent(object, []byte(csvEditorFixtureBody), "", "und", "text/csv; charset=utf-8", "table.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, query := range []string{"", "?edittype=markdown", "?lang=und"} {
|
||||
w := configRequest(s, token, "GET", "/e/-/table.csv"+query, nil)
|
||||
if w.Code != 200 || !strings.Contains(w.Body.String(), `data-csv="true"`) || !strings.Contains(w.Body.String(), `value="code"`) || strings.Contains(w.Body.String(), `data-editor-action="markdown"`) {
|
||||
t.Fatalf("editor %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
head, _ := s.store.GetRevisionForExactLanguage(object, "und")
|
||||
if head.UUID != first.UUID {
|
||||
t.Fatal("GET changed revision")
|
||||
}
|
||||
save := func(auth, base, body string) int {
|
||||
data, _ := json.Marshal(map[string]any{"object_uuid": object, "body": body, "lang": "und", "content_type": "text/csv; charset=utf-8", "filename": "table.csv", "base_revision_uuid": base})
|
||||
r := httptest.NewRequest("POST", "http://localhost/_/api/v1/revisions/save", bytes.NewReader(data))
|
||||
r.Header.Set("Authorization", "Bearer "+auth)
|
||||
r.Header.Set("Content-Type", "application/json")
|
||||
w := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
return w.Code
|
||||
}
|
||||
changed := strings.Replace(csvEditorFixtureBody, "日本語", "更新", 1)
|
||||
if code := save(token, first.UUID, changed); code != 200 {
|
||||
t.Fatal("save", code)
|
||||
}
|
||||
if code := save(token, first.UUID, "stale"); code != 409 {
|
||||
t.Fatal("stale save", code)
|
||||
}
|
||||
head, _ = s.store.GetRevisionForExactLanguage(object, "und")
|
||||
if head.Body != changed || head.ContentType != "text/csv; charset=utf-8" || head.Filename != "table.csv" {
|
||||
t.Fatal("CSV altered")
|
||||
}
|
||||
state := configRequest(s, token, "GET", "/_/api/v1/editor/state?uuid="+object+"&lang=und&revision="+first.UUID, nil)
|
||||
var content struct {
|
||||
Body string
|
||||
Editable bool
|
||||
}
|
||||
if err = json.Unmarshal(state.Body.Bytes(), &content); err != nil || state.Code != 200 || !content.Editable || content.Body != csvEditorFixtureBody {
|
||||
t.Fatal("restore", state.Code, err)
|
||||
}
|
||||
reader, err := s.store.CreatePasswordAccount(domain, "csvreader", "a long test password", "Reader", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.SetPrincipalState(domain, reader.UUID, "readonly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
denied, _ := s.store.CreateAuthSession(domain, reader.UUID)
|
||||
if code := save(denied, head.UUID, "forbidden"); code != 403 {
|
||||
t.Fatal("readonly save", code)
|
||||
}
|
||||
// Initial CSV is embedded as an escaped JS string to preserve CRLF. A
|
||||
// field must not terminate that script or become executable markup.
|
||||
if _, err = s.store.SaveRevisionContent(object, []byte("\"</script><script>alert(1)</script>\",value\r\n"), "", "und", "text/csv", "table.csv"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
escaped := configRequest(s, token, "GET", "/e/-/table.csv", nil)
|
||||
if escaped.Code != 200 || strings.Contains(escaped.Body.String(), "<script>alert(1)</script>") || !strings.Contains(escaped.Body.String(), `\u003c/script\u003e`) {
|
||||
t.Fatal("CSV script string was not escaped")
|
||||
}
|
||||
for _, input := range []struct {
|
||||
body []byte
|
||||
code int
|
||||
}{{[]byte(strings.Repeat("x", maxCSVMacroBytes+1)), 413}, {[]byte{0xff, 0xfe}, 415}, {[]byte("a,\x00"), 415}} {
|
||||
rev, e := s.store.SaveRevisionContent(object, input.body, "", "und", "text/csv", "table.csv")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
w := configRequest(s, token, "GET", "/e/-/table.csv", nil)
|
||||
if w.Code != input.code {
|
||||
t.Fatalf("editor bounds %d wanted %d", w.Code, input.code)
|
||||
}
|
||||
w = configRequest(s, token, "GET", "/_/api/v1/editor/state?uuid="+object+"&lang=und&revision="+rev.UUID, nil)
|
||||
if w.Code != input.code {
|
||||
t.Fatalf("state bounds %d wanted %d", w.Code, input.code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCSVEditorChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
for _, width := range []string{"1280", "390"} {
|
||||
t.Run(width, func(t *testing.T) {
|
||||
s, token, domain, _ := editorFixture(t)
|
||||
object, err := s.store.CreatePageAtPathInDomain(domain, "/table.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.SaveRevisionContent(object, []byte(csvEditorFixtureBody), "", "und", "text/csv; charset=utf-8", "table.csv"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
script, err := os.ReadFile("internal/server/testdata/csv-editor.js")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.URL.Path == "/e/-/table.csv" {
|
||||
rec := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(rec, r)
|
||||
for k, v := range rec.Header() {
|
||||
w.Header()[k] = v
|
||||
}
|
||||
w.WriteHeader(rec.Code)
|
||||
_, policy, _ := strings.Cut(rec.Header().Get("Content-Security-Policy"), "'nonce-")
|
||||
nonce, _, _ := strings.Cut(policy, "'")
|
||||
w.Write([]byte(strings.Replace(rec.Body.String(), "</body>", `<script nonce="`+html.EscapeString(nonce)+`">`+string(script)+"</script></body>", 1)))
|
||||
return
|
||||
}
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
}))
|
||||
defer server.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
||||
defer cancel()
|
||||
out, err := exec.CommandContext(ctx, "node", "internal/server/testdata/vim-browser-smoke.mjs", server.URL+"/e/-/table.csv", t.TempDir(), "/tmp/pageswiki-csv-editor-"+width+".png", width, "850").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("browser: %v %s", err, out)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"html"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Projection only: no network fetch, shared rendered cache or write-back.
|
||||
const maxCSVMacroBytes = 256 << 10
|
||||
|
||||
var csvMacroRE = regexp.MustCompile(`^\{\{csv:(?:"([^"]+)"|([^\s}]+))(.*?)\}\}$`)
|
||||
var csvRangeRE = regexp.MustCompile(`^([A-Z]{1,2})([1-9][0-9]{0,3}):([A-Z]{1,2})([1-9][0-9]{0,3})$`)
|
||||
|
||||
type csvMacroOptions struct {
|
||||
Path, Revision string
|
||||
Row, EndRow, Column, EndColumn int
|
||||
Header bool
|
||||
}
|
||||
|
||||
func parseCSVMacro(raw string) (csvMacroOptions, error) {
|
||||
o := csvMacroOptions{Row: 1, EndRow: 200, Column: 1, EndColumn: 32, Header: true}
|
||||
m := csvMacroRE.FindStringSubmatch(raw)
|
||||
bad := errors.New("invalid CSV macro")
|
||||
if m == nil {
|
||||
return o, bad
|
||||
}
|
||||
o.Path = m[1]
|
||||
if o.Path == "" {
|
||||
o.Path = m[2]
|
||||
}
|
||||
if !strings.HasPrefix(o.Path, "/") || strings.HasPrefix(o.Path, "//") || path.Clean(o.Path) != o.Path || strings.ContainsAny(o.Path, "\\\x00\r\n") || len(o.Path) > 2048 {
|
||||
return o, bad
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, field := range strings.Fields(m[3]) {
|
||||
key, value, ok := strings.Cut(field, "=")
|
||||
if !ok || seen[key] {
|
||||
return o, bad
|
||||
}
|
||||
seen[key] = true
|
||||
switch key {
|
||||
case "header":
|
||||
if value != "true" && value != "false" {
|
||||
return o, bad
|
||||
}
|
||||
o.Header = value == "true"
|
||||
case "rev":
|
||||
if _, err := uuid.Parse(value); len(value) != 36 || err != nil {
|
||||
return o, bad
|
||||
}
|
||||
o.Revision = value
|
||||
case "range":
|
||||
parts := csvRangeRE.FindStringSubmatch(strings.ToUpper(value))
|
||||
if parts == nil {
|
||||
return o, bad
|
||||
}
|
||||
col := func(s string) int {
|
||||
n := 0
|
||||
for _, c := range s {
|
||||
n = n*26 + int(c-'A') + 1
|
||||
}
|
||||
return n
|
||||
}
|
||||
o.Column, o.EndColumn = col(parts[1]), col(parts[3])
|
||||
o.Row, _ = strconv.Atoi(parts[2])
|
||||
o.EndRow, _ = strconv.Atoi(parts[4])
|
||||
if o.Column > o.EndColumn || o.EndColumn > 100 || o.EndColumn-o.Column >= 32 || o.Row > o.EndRow || o.EndRow > 2000 || o.EndRow-o.Row >= 200 {
|
||||
return o, bad
|
||||
}
|
||||
default:
|
||||
return o, bad
|
||||
}
|
||||
}
|
||||
return o, nil
|
||||
}
|
||||
|
||||
func csvMacroTable(body []byte, o csvMacroOptions) (string, error) {
|
||||
if len(body) > maxCSVMacroBytes || !utf8.Valid(body) || strings.IndexByte(string(body), 0) >= 0 {
|
||||
return "", errors.New("invalid CSV input")
|
||||
}
|
||||
reader := csv.NewReader(strings.NewReader(strings.TrimPrefix(string(body), "\ufeff")))
|
||||
reader.FieldsPerRecord = -1
|
||||
var out strings.Builder
|
||||
out.WriteString(`<div class="csv-projection table-scroll"><table><caption><a href="` + html.EscapeString((&url.URL{Path: o.Path}).EscapedPath()) + `" title="Revision ` + html.EscapeString(o.Revision) + `">` + html.EscapeString(path.Base(o.Path)) + `</a></caption><tbody>`)
|
||||
for row := 1; row <= o.EndRow; row++ {
|
||||
record, err := reader.Read()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(record) > 100 {
|
||||
return "", errors.New("too many CSV columns")
|
||||
}
|
||||
if row < o.Row {
|
||||
continue
|
||||
}
|
||||
out.WriteString("<tr>")
|
||||
cell := "td"
|
||||
if o.Header && row == o.Row {
|
||||
cell = "th"
|
||||
}
|
||||
for col := o.Column; col <= o.EndColumn && col <= len(record); col++ {
|
||||
if len(record[col-1]) > 16<<10 {
|
||||
return "", errors.New("CSV cell too large")
|
||||
}
|
||||
// Never expand macros, formulas or markup from CSV cells.
|
||||
out.WriteString("<" + cell + ">" + html.EscapeString(record[col-1]) + "</" + cell + ">")
|
||||
}
|
||||
out.WriteString("</tr>")
|
||||
}
|
||||
out.WriteString("</tbody></table></div>")
|
||||
return out.String(), nil
|
||||
}
|
||||
|
||||
func (s *Server) expandCSVMacro(r *http.Request, macro string) string {
|
||||
fallback := `<span class="projection-warning">` + html.EscapeString(translate(s.getLocale(s.domainUUIDForRequest(r)), "viewer.csv_unavailable")) + `</span>`
|
||||
o, err := parseCSVMacro(macro)
|
||||
if err != nil || r.Context().Err() != nil || s.store == nil || isAnonymousProjection(r) || !s.pathReadFilter(r)(o.Path) {
|
||||
return fallback
|
||||
}
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
object, err := s.store.ResolvePathInDomainContext(r.Context(), domain, o.Path)
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
rev, err := s.store.GetLatestRevisionMetadataForLanguagesContext(r.Context(), object, s.revisionLanguageCandidates(r))
|
||||
if o.Revision != "" {
|
||||
rev, err = s.store.GetRevisionMetadataContext(r.Context(), o.Revision)
|
||||
}
|
||||
if err != nil || rev == nil || rev.UUID == "" || rev.ObjectUUID != object {
|
||||
return fallback
|
||||
}
|
||||
media := strings.ToLower(strings.TrimSpace(strings.Split(rev.ContentType, ";")[0]))
|
||||
if media != "text/csv" && media != "application/csv" {
|
||||
return fallback
|
||||
}
|
||||
size, err := s.store.DocumentSizeContext(r.Context(), rev.DocumentHash)
|
||||
if err != nil || size > maxCSVMacroBytes {
|
||||
return fallback
|
||||
}
|
||||
window, err := s.store.ReadDocumentWindowContext(r.Context(), rev.DocumentHash, 0, maxCSVMacroBytes)
|
||||
if err != nil || window.Truncated {
|
||||
return fallback
|
||||
}
|
||||
o.Revision = rev.UUID
|
||||
table, err := csvMacroTable(window.Data, o)
|
||||
if err != nil || r.Context().Err() != nil {
|
||||
return fallback
|
||||
}
|
||||
return table
|
||||
}
|
||||
|
||||
func init() {
|
||||
translations["en"]["viewer.csv_unavailable"] = "CSV unavailable (access, format or size limit)."
|
||||
translations["ja"]["viewer.csv_unavailable"] = "CSVを表示できません(権限・形式・サイズ制限)。"
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"pageswiki/internal/grammaratur"
|
||||
)
|
||||
|
||||
func TestCSVMacroParsingAndBounds(t *testing.T) {
|
||||
for _, raw := range []string{`{{csv:/data/a.csv}}`, `{{csv:"/data/日本語 table.csv" range=B2:D4 header=false}}`} {
|
||||
if _, err := parseCSVMacro(raw); err != nil {
|
||||
t.Fatal(raw, err)
|
||||
}
|
||||
}
|
||||
for _, raw := range []string{`{{csv:https://example.org/a.csv}}`, `{{csv://evil/a.csv}}`, `{{csv:/a/../secret}}`, `{{csv:/a range=A1:C201}}`, `{{csv:/a range=A1:AG2}}`, `{{csv:/a range=A2001:B2002}}`, `{{csv:/a range=D2:A1}}`, `{{csv:/a header=yes}}`, `{{csv:/a header=true header=false}}`, `{{csv:/a unsupported=1}}`, `{{csv:/a rev=bad}}`} {
|
||||
if _, err := parseCSVMacro(raw); err == nil {
|
||||
t.Fatal("accepted", raw)
|
||||
}
|
||||
}
|
||||
o, _ := parseCSVMacro(`{{csv:/data/a.csv range=A1:C3}}`)
|
||||
body := "\ufeffname,description,formula\r\n日本語,\"a,b\r\nnext\",=1+1\r\n<script>,{{children:/private}},end\r\n"
|
||||
got, err := csvMacroTable([]byte(body), o)
|
||||
if err != nil || !strings.Contains(got, "<th>name</th>") || !strings.Contains(got, "a,b\nnext") || !strings.Contains(got, "<script>") || !strings.Contains(got, "{{children:/private}}") {
|
||||
t.Fatalf("CSV: %s %v", got, err)
|
||||
}
|
||||
checkInertProjection(t, got)
|
||||
for _, bad := range [][]byte{[]byte("a,\"unterminated"), {0xff}, []byte("a,\x00"), []byte(strings.Repeat("x", maxCSVMacroBytes+1)), []byte(strings.Repeat("x", (16<<10)+1)), []byte(strings.Repeat("a,", 101))} {
|
||||
if _, err := csvMacroTable(bad, o); err == nil {
|
||||
t.Fatal("invalid/large CSV accepted")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCSVMacroProjectionAuthorizationAndRevision(t *testing.T) {
|
||||
s, token, domain := configFixture(t)
|
||||
object, err := s.store.CreatePageAtPathInDomain(domain, "/data/report.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
first, err := s.store.SaveRevisionContent(object, []byte("name,value\r\noriginal,1\r\n"), "", "und", "text/csv", "report.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := httptest.NewRequest("GET", "http://localhost/guide", nil)
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
macro := `{{csv:/data/report.csv range=A1:B2}}`
|
||||
got := s.safeHTMLProjection(r, "<p>"+macro+"</p><code>"+macro+"</code>", "/guide", true)
|
||||
if strings.Count(got, `class="csv-projection table-scroll"`) != 1 || !strings.Contains(got, "original") || !strings.Contains(got, "<code>"+macro+"</code>") || !strings.Contains(got, first.UUID) {
|
||||
t.Fatal(got)
|
||||
}
|
||||
second, err := s.store.SaveRevisionContent(object, []byte("name,value\nupdated,2\n"), "", "und", "text/csv", "report.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got = s.safeHTMLProjection(r, macro, "/guide", true)
|
||||
if !strings.Contains(got, "updated") || !strings.Contains(got, second.UUID) || strings.Contains(got, "original") {
|
||||
t.Fatal("stale projection", got)
|
||||
}
|
||||
got = s.safeHTMLProjection(r, `{{csv:/data/report.csv rev=`+first.UUID+`}}`, "/guide", true)
|
||||
if !strings.Contains(got, "original") || strings.Contains(got, "updated") {
|
||||
t.Fatal("pinned revision", got)
|
||||
}
|
||||
other, err := s.store.CreatePageAtPathInDomain(domain, "/data/other.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foreign, err := s.store.SaveRevisionContent(other, []byte("SECRET_DIFFERENT_OBJECT"), "", "und", "text/csv", "other.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got = s.safeHTMLProjection(r, `{{csv:/data/report.csv rev=`+foreign.UUID+`}}`, "/guide", true)
|
||||
if strings.Contains(got, "SECRET") || strings.Contains(got, "<table") {
|
||||
t.Fatal("foreign revision leaked", got)
|
||||
}
|
||||
// A fresh request with no credentials must not reuse another reader's table.
|
||||
denied := httptest.NewRequest("GET", "http://localhost/guide", nil)
|
||||
got = s.safeHTMLProjection(denied, macro, "/guide", true)
|
||||
if strings.Contains(got, "updated") || strings.Contains(got, "<table") {
|
||||
t.Fatal("unauthorized table", got)
|
||||
}
|
||||
public := r.WithContext(context.WithValue(r.Context(), anonymousProjectionKey{}, true))
|
||||
if got = s.safeHTMLProjection(public, macro, "/guide", true); strings.Contains(got, "<table") {
|
||||
t.Fatal("anonymous CSV expanded", got)
|
||||
}
|
||||
ctx, cancel := context.WithCancel(r.Context())
|
||||
cancel()
|
||||
if got = s.expandCSVMacro(r.WithContext(ctx), macro); strings.Contains(got, "<table") {
|
||||
t.Fatal("cancelled projection ran")
|
||||
}
|
||||
// Authoring must preserve the macro, never bake projected rows into HTML.
|
||||
source := "<p>" + macro + "</p>"
|
||||
md, err := grammaratur.HTMLToMarkdownAuthoring(source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(grammaratur.MarkdownAuthoringHTML(md), macro) || strings.Contains(md, "updated") {
|
||||
t.Fatal("authoring expanded CSV", md)
|
||||
}
|
||||
// Four distinct CSV reads per projection, then leave authored syntax literal.
|
||||
input := strings.Repeat(macro, 2)
|
||||
for _, col := range []string{"A1:A2", "B1:B2", "A1:B1", "A2:B2"} {
|
||||
input += `{{csv:/data/report.csv range=` + col + `}}`
|
||||
}
|
||||
got = s.safeHTMLProjection(r, input, "/guide", true)
|
||||
if strings.Count(got, "<table>") != 5 || !strings.Contains(got, "{{csv:") {
|
||||
t.Fatal("CSV budget not enforced", got)
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package server
|
||||
|
||||
func init() {
|
||||
for lang, entries := range map[string]map[string]string{
|
||||
"en": {"editor.tools": "Insert component / drafts", "editor.language": "Edit / fork language", "editor.restore": "Restore a revision into the editor"},
|
||||
"ja": {"editor.tools": "コンポーネント挿入・下書き", "editor.language": "言語の編集・分岐", "editor.restore": "過去のリビジョンをエディタに復元"},
|
||||
"en": {"editor.tools": "Insert component / drafts", "editor.language": "Edit / fork language", "editor.restore": "Restore a revision into the editor", "editor.csv_source": "CSV source", "editor.csv_table": "CSV table"},
|
||||
"ja": {"editor.tools": "コンポーネント挿入・下書き", "editor.language": "言語の編集・分岐", "editor.restore": "過去のリビジョンをエディタに復元", "editor.csv_source": "CSVソースを表示", "editor.csv_table": "CSVの表を表示"},
|
||||
} {
|
||||
for key, value := range entries {
|
||||
translations[lang][key] = value
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"pageswiki/internal/grammaratur"
|
||||
)
|
||||
@@ -73,7 +74,20 @@ func (s *Server) handleEditorState(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
out := map[string]any{"revision_uuid": rev.UUID, "head_revision_uuid": head, "lang": rev.Language, "content_type": rev.ContentType, "filename": rev.Filename, "principal_uuid": owner}
|
||||
if r.URL.Query().Get("metadata") != "1" {
|
||||
if rev.UUID != "" {
|
||||
csv := selectProjectionAdapter(contentDescriptor{MediaType: strings.ToLower(strings.TrimSpace(strings.Split(rev.ContentType, ";")[0])), Filename: rev.Filename}).Kind == "csv"
|
||||
if csv {
|
||||
size, e := s.store.DocumentSizeContext(r.Context(), rev.DocumentHash)
|
||||
if e != nil || size > maxCSVMacroBytes {
|
||||
http.Error(w, "CSV editor size limit exceeded", 413)
|
||||
return
|
||||
}
|
||||
window, e := s.store.ReadDocumentWindowContext(r.Context(), rev.DocumentHash, 0, maxCSVMacroBytes)
|
||||
if e != nil || window.Truncated || !utf8.Valid(window.Data) || strings.ContainsRune(string(window.Data), 0) {
|
||||
http.Error(w, "CSV source unavailable or not UTF-8", 415)
|
||||
return
|
||||
}
|
||||
rev.Body = string(window.Data)
|
||||
} else if rev.UUID != "" {
|
||||
rev, err = s.store.GetRevision(rev.UUID)
|
||||
}
|
||||
if err != nil {
|
||||
@@ -90,7 +104,7 @@ func (s *Server) handleEditorState(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
out["body"], out["markdown"] = rev.Body, markdown
|
||||
kind := revisionContentView(rev, "").Kind
|
||||
out["editable"] = rev.UUID == "" || kind == "html" || kind == "code"
|
||||
out["editable"] = rev.UUID == "" || kind == "html" || kind == "code" || (csv && utf8.ValidString(rev.Body) && !strings.ContainsRune(rev.Body, 0))
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(out)
|
||||
}
|
||||
@@ -189,7 +189,7 @@ func readEndpointResolver(path string) (endpointTargetResolver, string) {
|
||||
return resolveHandler, "read"
|
||||
case strings.HasPrefix(path, "/_/view/print/"):
|
||||
return resolvePrint, "read"
|
||||
case strings.HasPrefix(path, "/v/preview"), strings.HasPrefix(path, "/v/plain"), strings.HasPrefix(path, "/v/markdown"):
|
||||
case strings.HasPrefix(path, "/v/preview"), strings.HasPrefix(path, "/v/plain"), strings.HasPrefix(path, "/v/markdown"), path == "/v/slides", strings.HasPrefix(path, "/v/slides/"):
|
||||
return resolveViewPath, "read"
|
||||
case strings.HasPrefix(path, "/o/e/"):
|
||||
return resolveObjectURL, "write"
|
||||
|
||||
@@ -268,7 +268,7 @@ func objectIDFromRoute(path string) string {
|
||||
}
|
||||
|
||||
func semanticViewPath(route string) string {
|
||||
for _, prefix := range []string{"/v/preview", "/v/plain", "/v/markdown", "/v/browser"} {
|
||||
for _, prefix := range []string{"/v/preview", "/v/plain", "/v/markdown", "/v/browser", "/v/slides"} {
|
||||
if strings.HasPrefix(route, prefix) {
|
||||
path := strings.TrimPrefix(route, prefix)
|
||||
if path == "" {
|
||||
|
||||
@@ -10,16 +10,26 @@ import (
|
||||
const systemExtensionStateKey = "system_extension_states"
|
||||
|
||||
func (s *Server) systemExtensionEnabled(domainUUID, id string) bool {
|
||||
defaultEnabled := true
|
||||
for _, manifest := range systemext.Catalog() {
|
||||
if manifest.ID == id {
|
||||
defaultEnabled = manifest.Enabled
|
||||
break
|
||||
}
|
||||
}
|
||||
raw, err := s.store.GetConfigInDomain(domainUUID, systemExtensionStateKey)
|
||||
if err != nil || strings.TrimSpace(raw) == "" {
|
||||
return true
|
||||
return defaultEnabled
|
||||
}
|
||||
var states map[string]bool
|
||||
if json.Unmarshal([]byte(raw), &states) != nil {
|
||||
return true
|
||||
return defaultEnabled
|
||||
}
|
||||
enabled, ok := states[id]
|
||||
return !ok || enabled
|
||||
if !ok {
|
||||
return defaultEnabled
|
||||
}
|
||||
return enabled
|
||||
}
|
||||
|
||||
func (s *Server) setSystemExtensionEnabled(domainUUID, id string, enabled bool) error {
|
||||
|
||||
@@ -17,7 +17,8 @@ func feedRoute(p string) bool { return p == "/v/feeds" || strings.HasPrefix(p, f
|
||||
func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
if !s.systemExtensionEnabled(domain, "organizer.feeds") {
|
||||
licenseDownload := strings.HasPrefix(r.URL.Path, geckoAPI+"distribution/v0.0.1/")
|
||||
if !licenseDownload && !s.systemExtensionEnabled(domain, "organizer.feeds") {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
@@ -30,6 +31,10 @@ func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, geckoAPI) {
|
||||
s.handleFeedBrowser(w, r, domain, actor, active)
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/v/feeds" {
|
||||
if r.Method != "GET" && r.Method != "HEAD" {
|
||||
w.WriteHeader(405)
|
||||
@@ -50,7 +55,14 @@ func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
prefix = preferences.WikiPrefix
|
||||
linkMode = preferences.RSSLinkMode
|
||||
}
|
||||
s.renderWithContext(w, r, "feeds.gohtml", map[string]any{"Title": "RSS", "FeedWritable": active, "FeedWikiPrefix": prefix, "FeedLinkMode": linkMode, "FeedShareX": s.systemExtensionEnabled(domain, "sharing.x")})
|
||||
if linkMode == "gecko" {
|
||||
if active && s.geckoAvailable(domain) {
|
||||
geckoIsolation(w)
|
||||
} else {
|
||||
linkMode = "tab"
|
||||
}
|
||||
}
|
||||
s.renderWithContext(w, r, "feeds.gohtml", map[string]any{"Title": "RSS", "FeedTimezone": s.getTimezoneName(domain), "FeedWritable": active, "FeedWikiPrefix": prefix, "FeedLinkMode": linkMode, "FeedShareX": s.systemExtensionEnabled(domain, "sharing.x")})
|
||||
return
|
||||
}
|
||||
key := strings.TrimPrefix(r.URL.Path, feedsAPI)
|
||||
|
||||
@@ -21,6 +21,10 @@ func TestRSSLinkPreference(t *testing.T) {
|
||||
if err != nil || p.RSSLinkMode != "embedded" {
|
||||
t.Fatal(p.RSSLinkMode, err)
|
||||
}
|
||||
p.RSSLinkMode = "gecko"
|
||||
if w := taskRequest(s, token, "PUT", "preferences", p, ""); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
p.RSSLinkMode = "unsafe"
|
||||
if w := taskRequest(s, token, "PUT", "preferences", p, ""); w.Code != 422 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"pageswiki/internal/geckorelay"
|
||||
)
|
||||
|
||||
const geckoAPI = feedsAPI + "browser/"
|
||||
|
||||
type geckoProxy struct {
|
||||
origin *url.URL
|
||||
key string
|
||||
transport *http.Transport
|
||||
}
|
||||
|
||||
func (s *Server) geckoConfig() *geckoProxy {
|
||||
s.geckoOnce.Do(func() {
|
||||
u, err := url.Parse(os.Getenv("PAGESWIKI_GECKO_RELAY"))
|
||||
if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" || u.User != nil || u.RawQuery != "" || u.Fragment != "" || (u.Path != "" && u.Path != "/") {
|
||||
return
|
||||
}
|
||||
key, err := os.ReadFile(os.Getenv("PAGESWIKI_GECKO_KEY_FILE"))
|
||||
if err != nil || len(strings.TrimSpace(string(key))) < 32 {
|
||||
return
|
||||
}
|
||||
s.gecko = &geckoProxy{origin: u, key: strings.TrimSpace(string(key)), transport: &http.Transport{Proxy: nil, DialContext: (&net.Dialer{Timeout: 5 * time.Second}).DialContext, ResponseHeaderTimeout: 10 * time.Second, TLSHandshakeTimeout: 5 * time.Second, IdleConnTimeout: 30 * time.Second, MaxIdleConnsPerHost: 4}}
|
||||
})
|
||||
return s.gecko
|
||||
}
|
||||
|
||||
func (s *Server) geckoAvailable(domain string) bool {
|
||||
return s.systemExtensionEnabled(domain, "viewer.gecko") && s.geckoConfig() != nil
|
||||
}
|
||||
|
||||
func geckoIsolation(w http.ResponseWriter) {
|
||||
w.Header().Set("Cross-Origin-Opener-Policy", "same-origin")
|
||||
w.Header().Set("Cross-Origin-Embedder-Policy", "require-corp")
|
||||
w.Header().Set("Cross-Origin-Resource-Policy", "same-origin")
|
||||
}
|
||||
|
||||
func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domain, actor string, active bool) {
|
||||
path := strings.TrimPrefix(r.URL.Path, geckoAPI)
|
||||
// Recipients can still obtain sources after the viewer is disabled.
|
||||
distribution := strings.HasPrefix(path, strings.TrimPrefix(geckorelay.DistributionPrefix, "/"))
|
||||
if s.geckoConfig() == nil || (!distribution && (!active || !s.geckoAvailable(domain))) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if r.Method != "GET" || r.URL.RawQuery != "" {
|
||||
http.Error(w, "invalid request", 400)
|
||||
return
|
||||
}
|
||||
switch path {
|
||||
case "":
|
||||
geckoIsolation(w)
|
||||
w.Header().Set("Content-Security-Policy", "default-src 'none'; script-src 'self' blob: 'wasm-unsafe-eval'; worker-src 'self' blob:; connect-src 'self' data:; style-src 'self'; img-src 'self' data:; frame-ancestors 'self'; base-uri 'none'; form-action 'none'")
|
||||
w.Header().Set("Referrer-Policy", "no-referrer")
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
io.WriteString(w, geckoShell)
|
||||
return
|
||||
case "assets/v0.0.1/gecko.js", "assets/v0.0.1/gecko.wasm.zst":
|
||||
case "wisp/":
|
||||
// WebSocket cookies alone are not CSRF protection.
|
||||
if r.Header.Get("Origin") != externalURL(r, "") || !strings.EqualFold(r.Header.Get("Upgrade"), "websocket") {
|
||||
http.Error(w, "forbidden", 403)
|
||||
return
|
||||
}
|
||||
default:
|
||||
if !distribution {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
cfg := s.geckoConfig()
|
||||
ctx, cancel := context.WithCancel(r.Context())
|
||||
defer cancel()
|
||||
if path == "wisp/" {
|
||||
token := s.authTokenFromRequest(r)
|
||||
go func() {
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
p, err := s.store.PrincipalForSession(domain, token)
|
||||
if err != nil || p.UUID != actor || p.State != "active" || !s.systemExtensionEnabled(domain, "organizer.feeds") || !s.geckoAvailable(domain) {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
proxy := &httputil.ReverseProxy{Transport: cfg.transport, Rewrite: func(p *httputil.ProxyRequest) {
|
||||
p.SetURL(cfg.origin)
|
||||
p.Out.URL.Path = "/" + path
|
||||
p.Out.URL.RawPath = ""
|
||||
// No ambient credentials, forwarding headers, target URL or user-supplied
|
||||
// grant crosses this boundary. The relay origin is operator-configured.
|
||||
keep := http.Header{}
|
||||
for _, h := range []string{"Upgrade", "Connection", "Sec-WebSocket-Key", "Sec-WebSocket-Version", "Origin", "Range", "If-None-Match", "If-Modified-Since"} {
|
||||
if value := p.Out.Header.Get(h); value != "" {
|
||||
keep.Set(h, value)
|
||||
}
|
||||
}
|
||||
keep.Set(geckorelay.GrantHeader, geckorelay.Sign(cfg.key, geckorelay.Grant{Subject: domain + ":" + actor, Nonce: randomURLToken(24), Expires: time.Now().Add(30 * time.Second).Unix()}))
|
||||
p.Out.Header = keep
|
||||
}, ModifyResponse: func(resp *http.Response) error {
|
||||
resp.Header.Del("Set-Cookie")
|
||||
resp.Header.Set("Cross-Origin-Resource-Policy", "same-origin")
|
||||
if resp.Header.Get("Cache-Control") == "" {
|
||||
resp.Header.Set("Cache-Control", "private, no-store")
|
||||
}
|
||||
return nil
|
||||
}, ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
http.Error(w, "browser relay unavailable", http.StatusBadGateway)
|
||||
}}
|
||||
// ReverseProxy adds upstream headers rather than replacing existing values.
|
||||
// Do not accidentally append the RSS API's no-store to versioned assets.
|
||||
w.Header().Del("Cache-Control")
|
||||
proxy.ServeHTTP(w, r.WithContext(ctx))
|
||||
}
|
||||
|
||||
const geckoShell = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="/static/css/feed-gecko.css?v=1"><title>Gecko</title></head><body><p id="status" role="status"></p><canvas id="screen" tabindex="0" aria-label="Original article"></canvas><script type="module" src="/static/js/feed-gecko.js?v=2"></script></body></html>`
|
||||
|
||||
func init() {
|
||||
translations["en"]["feeds.gecko"] = "Gecko RSS browser (experimental)"
|
||||
translations["ja"]["feeds.gecko"] = "Gecko RSSブラウザ(実験的)"
|
||||
translations["en"]["feeds.gecko_help"] = "Requires a separately deployed authenticated relay. Public HTTP/HTTPS only; browsing uses the relay's IP address."
|
||||
translations["ja"]["feeds.gecko_help"] = "認証付き中継サービスの別途配置が必要です。公開HTTP/HTTPSのみ。閲覧先には中継サーバーのIPが使われます。"
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
"pageswiki/internal/geckorelay"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
// The real engine runs against a synthetic Wisp HTTP responder. This test never
|
||||
// dials an article server, production source, DNS name or external calendar.
|
||||
func TestFeedGeckoChromium(t *testing.T) {
|
||||
testFeedGeckoChromium(t, false)
|
||||
}
|
||||
|
||||
func TestFeedGeckoStartupFailureChromium(t *testing.T) {
|
||||
testFeedGeckoChromium(t, true)
|
||||
}
|
||||
|
||||
func testFeedGeckoChromium(t *testing.T, failure bool) {
|
||||
assets := os.Getenv("PAGESWIKI_GECKO_TEST_ASSETS")
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" || assets == "" {
|
||||
t.Skip("opt-in real Gecko assets")
|
||||
}
|
||||
var connections atomic.Int64
|
||||
publicHTTPS := !failure && os.Getenv("PAGESWIKI_GECKO_PUBLIC_HTTPS_TEST") == "1"
|
||||
realRelay, err := geckorelay.New(geckoTestKey, assets)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if publicHTTPS {
|
||||
realRelay.Distribution, err = geckorelay.VerifyDistribution(assets)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if failure && strings.HasSuffix(r.URL.Path, "/NotoSansCJKjp-Regular.otf") {
|
||||
http.Error(w, "synthetic startup failure", 503)
|
||||
return
|
||||
}
|
||||
if publicHTTPS {
|
||||
realRelay.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
if _, err := geckorelay.Verify(geckoTestKey, r.Header.Get(geckorelay.GrantHeader), time.Now()); err != nil {
|
||||
http.Error(w, "bad grant", 403)
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, geckorelay.DistributionPrefix) {
|
||||
http.ServeFile(w, r, filepath.Join(assets, filepath.Base(r.URL.Path)))
|
||||
return
|
||||
}
|
||||
if r.URL.Path != "/wisp/" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
connections.Add(1)
|
||||
defer connections.Add(-1)
|
||||
packet := func(kind byte, id uint32, data []byte) []byte {
|
||||
out := make([]byte, 5+len(data))
|
||||
out[0] = kind
|
||||
binary.LittleEndian.PutUint32(out[1:], id)
|
||||
copy(out[5:], data)
|
||||
return out
|
||||
}
|
||||
websocket.Message.Send(ws, packet(3, 0, []byte{8, 0, 0, 0}))
|
||||
requests := map[uint32]string{}
|
||||
for {
|
||||
var p []byte
|
||||
if websocket.Message.Receive(ws, &p) != nil || len(p) < 5 {
|
||||
return
|
||||
}
|
||||
id := binary.LittleEndian.Uint32(p[1:])
|
||||
switch p[0] {
|
||||
case 1:
|
||||
requests[id] = ""
|
||||
case 2:
|
||||
requests[id] += string(p[5:])
|
||||
if !strings.Contains(requests[id], "\r\n\r\n") {
|
||||
continue
|
||||
}
|
||||
body := `<!doctype html><meta charset="utf-8"><body style="margin:0;background:rgb(255,0,0)"><a style="display:block;width:300px;height:100px;background:blue;color:white" href="http://fixture.invalid/next">Synthetic next page</a><h1>日本語の記事:学舎の園</h1>`
|
||||
if strings.HasPrefix(requests[id], "GET /next ") {
|
||||
body = `<!doctype html><body style="margin:0;background:rgb(0,255,0)"><h1>Second synthetic page</h1>`
|
||||
}
|
||||
response := fmt.Sprintf("HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s", len(body), body)
|
||||
websocket.Message.Send(ws, packet(2, id, []byte(response)))
|
||||
websocket.Message.Send(ws, packet(4, id, []byte{2}))
|
||||
delete(requests, id)
|
||||
case 4:
|
||||
delete(requests, id)
|
||||
}
|
||||
}
|
||||
}).ServeHTTP(w, r)
|
||||
}))
|
||||
defer backend.Close()
|
||||
s, token, domain, actor, source := feedFixture(t)
|
||||
configureTestGecko(t, s, domain, backend.URL)
|
||||
p, e := s.store.TaskPreferences(context.Background(), domain, actor)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
p.RSSLinkMode = "gecko"
|
||||
if _, e = s.store.SaveTaskPreferences(context.Background(), domain, actor, p, time.Now()); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
claim, e := s.store.ClaimFeed(context.Background(), source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
articleURL := "http://fixture.invalid/first"
|
||||
if publicHTTPS {
|
||||
articleURL = "https://example.com/"
|
||||
}
|
||||
if e = s.store.CompleteFeed(context.Background(), claim, []store.FeedItem{{ID: "synthetic", Title: "Gecko synthetic fixture", URL: articleURL, Body: "Synthetic test fixture."}}, "", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
handler := s.handler()
|
||||
web := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if publicHTTPS && r.URL.Path == "/static/js/feed-gecko.js" {
|
||||
js, err := os.ReadFile("static/js/feed-gecko.js")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
http.Error(w, "fixture missing", 500)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/javascript")
|
||||
io.WriteString(w, strings.Replace(string(js), "engine=new Gecko(", "globalThis.fixtureEngine=engine=new Gecko(", 1))
|
||||
return
|
||||
}
|
||||
if r.Header.Get("Origin") == "http://"+r.Host {
|
||||
r.Header.Set("Origin", "http://localhost")
|
||||
}
|
||||
r.Host = "localhost"
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
handler.ServeHTTP(w, r)
|
||||
}))
|
||||
defer web.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second)
|
||||
defer cancel()
|
||||
mode := "synthetic"
|
||||
if failure {
|
||||
mode = "startup-failure"
|
||||
}
|
||||
if publicHTTPS {
|
||||
mode = "public-https"
|
||||
}
|
||||
out, e := exec.CommandContext(ctx, "node", "internal/server/testdata/feed-gecko-browser.mjs", web.URL+"/v/feeds", t.TempDir(), "/tmp/pageswiki-feed-gecko.png", mode).CombinedOutput()
|
||||
if e != nil {
|
||||
t.Fatalf("browser: %v\n%s", e, out)
|
||||
}
|
||||
io.WriteString(os.Stdout, string(out))
|
||||
for i := 0; i < 30 && connections.Load() != 0; i++ {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
if connections.Load() != 0 {
|
||||
t.Fatal("viewer close left relay session alive")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
"pageswiki/internal/geckorelay"
|
||||
)
|
||||
|
||||
const geckoTestKey = "synthetic-server-relay-key-at-least-32-bytes"
|
||||
|
||||
func configureTestGecko(t *testing.T, s *Server, domain, origin string) {
|
||||
t.Helper()
|
||||
path := filepath.Join(t.TempDir(), "key")
|
||||
if err := os.WriteFile(path, []byte(geckoTestKey), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PAGESWIKI_GECKO_RELAY", origin)
|
||||
t.Setenv("PAGESWIKI_GECKO_KEY_FILE", path)
|
||||
if err := s.setSystemExtensionEnabled(domain, "viewer.gecko", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedGeckoAuthorizationAndHeaders(t *testing.T) {
|
||||
s, token, domain, actor, _ := feedFixture(t)
|
||||
if s.systemExtensionEnabled(domain, "viewer.gecko") {
|
||||
t.Fatal("experimental relay enabled by default")
|
||||
}
|
||||
for _, raw := range []string{"bad json", `{"organizer.feeds":true}`} {
|
||||
if err := s.store.SetConfigInDomain(domain, systemExtensionStateKey, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s.systemExtensionEnabled(domain, "viewer.gecko") {
|
||||
t.Fatal("invalid/absent config enabled relay")
|
||||
}
|
||||
}
|
||||
var requests atomic.Int64
|
||||
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests.Add(1)
|
||||
g, err := geckorelay.Verify(geckoTestKey, r.Header.Get(geckorelay.GrantHeader), time.Now())
|
||||
if err != nil || g.Subject != domain+":"+actor {
|
||||
t.Error("missing bound grant")
|
||||
}
|
||||
for _, h := range []string{"Cookie", "Authorization", "X-Forwarded-For", "Forwarded", "Referer"} {
|
||||
if r.Header.Get(h) != "" {
|
||||
t.Error("credential/header leaked", h)
|
||||
}
|
||||
}
|
||||
if r.URL.Path != "/assets/v0.0.1/gecko.js" && r.URL.Path != "/distribution/v0.0.1/manifest.json" {
|
||||
t.Error("path", r.URL.Path)
|
||||
}
|
||||
w.Header().Set("Set-Cookie", "forbidden=1")
|
||||
w.Header().Set("Cache-Control", "private, max-age=86400, immutable")
|
||||
io.WriteString(w, "export const fixture=true;")
|
||||
}))
|
||||
defer upstream.Close()
|
||||
configureTestGecko(t, s, domain, upstream.URL)
|
||||
r := httptest.NewRequest("GET", "http://localhost"+geckoAPI+"assets/v0.0.1/gecko.js", nil)
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
r.Header.Set("Cookie", "private=secret")
|
||||
r.Header.Set("X-Forwarded-For", "secret")
|
||||
w := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
if w.Code != 200 || requests.Load() != 1 || w.Header().Get("Set-Cookie") != "" {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if len(w.Header().Values("Cache-Control")) != 1 || strings.Contains(w.Header().Get("Cache-Control"), "no-store") {
|
||||
t.Fatal("asset cache disabled", w.Header())
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
path, method string
|
||||
code int
|
||||
}{{"", "GET", 200}, {"wisp/", "GET", 403}, {"assets/v0.0.1/gecko.js?target=https://example.org", "GET", 400}, {"unknown", "GET", 404}, {"assets/v0.0.1/gecko.js", "POST", 400}} {
|
||||
w = feedRequestTest(s, token, tc.method, "browser/"+tc.path, nil)
|
||||
if w.Code != tc.code {
|
||||
t.Fatalf("%s %s: %d %s", tc.method, tc.path, w.Code, w.Body)
|
||||
}
|
||||
if tc.path == "" && w.Header().Get("Cross-Origin-Embedder-Policy") != "require-corp" {
|
||||
t.Fatal("not isolated")
|
||||
}
|
||||
}
|
||||
if w = feedRequestTest(s, "", "GET", "browser/assets/v0.0.1/gecko.js", nil); w.Code == 200 {
|
||||
t.Fatal("anonymous")
|
||||
}
|
||||
for _, origin := range []string{"https://evil.example", "null", "http://localhost.evil.example"} {
|
||||
r := httptest.NewRequest("GET", "http://localhost"+geckoAPI+"wisp/", nil)
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
r.Header.Set("Origin", origin)
|
||||
r.Header.Set("Upgrade", "websocket")
|
||||
w := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
if w.Code != 403 {
|
||||
t.Fatal("cross-site websocket", origin, w.Code)
|
||||
}
|
||||
}
|
||||
prefs, err := s.store.TaskPreferences(context.Background(), domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prefs.RSSLinkMode = "gecko"
|
||||
if _, err = s.store.SaveTaskPreferences(context.Background(), domain, actor, prefs, time.Now()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
page := func() *httptest.ResponseRecorder {
|
||||
r := httptest.NewRequest("GET", "http://localhost/v/feeds", nil)
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
w := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
return w
|
||||
}
|
||||
w = page()
|
||||
if w.Code != 200 || w.Header().Get("Cross-Origin-Opener-Policy") != "same-origin" || !strings.Contains(w.Body.String(), `data-link-mode="gecko"`) {
|
||||
t.Fatal("isolated page", w.Code)
|
||||
}
|
||||
if err = s.setSystemExtensionEnabled(domain, "viewer.gecko", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w = page()
|
||||
if w.Header().Get("Cross-Origin-Opener-Policy") != "" || !strings.Contains(w.Body.String(), `data-link-mode="tab"`) {
|
||||
t.Fatal("disabled fallback")
|
||||
}
|
||||
if w = feedRequestTest(s, token, "GET", "browser/", nil); w.Code != 404 {
|
||||
t.Fatal("disabled shell", w.Code)
|
||||
}
|
||||
if err = s.setSystemExtensionEnabled(domain, "organizer.feeds", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w = feedRequestTest(s, token, "GET", "browser/distribution/v0.0.1/manifest.json", nil); w.Code != 200 {
|
||||
t.Fatal("sources lost after disabling extensions", w.Code)
|
||||
}
|
||||
if w = feedRequestTest(s, "", "GET", "browser/distribution/v0.0.1/manifest.json", nil); w.Code == 200 {
|
||||
t.Fatal("anonymous source download")
|
||||
}
|
||||
if err = s.setSystemExtensionEnabled(domain, "organizer.feeds", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.setSystemExtensionEnabled(domain, "viewer.gecko", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`UPDATE principals SET state='readonly' WHERE uuid=?`, actor); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w = feedRequestTest(s, token, "GET", "browser/", nil); w.Code != 404 {
|
||||
t.Fatal("readonly browser", w.Code)
|
||||
}
|
||||
if w = feedRequestTest(s, token, "GET", "browser/distribution/v0.0.1/manifest.json", nil); w.Code != 200 {
|
||||
t.Fatal("readonly recipient lost source access", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedGeckoWebsocketRevocation(t *testing.T) {
|
||||
for _, disable := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "logout", true: "disable"}[disable], func(t *testing.T) {
|
||||
s, token, domain, _, _ := feedFixture(t)
|
||||
relay, err := geckorelay.New(geckoTestKey, t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
upstream := httptest.NewServer(relay)
|
||||
defer upstream.Close()
|
||||
configureTestGecko(t, s, domain, upstream.URL)
|
||||
web := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
}))
|
||||
defer web.Close()
|
||||
cfg, _ := websocket.NewConfig("ws"+strings.TrimPrefix(web.URL, "http")+geckoAPI+"wisp/", "http://localhost")
|
||||
cfg.Header.Set("Authorization", "Bearer "+token)
|
||||
conn, err := websocket.DialConfig(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
conn.SetDeadline(time.Now().Add(12 * time.Second))
|
||||
var frame []byte
|
||||
if err = websocket.Message.Receive(conn, &frame); err != nil || len(frame) != 9 || frame[0] != 3 || binary.LittleEndian.Uint32(frame[1:]) != 0 {
|
||||
t.Fatal(frame, err)
|
||||
}
|
||||
if disable {
|
||||
err = s.setSystemExtensionEnabled(domain, "viewer.gecko", false)
|
||||
} else {
|
||||
err = s.store.RevokeAuthSession(token)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
start := time.Now()
|
||||
err = websocket.Message.Receive(conn, &frame)
|
||||
if err == nil || time.Since(start) > 10*time.Second {
|
||||
t.Fatal("session not promptly closed", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -531,6 +531,9 @@ func TestFeedsChromium(t *testing.T) {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
s, token, domain, actor, source := feedFixture(t)
|
||||
if err := s.store.SetConfigInDomain(domain, "timezone", "Asia/Tokyo"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prefs, err := s.store.TaskPreferences(context.Background(), domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -20,11 +20,11 @@ import (
|
||||
"golang.org/x/net/html/atom"
|
||||
)
|
||||
|
||||
const htmlProjectionVersion = "controlled-v2"
|
||||
const htmlProjectionVersion = "controlled-v3"
|
||||
const maxProjectionInput = 1 << 20
|
||||
const maxProjectionOutput = 4 << 20
|
||||
|
||||
var projectionMacroRE = regexp.MustCompile(`\{\{(?:children[^}]*|(?:city-breadcrumbs|spot-pages|quartier|street|spot|nearby|city)(?:\s+[^}]*)?)\}\}`)
|
||||
var projectionMacroRE = regexp.MustCompile(`\{\{(?:csv:[^}]*|children[^}]*|(?:city-breadcrumbs|spot-pages|quartier|street|spot|nearby|city)(?:\s+[^}]*)?)\}\}`)
|
||||
var languageClassRE = regexp.MustCompile(`^language-[a-zA-Z0-9_+-]{1,40}$`)
|
||||
|
||||
func projectionPolicy(generated bool) *bluemonday.Policy {
|
||||
@@ -199,6 +199,8 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
|
||||
}
|
||||
var output strings.Builder
|
||||
macros, count := 0, 0
|
||||
csvCount := 0
|
||||
csvResults := map[string]string{}
|
||||
var emit func(*html.Node, int, bool) bool
|
||||
emit = func(n *html.Node, depth int, literal bool) bool {
|
||||
count++
|
||||
@@ -226,6 +228,14 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
|
||||
// be reparsed as a nested children request on its raw text.
|
||||
if isAnonymousProjection(r) {
|
||||
expanded = s.expandPublicMacro(r, macro, path)
|
||||
} else if strings.HasPrefix(macro, "{{csv:") {
|
||||
if cached, ok := csvResults[macro]; ok {
|
||||
expanded = cached
|
||||
} else if csvCount < 4 {
|
||||
csvCount++
|
||||
expanded = s.expandCSVMacro(r, macro)
|
||||
csvResults[macro] = expanded
|
||||
}
|
||||
} else if strings.HasPrefix(macro, "{{children") {
|
||||
expanded = s.expandChildrenMacros(macro, path)
|
||||
} else {
|
||||
@@ -236,6 +246,9 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
|
||||
// promote decoded entities into trusted generated elements.
|
||||
output.WriteString(stdhtml.EscapeString(macro))
|
||||
} else {
|
||||
if output.Len()+len(expanded) > maxProjectionOutput {
|
||||
return false
|
||||
}
|
||||
output.WriteString(expanded)
|
||||
}
|
||||
at = loc[1]
|
||||
|
||||
@@ -37,7 +37,7 @@ func parseTrustedTemplates(t *template.Template) (*template.Template, error) {
|
||||
|
||||
func safeProjectionTemplate(name string) bool {
|
||||
switch name {
|
||||
case "periodical.gohtml", "public_periodical.gohtml", "periodical_new.gohtml":
|
||||
case "periodical.gohtml", "public_periodical.gohtml", "periodical_new.gohtml", "slides.gohtml":
|
||||
return true
|
||||
case "city_map.gohtml", "public_tree.gohtml", "anonymous_view.gohtml", "page.gohtml", "home.gohtml", "search_home.gohtml", "object_view.gohtml", "revision_view.gohtml", "preview.gohtml", "print.gohtml", "profile.gohtml", "editor.gohtml", "object_editor.gohtml":
|
||||
return true
|
||||
|
||||
@@ -19,7 +19,7 @@ func NormalizePath(
|
||||
// Hosted adapter assets use directory-relative module and worker URLs.
|
||||
// DAV collections also require the slash: removing it conflicts with
|
||||
// ServeMux's collection redirect and causes an infinite redirect loop.
|
||||
if strings.HasPrefix(p, "/_/adaptor/") || strings.HasPrefix(p, "/_/api/v1/caldav/") || strings.HasPrefix(p, "/_/api/v1/carddav/") {
|
||||
if strings.HasPrefix(p, "/_/adaptor/") || strings.HasPrefix(p, "/_/api/v1/caldav/") || strings.HasPrefix(p, "/_/api/v1/carddav/") || strings.HasPrefix(p, "/_/api/v1/extension/organizer.feeds/browser/") {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,3 +24,18 @@ func TestNormalizePathDAVCollections(t *testing.T) {
|
||||
t.Fatal("Wiki canonicalization changed", w.Code, w.Header())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePathGeckoWebsocket(t *testing.T) {
|
||||
for _, path := range []string{"/_/api/v1/extension/organizer.feeds/browser/", "/_/api/v1/extension/organizer.feeds/browser/wisp/"} {
|
||||
w := httptest.NewRecorder()
|
||||
NormalizePath(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != path {
|
||||
t.Fatal(r.URL.Path)
|
||||
}
|
||||
w.WriteHeader(401)
|
||||
})).ServeHTTP(w, httptest.NewRequest("GET", path, nil))
|
||||
if w.Code != 401 || w.Header().Get("Location") != "" {
|
||||
t.Fatal("redirected browser endpoint", w.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ func (s *Server) renderWithContext(
|
||||
data["TasksEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.tasks")
|
||||
data["ContactsEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.contacts")
|
||||
data["FeedsEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.feeds")
|
||||
data["SlidesEnabled"] = s.systemExtensionEnabled(domainUUID, "viewer.slides")
|
||||
data["OrganizerSection"] = organizerSection(r.URL.Path)
|
||||
if r.URL.Path == "/" {
|
||||
data["IsHome"] = true
|
||||
|
||||
@@ -16,6 +16,7 @@ type UIHandlers struct {
|
||||
Preview http.HandlerFunc
|
||||
PlainView http.HandlerFunc
|
||||
MarkdownView http.HandlerFunc
|
||||
Slides http.HandlerFunc
|
||||
CompileMarkdown http.HandlerFunc
|
||||
CompileDiagram http.HandlerFunc
|
||||
Config http.HandlerFunc
|
||||
@@ -93,6 +94,8 @@ func RegisterUIRoutes(
|
||||
|
||||
handleIfNotNil(mux, "/v/markdown", h.MarkdownView)
|
||||
handleIfNotNil(mux, "/v/markdown/", h.MarkdownView)
|
||||
handleIfNotNil(mux, "/v/slides", h.Slides)
|
||||
handleIfNotNil(mux, "/v/slides/", h.Slides)
|
||||
|
||||
handleIfNotNil(mux, "/:/compile/markdown", h.CompileMarkdown)
|
||||
handleIfNotNil(mux, "/:/compile/markdown/", h.CompileMarkdown)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"pageswiki/internal/grammaratur"
|
||||
"pageswiki/internal/store"
|
||||
@@ -211,16 +212,43 @@ func (s *Server) handleSemanticEditor(
|
||||
}
|
||||
}
|
||||
|
||||
latest, err :=
|
||||
s.latestRevisionForRequest(
|
||||
r,
|
||||
objectUUID,
|
||||
)
|
||||
|
||||
body := ""
|
||||
// CSV editing needs the complete source, never the viewer's truncated window.
|
||||
// Check metadata before loading a potentially large document.
|
||||
metadata, metaErr := s.store.GetLatestRevisionMetadataForLanguagesContext(r.Context(), objectUUID, s.revisionLanguageCandidates(r))
|
||||
if lang := r.URL.Query().Get("lang"); lang != "" {
|
||||
latest, err = s.store.GetRevisionForExactLanguage(objectUUID, lang)
|
||||
metadata, metaErr = s.store.GetRevisionMetadataForExactLanguage(objectUUID, lang)
|
||||
}
|
||||
if metaErr != nil || metadata == nil {
|
||||
http.Error(w, "revision unavailable or invalid language", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
csvEditor := selectProjectionAdapter(contentDescriptor{MediaType: strings.ToLower(strings.TrimSpace(strings.Split(metadata.ContentType, ";")[0])), Filename: metadata.Filename}).Kind == "csv"
|
||||
if csvEditor {
|
||||
size, sizeErr := s.store.DocumentSizeContext(r.Context(), metadata.DocumentHash)
|
||||
if sizeErr != nil || size > maxCSVMacroBytes {
|
||||
http.Error(w, "CSV editor requires a complete document of at most 256 KiB", http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var latest *store.Revision
|
||||
if csvEditor {
|
||||
// Load the immutable revision we checked; a concurrent new head is
|
||||
// handled by the normal save CAS, not by an unbounded second read.
|
||||
window, readErr := s.store.ReadDocumentWindowContext(r.Context(), metadata.DocumentHash, 0, maxCSVMacroBytes)
|
||||
if readErr != nil || window.Truncated {
|
||||
http.Error(w, "CSV source unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
latest = metadata
|
||||
latest.Body = string(window.Data)
|
||||
} else {
|
||||
latest, err = s.latestRevisionForRequest(r, objectUUID)
|
||||
if lang := r.URL.Query().Get("lang"); lang != "" {
|
||||
latest, err = s.store.GetRevisionForExactLanguage(objectUUID, lang)
|
||||
}
|
||||
}
|
||||
body := ""
|
||||
if err != nil {
|
||||
http.Error(w, "revision unavailable or invalid language", 400)
|
||||
return
|
||||
@@ -233,7 +261,13 @@ func (s *Server) handleSemanticEditor(
|
||||
if err == nil {
|
||||
if latest.UUID != "" {
|
||||
view := revisionContentView(latest, path)
|
||||
if view.Kind == "code" {
|
||||
if view.Kind == "csv" {
|
||||
if !csvEditor || !utf8.ValidString(latest.Body) || strings.ContainsRune(latest.Body, 0) || len(latest.Body) > maxCSVMacroBytes {
|
||||
http.Error(w, "CSV editor requires bounded UTF-8 text", http.StatusUnsupportedMediaType)
|
||||
return
|
||||
}
|
||||
editType = "code"
|
||||
} else if view.Kind == "code" {
|
||||
editType = "code"
|
||||
if strings.EqualFold(strings.TrimSpace(strings.Split(latest.ContentType, ";")[0]), "text/plain") {
|
||||
editType = "plain"
|
||||
@@ -294,6 +328,7 @@ func (s *Server) handleSemanticEditor(
|
||||
"BaseBody": baseBody,
|
||||
"BaseRevision": latest.UUID,
|
||||
"EditType": editType,
|
||||
"CSVEditor": csvEditor,
|
||||
"PageLanguage": latest.Language,
|
||||
"PageContentType": contentType,
|
||||
"PageFilename": filename,
|
||||
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
geckoOnce sync.Once
|
||||
gecko *geckoProxy
|
||||
calendarOnce sync.Once
|
||||
calendarRepo *calendar.Repository
|
||||
calendarErr error
|
||||
@@ -255,6 +257,7 @@ func (s *Server) registerRoutes() {
|
||||
Preview: s.handlePreview,
|
||||
PlainView: s.handlePlainView,
|
||||
MarkdownView: s.handleMarkdownView,
|
||||
Slides: s.handleSlides,
|
||||
CompileMarkdown: s.handleCompileMarkdown,
|
||||
CompileDiagram: s.handleCompileDiagram,
|
||||
Config: s.handleConfig,
|
||||
@@ -351,7 +354,7 @@ func (s *Server) handler() http.Handler {
|
||||
domainHandler = h
|
||||
h = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
background := r.URL.Query().Get("preview") == "1" ||
|
||||
strings.HasPrefix(r.URL.Path, "/v/preview-cache/")
|
||||
strings.HasPrefix(r.URL.Path, "/v/preview-cache/") || r.URL.Path == feedsAPI+"browser/wisp/"
|
||||
if !background {
|
||||
s.foregroundRequests.Add(1)
|
||||
defer s.foregroundRequests.Add(-1)
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"pageswiki/internal/grammaratur"
|
||||
)
|
||||
|
||||
const maxSlideSourceBytes = 256 << 10
|
||||
|
||||
func (s *Server) handleSlides(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||
w.Header().Set("Allow", "GET, HEAD")
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
if !s.systemExtensionEnabled(domain, "viewer.slides") {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
path := semanticViewPath(r.URL.Path)
|
||||
if !s.requestCanReadPath(r, path) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
object, err := s.store.ResolvePathInDomain(domain, path)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
revision, err := s.store.GetLatestRevisionMetadataForLanguagesContext(r.Context(), object, s.revisionLanguageCandidates(r))
|
||||
if err != nil || revision == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
media := strings.ToLower(strings.TrimSpace(strings.Split(revision.ContentType, ";")[0]))
|
||||
if media != "text/html" && media != "text/markdown" && media != "text/x-markdown" {
|
||||
http.Error(w, "slides require HTML or Markdown", http.StatusUnsupportedMediaType)
|
||||
return
|
||||
}
|
||||
size, err := s.store.DocumentSizeContext(r.Context(), revision.DocumentHash)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if size > maxSlideSourceBytes {
|
||||
http.Error(w, "slides source exceeds 256 KiB", http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
window, err := s.store.ReadDocumentWindowContext(r.Context(), revision.DocumentHash, 0, maxSlideSourceBytes)
|
||||
if err != nil || window.Truncated || !utf8.Valid(window.Data) {
|
||||
http.Error(w, "invalid slides source", http.StatusUnsupportedMediaType)
|
||||
return
|
||||
}
|
||||
source := string(window.Data)
|
||||
if media != "text/html" {
|
||||
source = grammaratur.MarkdownAuthoringHTML(source)
|
||||
}
|
||||
source = s.safeHTMLProjection(r, source, path, false)
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
if r.Method == http.MethodHead {
|
||||
return
|
||||
}
|
||||
s.renderWithContext(w, r, "slides.gohtml", map[string]any{"Title": path, "Path": path, "SlideSource": source})
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package server
|
||||
|
||||
func init() {
|
||||
for lang, entries := range map[string]map[string]string{
|
||||
"en": {"slides.title": "Slides", "slides.help": "Local Reveal.js viewer and editor preview. Separate slides with a horizontal rule.", "slides.preview": "Slide preview", "slides.close": "Return to page", "slides.fullscreen": "Fullscreen", "slides.error": "Slides could not be displayed. Use the document view (limit: 256 KiB, 100 slides)."},
|
||||
"ja": {"slides.title": "スライド", "slides.help": "ローカル同梱のReveal.jsで閲覧・編集プレビュー。水平線でスライドを区切ります。", "slides.preview": "スライドプレビュー", "slides.close": "ページへ戻る", "slides.fullscreen": "全画面", "slides.error": "スライドを表示できません。通常表示を使用してください(上限256 KiB・100枚)。"},
|
||||
} {
|
||||
for key, value := range entries {
|
||||
translations[lang][key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"html"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"pageswiki/internal/server/routes"
|
||||
)
|
||||
|
||||
const slideFixture = `<h1>First slide</h1><p>日本語のスライド</p><hr><h2>Second slide</h2><ul><li>Local Reveal.js</li><li>No source mutation</li></ul>`
|
||||
|
||||
func TestSlidesAccessAndLimits(t *testing.T) {
|
||||
s, token, domain, _ := editorFixture(t)
|
||||
routes.RegisterUIRoutes(s.mux, routes.UIHandlers{Slides: s.handleSlides})
|
||||
s.mux.HandleFunc("/deck", s.handleSemanticRoute)
|
||||
object, err := s.store.CreatePageAtPathInDomain(domain, "/deck")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
save := func(body, media string) {
|
||||
t.Helper()
|
||||
if _, e := s.store.SaveRevisionContent(object, []byte(body), "", "und", media, ""); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
save(slideFixture, "text/html")
|
||||
w := configRequest(s, token, "GET", "/v/slides/deck", nil)
|
||||
if w.Code != 200 || !strings.Contains(w.Body.String(), "data-slides-viewer") || !strings.Contains(w.Body.String(), "<h1>First slide") {
|
||||
t.Fatalf("slides %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
if !strings.Contains(w.Header().Get("Content-Security-Policy"), "'nonce-") {
|
||||
t.Fatal("missing CSP")
|
||||
}
|
||||
page := configRequest(s, token, "GET", "/deck", nil)
|
||||
if !strings.Contains(page.Body.String(), `href="/v/slides/deck"`) {
|
||||
t.Fatal("viewer action missing")
|
||||
}
|
||||
editor := configRequest(s, token, "GET", "/e/-/deck", nil)
|
||||
if !strings.Contains(editor.Body.String(), `data-editor-action="slides"`) {
|
||||
t.Fatal("preview action missing")
|
||||
}
|
||||
// A missing or unauthorized semantic path is not exposed via the new view.
|
||||
req := httptest.NewRequest("GET", "http://localhost/v/slides/deck", nil)
|
||||
denied := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(denied, req)
|
||||
if denied.Code == 200 || strings.Contains(denied.Body.String(), "First slide") {
|
||||
t.Fatal("anonymous private content exposed")
|
||||
}
|
||||
if configRequest(s, token, "GET", "/v/slides/missing", nil).Code != 404 {
|
||||
t.Fatal("missing deck")
|
||||
}
|
||||
if p := policyForRequest(httptest.NewRequest("GET", "/v/slides/deck", nil)); p.Resolver != resolveViewPath || p.Capability != "read" {
|
||||
t.Fatal("wrong policy")
|
||||
}
|
||||
if semanticViewPath("/v/slides/deck") != "/deck" {
|
||||
t.Fatal("wrong target")
|
||||
}
|
||||
save("# Markdown\n\n---\n\n## Second", "text/markdown")
|
||||
if w = configRequest(s, token, "GET", "/v/slides/deck", nil); w.Code != 200 || !strings.Contains(w.Body.String(), "<hr") {
|
||||
t.Fatal("markdown projection", w.Code)
|
||||
}
|
||||
save("%PDF-synthetic", "application/pdf")
|
||||
if configRequest(s, token, "GET", "/v/slides/deck", nil).Code != 415 {
|
||||
t.Fatal("binary accepted")
|
||||
}
|
||||
save(strings.Repeat("x", maxSlideSourceBytes+1), "text/html")
|
||||
if configRequest(s, token, "GET", "/v/slides/deck", nil).Code != 413 {
|
||||
t.Fatal("oversize accepted")
|
||||
}
|
||||
save(slideFixture, "text/html")
|
||||
if err = s.setSystemExtensionEnabled(domain, "viewer.slides", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if configRequest(s, token, "GET", "/v/slides/deck", nil).Code != 404 {
|
||||
t.Fatal("disabled viewer active")
|
||||
}
|
||||
editor = configRequest(s, token, "GET", "/e/-/deck", nil)
|
||||
if strings.Contains(editor.Body.String(), `data-editor-action="slides"`) {
|
||||
t.Fatal("disabled preview action")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlidesChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
for _, mode := range []string{"viewer", "editor"} {
|
||||
for _, width := range []string{"1280", "390"} {
|
||||
t.Run(mode+width, func(t *testing.T) {
|
||||
s, token, domain, _ := editorFixture(t)
|
||||
routes.RegisterUIRoutes(s.mux, routes.UIHandlers{Slides: s.handleSlides})
|
||||
object, err := s.store.CreatePageAtPathInDomain(domain, "/deck")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.SaveRevisionContent(object, []byte(slideFixture), "", "und", "text/html", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
script, err := os.ReadFile("internal/server/testdata/slides.js")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
route := "/v/slides/deck"
|
||||
if mode == "editor" {
|
||||
route = "/e/-/deck"
|
||||
}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.URL.Path == route {
|
||||
rec := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(rec, r)
|
||||
for k, v := range rec.Header() {
|
||||
w.Header()[k] = v
|
||||
}
|
||||
w.WriteHeader(rec.Code)
|
||||
_, policy, _ := strings.Cut(rec.Header().Get("Content-Security-Policy"), "'nonce-")
|
||||
nonce, _, _ := strings.Cut(policy, "'")
|
||||
w.Write([]byte(strings.Replace(rec.Body.String(), "</body>", `<script nonce="`+html.EscapeString(nonce)+`">`+string(script)+"</script></body>", 1)))
|
||||
return
|
||||
}
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
}))
|
||||
defer server.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, "node", "internal/server/testdata/vim-browser-smoke.mjs", server.URL+route, t.TempDir(), "/tmp/pageswiki-slides-"+mode+width+".png", width, "850")
|
||||
cmd.Env = append(os.Environ(), "PAGESWIKI_SLIDES_BROWSER=1")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("browser %v: %s", err, out)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,9 @@ func (c *smtpLimitedConn) Read(buffer []byte) (int, error) {
|
||||
}
|
||||
|
||||
type magicLinkChallenge struct {
|
||||
Return string `json:"return"`
|
||||
Email string `json:"email"`
|
||||
Return string `json:"return"`
|
||||
Email string `json:"email"`
|
||||
Remember bool `json:"remember,omitempty"`
|
||||
}
|
||||
|
||||
func smtpMailbox(value string) (*mail.Address, error) {
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func TestTaskCaptureDeletedRecreation(t *testing.T) {
|
||||
for _, wiki := range []bool{false, true} {
|
||||
t.Run(fmt.Sprint(wiki), func(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
id := uuid.NewString()
|
||||
input := map[string]any{"request_id": id, "title": "Original"}
|
||||
if wiki {
|
||||
input["wiki_body"], input["wiki_prefix"] = "Original private body", "/mail"
|
||||
}
|
||||
w := taskRequest(s, token, "POST", "capture", input, "")
|
||||
if w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
var result struct {
|
||||
Item store.TaskRecord `json:"item"`
|
||||
Path string `json:"page_path"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
page, path := result.Item.PageUUID, result.Path
|
||||
var revision string
|
||||
if wiki {
|
||||
r, err := s.store.GetLatestRevision(page)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
revision = r.UUID
|
||||
}
|
||||
if w = taskRequest(s, token, "DELETE", "items/"+id, nil, `"1"`); w.Code != 204 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w = taskRequest(s, token, "GET", "items/"+id, nil, ""); w.Code != 404 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
for _, title := range []string{"Original", "Changed"} {
|
||||
input["title"] = title
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 410 || !strings.Contains(w.Body.String(), `"deleted"`) {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
input["replaces_deleted"], input["request_id"] = id, store.TaskRecreationID(id)
|
||||
if wiki {
|
||||
input["wiki_body"] = "Must not overwrite the retained page"
|
||||
for _, invalidBody := range []string{"bad\x00body", strings.Repeat("x", 256<<10+1)} {
|
||||
input["wiki_body"] = invalidBody
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 422 {
|
||||
t.Fatal("reused page bypassed body validation", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
input["wiki_body"] = "Must not overwrite the retained page"
|
||||
}
|
||||
// A lost successful response, including concurrent retries, creates one
|
||||
// successor. It neither revives the original nor revises the Wiki.
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 4; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
v := taskRequest(s, token, "POST", "capture", input, "")
|
||||
if v.Code != 201 {
|
||||
t.Errorf("concurrent recreation: %d %s", v.Code, v.Body)
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
w = taskRequest(s, token, "POST", "capture", input, "")
|
||||
if w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Item.UUID != store.TaskRecreationID(id) || result.Item.UUID == id || result.Item.Title != "Changed" || result.Item.Version != 1 || result.Item.PageUUID != page || result.Path != path {
|
||||
t.Fatal(result)
|
||||
}
|
||||
if wiki {
|
||||
r, err := s.store.GetLatestRevision(page)
|
||||
if err != nil || r.UUID != revision || !strings.Contains(r.Body, "Original private body") {
|
||||
t.Fatal("Wiki changed", r, err)
|
||||
}
|
||||
}
|
||||
for table, expected := range map[string]int{"organizer_items": 1, "organizer_capture_receipts": 2, "organizer_task_deletions": 1, "organizer_revisions": 1} {
|
||||
var count int
|
||||
if err := s.store.DB.QueryRow("SELECT count(*) FROM " + table).Scan(&count); err != nil || count != expected {
|
||||
t.Fatal(table, count, err)
|
||||
}
|
||||
}
|
||||
if _, err := s.store.SaveTask(ctx, domain, actor, store.TaskRecord{UUID: id, Kind: "task", Title: "Offline resurrection", Status: "todo", Bucket: "inbox", Priority: 1}, 0); err != store.ErrTaskDeleted {
|
||||
t.Fatal("old UUID revived", err)
|
||||
}
|
||||
input["title"] = "Different committed recovery"
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 412 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
// Deleting the successor cannot be undone by replaying the recovery.
|
||||
if w = taskRequest(s, token, "DELETE", "items/"+result.Item.UUID, nil, `"1"`); w.Code != 204 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 410 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskCaptureRecreationGuards(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
id := uuid.NewString()
|
||||
input := map[string]any{"request_id": id, "title": "Original"}
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
recreate := map[string]any{"request_id": store.TaskRecreationID(id), "replaces_deleted": id, "title": "New"}
|
||||
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 412 {
|
||||
t.Fatal("live capture replaced", w.Code, w.Body)
|
||||
}
|
||||
if w := taskRequest(s, token, "DELETE", "items/"+id, nil, `"1"`); w.Code != 204 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
other, err := s.store.CreatePasswordAccount(domain, "recreateother", "long fixture password", "Other", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
otherToken, err := s.store.CreateAuthSession(domain, other.UUID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, otherToken, "POST", "capture", recreate, ""); w.Code != 404 {
|
||||
t.Fatal("other owner", w.Code, w.Body)
|
||||
}
|
||||
if _, err := s.store.RecreateCapturedTask(context.Background(), "other-domain", actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Wrong domain"), "", "", id); err != store.ErrAccessDenied {
|
||||
t.Fatal("wrong domain", err)
|
||||
}
|
||||
if err := s.store.SetPrincipalState(domain, actor, "readonly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.RecreateCapturedTask(context.Background(), domain, actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Readonly"), "", "", id); err != store.ErrAccessDenied {
|
||||
t.Fatal("readonly", err)
|
||||
}
|
||||
if err := s.store.SetPrincipalState(domain, actor, "active"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, err = s.store.CreateAuthSession(domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":false}`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.RecreateCapturedTask(context.Background(), domain, actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Disabled"), "", "", id); err != store.ErrAccessDenied {
|
||||
t.Fatal("extension disabled", err)
|
||||
}
|
||||
if err := s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":true}`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, invalid := range []string{uuid.NewString(), id, "not-an-id"} {
|
||||
recreate["request_id"] = invalid
|
||||
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 422 {
|
||||
t.Fatal("arbitrary recovery ID", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
recreate["request_id"] = store.TaskRecreationID(id)
|
||||
// Failure during receipt insertion rolls back the task, page and journals.
|
||||
if _, err := s.store.DB.Exec(`CREATE TRIGGER reject_recreation BEFORE INSERT ON organizer_capture_receipts BEGIN SELECT RAISE(ABORT,'fixture rejection'); END`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
recreate["wiki_body"], recreate["wiki_prefix"] = "New body", "/recreated"
|
||||
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 500 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
var count int
|
||||
if err := s.store.DB.QueryRow(`SELECT count(*) FROM organizer_items`).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatal("orphan task", count, err)
|
||||
}
|
||||
if err := s.store.DB.QueryRow(`SELECT count(*) FROM paths WHERE path LIKE '/recreated/%'`).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatal("orphan page", count, err)
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`DROP TRIGGER reject_recreation`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if _, err := s.store.GetTask(context.Background(), domain, actor, store.TaskRecreationID(id)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskCaptureOrphanReceipt(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
id := uuid.NewString()
|
||||
input := map[string]any{"request_id": id, "title": "Original"}
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
// Simulate preexisting corruption, not a supported user deletion operation.
|
||||
if _, err := s.store.DB.Exec(`DELETE FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=?`, domain, actor, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, title := range []string{"Original", "Changed"} {
|
||||
input["title"] = title
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 409 || !strings.Contains(w.Body.String(), "capture_missing") {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
input["request_id"], input["replaces_deleted"] = store.TaskRecreationID(id), id
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 409 || !strings.Contains(w.Body.String(), "capture_missing") {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func TestTaskDeleteAPIAndDAVTombstone(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
page, err := s.store.CreatePageAtPathInDomain(domain, "/delete-fixture-note")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task := newTaskRecord("task", "Delete fixture")
|
||||
task.PageUUID = page
|
||||
task.NotifyDue, task.DueOn = true, "2099-01-01"
|
||||
task, err = s.store.SaveTask(ctx, domain, actor, task, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
url := "items/" + task.UUID
|
||||
for _, test := range []struct {
|
||||
tag string
|
||||
status int
|
||||
}{{"", 428}, {`W/"1"`, 422}, {`"2"`, 412}} {
|
||||
w := taskRequest(s, token, "DELETE", url, nil, test.tag)
|
||||
if w.Code != test.status {
|
||||
t.Fatalf("precondition %s: %d %s", test.tag, w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
for i := 0; i < 2; i++ {
|
||||
w := taskRequest(s, token, "DELETE", url, nil, `"1"`)
|
||||
if w.Code != 204 {
|
||||
t.Fatalf("delete/retry: %d %s", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
for _, suffix := range []string{url, url + "/history"} {
|
||||
if w := taskRequest(s, token, "GET", suffix, nil, ""); w.Code != 404 {
|
||||
t.Fatalf("deleted read: %d %s", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
for _, view := range []string{"all", "archived", "done", "today"} {
|
||||
w := taskRequest(s, token, "GET", "items?view="+view, nil, "")
|
||||
if w.Code != 200 || strings.Contains(w.Body.String(), task.UUID) {
|
||||
t.Fatalf("deleted list %s: %d %s", view, w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
for _, table := range []string{"organizer_items", "organizer_revisions", "organizer_reminders", "organizer_task_metrics"} {
|
||||
var count int
|
||||
if err := s.store.DB.QueryRow(`SELECT count(*) FROM ` + table).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatalf("cleanup %s: %d %v", table, count, err)
|
||||
}
|
||||
}
|
||||
if id, err := s.store.ResolvePathInDomain(domain, "/delete-fixture-note"); err != nil || id != page {
|
||||
t.Fatal("Wiki note removed", id, err)
|
||||
}
|
||||
if _, err := s.store.SaveTask(ctx, domain, actor, task, 0); !errors.Is(err, store.ErrTaskDeleted) {
|
||||
t.Fatal("UUID recreated", err)
|
||||
}
|
||||
if _, _, err := s.store.PublishTaskActivity(ctx, 100); err != nil {
|
||||
t.Fatal("deleted head stalled outbox bridge", err)
|
||||
}
|
||||
for _, project := range []string{"", uuid.NewString()} {
|
||||
if project != "" {
|
||||
p := newTaskRecord("project", "Delete project fixture")
|
||||
p.UUID = project
|
||||
if _, err := s.store.SaveTask(ctx, domain, actor, p, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
davTask := newTaskRecord("task", "DAV fixture")
|
||||
davTask.ProjectUUID = project
|
||||
data := &store.TaskDAVData{Name: "client-fixture.ics", UID: "client-fixture-uid", Data: "fixture"}
|
||||
davTask, err = s.store.SaveTaskDAV(ctx, domain, actor, davTask, 0, data, "", project)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.DeleteTask(ctx, domain, actor, davTask.UUID, davTask.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Simulate reopening/rebuilding the derived DAV indexes.
|
||||
if err = s.store.EnsureTasksSchema(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.TaskDAVByName(ctx, domain, actor, data.Name, project); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("DAV deleted resource exposed", err)
|
||||
}
|
||||
items, err := s.store.TaskDAVList(ctx, domain, actor, project)
|
||||
if err != nil || len(items) != 0 {
|
||||
t.Fatal("DAV deleted resource listed", items, err)
|
||||
}
|
||||
for _, altered := range []string{"neither", "name", "uid"} {
|
||||
candidate := newTaskRecord("task", "Stale client PUT")
|
||||
candidate.ProjectUUID = project
|
||||
d := *data
|
||||
if altered == "name" {
|
||||
d.Name = "other.ics"
|
||||
}
|
||||
if altered == "uid" {
|
||||
d.UID = "other-uid"
|
||||
}
|
||||
if _, err := s.store.SaveTaskDAV(ctx, domain, actor, candidate, 0, &d, "", project); !errors.Is(err, store.ErrTaskDAVIdentity) {
|
||||
t.Fatalf("resurrection %s: %v", altered, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDeleteGuardsAndAtomicity(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
task, err := s.store.SaveTask(ctx, domain, actor, newTaskRecord("task", "Guarded fixture"), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other, err := s.store.CreatePasswordAccount(domain, "deleteother", "long fixture password", "Other", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.store.DeleteTask(ctx, domain, other.UUID, task.UUID, 1); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("ownership", err)
|
||||
}
|
||||
if err := s.store.DeleteTask(ctx, "other-domain", actor, task.UUID, 1); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatal("domain", err)
|
||||
}
|
||||
if err := s.store.SetPrincipalState(domain, actor, "readonly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, token, "DELETE", "items/"+task.UUID, nil, `"1"`); w.Code != 401 {
|
||||
t.Fatal("readonly", w.Code, w.Body)
|
||||
}
|
||||
if err := s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatal("readonly store", err)
|
||||
}
|
||||
if err := s.store.SetPrincipalState(domain, actor, "active"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, err = s.store.CreateAuthSession(domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":false}`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatal("disabled", err)
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`DELETE FROM config WHERE domain_uuid=? AND key='system_extension_states'`, domain); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
child := newTaskRecord("task", "Archived child")
|
||||
child.ParentUUID = task.UUID
|
||||
child.Archived = true
|
||||
child, err = s.store.SaveTask(ctx, domain, actor, child, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, token, "DELETE", "items/"+task.UUID, nil, `"1"`); w.Code != 409 || !strings.Contains(w.Body.String(), "has_children") {
|
||||
t.Fatal("children", w.Code, w.Body)
|
||||
}
|
||||
if err = s.store.DeleteTask(ctx, domain, actor, child.UUID, child.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
focus, err := s.store.ChangeTaskFocus(ctx, domain, actor, "start", store.TaskFocus{UUID: uuid.NewString(), TaskUUID: task.UUID, Phase: "focus", DurationMS: 25 * 60 * 1000}, 0, time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); !errors.Is(err, store.ErrTaskWorking) {
|
||||
t.Fatal("focus", err)
|
||||
}
|
||||
if _, err = s.store.ChangeTaskFocus(ctx, domain, actor, "cancel", focus, focus.Version, time.Now()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
work, err := s.store.ChangeTaskWork(ctx, domain, actor, "start", store.TaskWork{UUID: uuid.NewString(), TaskUUID: task.UUID}, time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); !errors.Is(err, store.ErrTaskWorking) {
|
||||
t.Fatal("running work", err)
|
||||
}
|
||||
if _, err = s.store.ChangeTaskWork(ctx, domain, actor, "stop", work, time.Now()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Abort at the last delete step: neither a tombstone nor partial cleanup may remain.
|
||||
if _, err = s.store.DB.Exec(`CREATE TRIGGER fail_fixture_delete BEFORE DELETE ON organizer_items BEGIN SELECT RAISE(ABORT,'fixture failure'); END`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); err == nil {
|
||||
t.Fatal("injected failure ignored")
|
||||
}
|
||||
if _, err = s.store.GetTask(ctx, domain, actor, task.UUID); err != nil {
|
||||
t.Fatal("head not rolled back", err)
|
||||
}
|
||||
var n int
|
||||
if err = s.store.DB.QueryRow(`SELECT count(*) FROM organizer_task_deletions WHERE item_uuid=?`, task.UUID).Scan(&n); err != nil || n != 0 {
|
||||
t.Fatal("partial tombstone", n, err)
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`DROP TRIGGER fail_fixture_delete`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task.Archived = true
|
||||
task, err = s.store.SaveTask(ctx, domain, actor, task, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, token, "DELETE", "items/"+task.UUID, nil, `"`+strconv.FormatInt(task.Version, 10)+`"`); w.Code != 204 {
|
||||
t.Fatal("archived deletion", w.Code, w.Body)
|
||||
}
|
||||
if err := s.store.DeleteTask(ctx, domain, other.UUID, task.UUID, task.Version); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("tombstone ownership", err)
|
||||
}
|
||||
if _, err := s.store.SaveTask(ctx, domain, other.UUID, task, 0); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("tombstone creation privacy", err)
|
||||
}
|
||||
if err := s.store.DB.QueryRow(`SELECT count(*) FROM organizer_work_sessions WHERE uuid=? AND end_ms>0`, work.UUID).Scan(&n); err != nil || n != 1 {
|
||||
t.Fatal("work history removed", n, err)
|
||||
}
|
||||
project, err := s.store.SaveTask(ctx, domain, actor, newTaskRecord("project", "Keep project"), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.DeleteTask(ctx, domain, actor, project.UUID, 1); !errors.Is(err, store.ErrTaskInvalid) {
|
||||
t.Fatal("project unexpectedly deleted", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDeleteDAVHTTP(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
auth, name := "Bearer "+token, "delete-client.ics"
|
||||
url := taskDAVCollection + name
|
||||
if w := davTaskRequest(s, auth, "PUT", url, taskICALFixture, nil); w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
item, err := s.store.TaskDAVByName(ctx, domain, actor, name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before := davTaskRequest(s, auth, "GET", url, "", nil)
|
||||
if before.Code != 200 {
|
||||
t.Fatal(before.Code, before.Body)
|
||||
}
|
||||
if err = s.store.DeleteTask(ctx, domain, actor, item.UUID, item.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := davTaskRequest(s, auth, "GET", url, "", nil); w.Code != 404 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
query := `<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"><d:prop><d:getetag/><c:calendar-data/></d:prop><c:filter><c:comp-filter name="VCALENDAR"><c:comp-filter name="VTODO"/></c:comp-filter></c:filter></c:calendar-query>`
|
||||
if w := davTaskRequest(s, auth, "REPORT", taskDAVCollection, query, nil); w.Code != 207 || strings.Contains(w.Body.String(), name) {
|
||||
t.Fatal("query", w.Code, w.Body)
|
||||
}
|
||||
multi := `<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"><d:prop><d:getetag/><c:calendar-data/></d:prop><d:href>` + url + `</d:href></c:calendar-multiget>`
|
||||
if w := davTaskRequest(s, auth, "REPORT", taskDAVCollection, multi, nil); w.Code != 207 || !strings.Contains(w.Body.String(), "404 Not Found") {
|
||||
t.Fatal("multiget", w.Code, w.Body)
|
||||
}
|
||||
if w := davTaskRequest(s, auth, "PUT", url, taskICALFixture, map[string]string{"If-Match": before.Header().Get("ETag")}); w.Code != 412 {
|
||||
t.Fatal("stale conditional PUT", w.Code, w.Body)
|
||||
}
|
||||
if w := davTaskRequest(s, auth, "PUT", url, taskICALFixture, nil); w.Code != 403 || !strings.Contains(w.Body.String(), "no-uid-conflict") {
|
||||
t.Fatal("stale unconditional PUT", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
@@ -56,20 +56,21 @@ func applyTaskReminderDefaults(item *store.TaskRecord, p store.TaskPreferences)
|
||||
}
|
||||
|
||||
type taskCaptureInput struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Title string `json:"title"`
|
||||
Notes string `json:"notes"`
|
||||
ProjectUUID *string `json:"project_uuid"`
|
||||
AssigneeUUID *string `json:"assignee_uuid"`
|
||||
DueOn *string `json:"due_on"`
|
||||
StartOn *string `json:"start_on"`
|
||||
PlannedOn *string `json:"planned_on"`
|
||||
ReviewOn *string `json:"review_on"`
|
||||
Estimate *int `json:"estimate_minutes"`
|
||||
Complexity *int `json:"complexity"`
|
||||
WikiBody *string `json:"wiki_body,omitempty"`
|
||||
WikiPrefix *string `json:"wiki_prefix,omitempty"`
|
||||
WikiSuffix *string `json:"wiki_suffix,omitempty"`
|
||||
ReplacesDeleted string `json:"replaces_deleted,omitempty"`
|
||||
RequestID string `json:"request_id"`
|
||||
Title string `json:"title"`
|
||||
Notes string `json:"notes"`
|
||||
ProjectUUID *string `json:"project_uuid"`
|
||||
AssigneeUUID *string `json:"assignee_uuid"`
|
||||
DueOn *string `json:"due_on"`
|
||||
StartOn *string `json:"start_on"`
|
||||
PlannedOn *string `json:"planned_on"`
|
||||
ReviewOn *string `json:"review_on"`
|
||||
Estimate *int `json:"estimate_minutes"`
|
||||
Complexity *int `json:"complexity"`
|
||||
WikiBody *string `json:"wiki_body,omitempty"`
|
||||
WikiPrefix *string `json:"wiki_prefix,omitempty"`
|
||||
WikiSuffix *string `json:"wiki_suffix,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request, actor string, active bool, kind string) {
|
||||
@@ -155,7 +156,7 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"preferences": p, "defaults": defaultTask(p, time.Now().In(s.getLocation(domain))), "timezone": s.getTimezoneName(domain), "last_digest": last})
|
||||
writeEventJSON(w, 200, map[string]any{"preferences": p, "defaults": defaultTask(p, time.Now().In(s.getLocation(domain))), "timezone": s.getTimezoneName(domain), "last_digest": last, "gecko_available": s.geckoAvailable(domain)})
|
||||
return
|
||||
}
|
||||
if r.Method == "PUT" {
|
||||
@@ -197,6 +198,13 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
if input.ReplacesDeleted != "" {
|
||||
id, err := uuid.Parse(input.ReplacesDeleted)
|
||||
if err != nil || id.String() != input.ReplacesDeleted || input.RequestID != store.TaskRecreationID(input.ReplacesDeleted) {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
}
|
||||
raw, _ := json.Marshal(input)
|
||||
hash := sha256.Sum256(raw)
|
||||
requestHash := hex.EncodeToString(hash[:])
|
||||
@@ -261,7 +269,11 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
target = store.TaskCaptureWikiPath(prefix, item.Title, input.RequestID)
|
||||
pathID := input.RequestID
|
||||
if input.ReplacesDeleted != "" {
|
||||
pathID = input.ReplacesDeleted
|
||||
}
|
||||
target = store.TaskCaptureWikiPath(prefix, item.Title, pathID)
|
||||
if input.WikiSuffix != nil {
|
||||
if !store.ValidTaskMailSuffix(*input.WikiSuffix) {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
@@ -280,7 +292,11 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
item, err = s.store.CaptureTaskWithWiki(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body)
|
||||
if input.ReplacesDeleted != "" {
|
||||
item, err = s.store.RecreateCapturedTask(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body, input.ReplacesDeleted)
|
||||
} else {
|
||||
item, err = s.store.CaptureTaskWithWiki(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body)
|
||||
}
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
|
||||
@@ -62,6 +62,14 @@ func taskError(w http.ResponseWriter, err error) {
|
||||
status, code = 422, "invalid"
|
||||
case errors.Is(err, store.ErrTaskConflict):
|
||||
status, code = 412, "conflict"
|
||||
case errors.Is(err, store.ErrTaskCaptureMissing):
|
||||
status, code = 409, "capture_missing"
|
||||
case errors.Is(err, store.ErrTaskDeleted):
|
||||
status, code = 410, "deleted"
|
||||
case errors.Is(err, store.ErrTaskHasChildren):
|
||||
status, code = 409, "has_children"
|
||||
case errors.Is(err, store.ErrTaskWorking):
|
||||
status, code = 409, "working"
|
||||
case errors.Is(err, store.ErrTaskDAVIdentity):
|
||||
status, code = 409, "uid_conflict"
|
||||
case errors.Is(err, store.ErrTaskDAVRelocated):
|
||||
@@ -323,8 +331,30 @@ func (s *Server) handleTasksAPI(w http.ResponseWriter, r *http.Request) {
|
||||
writeEventJSON(w, 200, map[string]any{"items": items, "parents": parents, "next": next, "today": today})
|
||||
return
|
||||
}
|
||||
if r.Method == "DELETE" && id != "" {
|
||||
if !active {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
tag := r.Header.Get("If-Match")
|
||||
if tag == "" {
|
||||
writeEventJSON(w, 428, map[string]string{"error": "precondition"})
|
||||
return
|
||||
}
|
||||
expected, _ := strconv.ParseInt(strings.Trim(tag, `"`), 10, 64)
|
||||
if expected < 1 || tag != `"`+strconv.FormatInt(expected, 10)+`"` {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
if err := s.store.DeleteTask(ctx, domain, actor, id, expected); err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
if (r.Method != "POST" || id != "") && (r.Method != "PUT" || id == "") {
|
||||
w.Header().Set("Allow", "GET, POST, PUT")
|
||||
w.Header().Set("Allow", "GET, POST, PUT, DELETE")
|
||||
w.WriteHeader(405)
|
||||
return
|
||||
}
|
||||
|
||||
+4
@@ -4,6 +4,10 @@
|
||||
if (phase === 'login') {
|
||||
const form = document.querySelector('form[action="/_/auth/login"]')
|
||||
assert(form, 'Login form missing')
|
||||
const remember = form.elements.remember
|
||||
assert(remember && !remember.checked, 'Trusted login must be opt-in')
|
||||
remember.checked = true
|
||||
remember.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
form.elements.username.value = 'admin'
|
||||
form.elements.password.value = 'a long test password'
|
||||
sessionStorage.setItem('auth-flow-phase', 'authenticated')
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
(async()=>{
|
||||
const wait=async fn=>{for(let i=0;i<200;i++){if(fn())return;await new Promise(r=>setTimeout(r,30));}throw Error('Timeout '+fn);};
|
||||
const assert=(ok,msg)=>{if(!ok)throw Error(msg);};
|
||||
await wait(()=>document.querySelector('.browser-upload-queue'));
|
||||
const drop=(target,files)=>{const transfer=new DataTransfer();for(const [name,body]of files)transfer.items.add(new File([body],name,{type:'text/plain'}));const event=new DragEvent('drop',{bubbles:true,cancelable:true,dataTransfer:transfer});target.dispatchEvent(event);assert(event.defaultPrevented,'File drop did not prevent navigation');};
|
||||
const main=document.querySelector('.browser-main');
|
||||
drop(main,[['日本語 #1.txt','new file'],['existing.txt','must not replace'],['cancel.txt','not sent']]);
|
||||
const queued=[...document.querySelectorAll('.browser-upload-queue li')];queued[2].querySelector('button').click();
|
||||
drop(document.querySelector('.browser-row[data-path="/drop/sub"]'),[['nested.txt','nested']]);
|
||||
await wait(()=>document.querySelectorAll('.browser-upload-queue [data-state=done]').length===2&&document.querySelectorAll('.browser-upload-queue [data-state=failed]').length===1);
|
||||
await wait(()=>document.querySelector('.browser-row[data-path="/drop/日本語 #1.txt"]'));
|
||||
assert(document.querySelectorAll('.browser-upload-queue [data-state=cancelled]').length===1,'Cancellation missing');
|
||||
const card=document.querySelector('.browser-upload-queue'),rect=card.getBoundingClientRect();assert(getComputedStyle(card).position==='fixed'&&rect.right<=innerWidth&&rect.bottom<=innerHeight,'Queue not floating within viewport');
|
||||
const toggle=card.querySelector('[aria-controls]');toggle.click();assert(getComputedStyle(card.querySelector('ol')).display==='none','Queue collapse failed');toggle.click();
|
||||
assert(document.querySelectorAll('.browser-upload-queue progress[value="100"]').length===2,'Completion progress missing');
|
||||
document.body.dataset.vimReady='true';
|
||||
})().catch(e=>{const p=document.createElement('pre');p.id='error';p.textContent=e.stack;document.body.append(p);});
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
(async()=>{
|
||||
const assert=(ok,msg)=>{if(!ok)throw Error(msg)},delay=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
const wait=async fn=>{for(let n=0;n<150;n++){if(fn())return;await delay(25)}throw Error('Timeout '+fn)};
|
||||
await wait(()=>window.PagesWikiCodeMirror&&document.querySelector('.csv-edit-scroll textarea'));
|
||||
const e=window.PagesEditor;setEditorPreviewVisible(true);e.paused=true;
|
||||
if(innerWidth<=700){assert(getComputedStyle(document.querySelector('.editor-pane')).display==='none','Mobile table is not full width');setEditorPreviewVisible(false);assert(getComputedStyle(document.querySelector('.editor-pane')).display!=='none','Mobile source inaccessible');setEditorPreviewVisible(true);}
|
||||
const original=e.text(),base=e.baseRevision;
|
||||
const cell=(r,c)=>document.querySelector(`.csv-edit-scroll textarea[data-row="${r}"][data-column="${c}"]`);
|
||||
const button=text=>[...document.querySelectorAll('.csv-edit-toolbar button')].find(b=>b.textContent===text);
|
||||
let input=cell(1,0);input.focus();input.value='新しい,名前';input.dispatchEvent(new Event('input',{bubbles:true}));
|
||||
await delay(400);assert(document.activeElement===input,'Table caret lost; connected='+input.isConnected+' active='+document.activeElement?.className);
|
||||
assert(e.text()==='\ufeff"name",description\r\n"新しい,名前","a,b\r\nnext"\r\n','Untouched CSV changed');
|
||||
e.persist();assert(localStorage.getItem(e.keyPrefix()+e.tab),'CSV draft missing');
|
||||
button('↶').click();assert(e.text()===original,'Undo not lossless');button('↷').click();
|
||||
assert(await e.saveNow(),'CSV save failed');assert(e.baseRevision!==base,'Revision unchanged');
|
||||
let state=await e.state();assert(state.body===e.text()&&state.content_type==='text/csv; charset=utf-8'&&state.editable,'CSV metadata changed');
|
||||
// Markup and formulas are text, never document nodes or evaluated values.
|
||||
e.paused=true;input=cell(1,0);input.value='<img src=x onerror=alert(1)>';input.dispatchEvent(new Event('input',{bubbles:true}));
|
||||
assert(!document.querySelector('.csv-edit-pane img'),'CSV injected markup');
|
||||
assert(await e.saveNow(),'Markup-as-data save failed');
|
||||
// A competing change is always reviewed, even on different CSV fields.
|
||||
const remoteBody=PagesCSV.edit(e.text(),'cell',0,1,'remote');
|
||||
const remote=await e.post('/_/api/v1/revisions/save',{object_uuid:e.value('object-uuid'),body:remoteBody,lang:'und',content_type:e.value('page-content-type'),filename:'table.csv',base_revision_uuid:e.baseRevision,editor_principal_uuid:e.owner});
|
||||
e.paused=true;e.setText(PagesCSV.edit(e.text(),'cell',1,0,'local'));
|
||||
assert(!await e.saveNow(),'Conflicting CSV silently saved');
|
||||
assert(document.querySelector('#editor-dialog textarea[readonly]'),'CSV conflict comparison missing');
|
||||
assert((await e.state()).revision_uuid===remote.revision_uuid,'Remote CSV overwritten');
|
||||
const merged=PagesCSV.edit(remoteBody,'cell',1,0,'local');
|
||||
const areas=document.querySelectorAll('#editor-dialog textarea');areas[areas.length-1].value=merged;
|
||||
document.querySelector('#editor-dialog footer button:last-child').click();await wait(()=>!document.querySelector('#editor-dialog'));
|
||||
assert(await e.saveNow(),'Reviewed CSV failed to save');
|
||||
// Restore stages the old CSV, retains MIME and creates a new revision on save.
|
||||
e.paused=true;await e.historyDialog();const history=document.querySelector('#editor-dialog select');history.value=base;
|
||||
document.querySelector('#editor-dialog footer button:last-child').click();await wait(()=>!document.querySelector('#editor-dialog'));
|
||||
assert(e.text()===original,'History did not restore exact CSV');assert(await e.saveNow(),'Restore save failed');
|
||||
// Source syntax errors do not cause a truncated table to be written back.
|
||||
e.paused=true;e.setText('"unfinished');await e.renderPreview();assert(!document.querySelector('.csv-edit-scroll'),'Malformed CSV table editable');assert(e.text()==='"unfinished','Malformed source lost');
|
||||
e.setText(original);await e.renderPreview();
|
||||
for(let i=0;i<27;i++)button('+↧').click();
|
||||
assert(PagesCSV.parse(e.text()).rows.length===29,'Row append failed');
|
||||
assert(document.querySelectorAll('.csv-edit-scroll tbody tr').length<=25,'Table was not paged');
|
||||
button('‹').click();assert(document.querySelectorAll('.csv-edit-scroll tbody tr').length===25,'Previous page missing');
|
||||
button('+→').click();assert(PagesCSV.parse(e.text()).rows[0].cells.length===3,'Column append failed');
|
||||
cell(1,1).focus();button('−→').click();assert(PagesCSV.parse(e.text()).rows[0].cells.length===2,'Column delete failed');
|
||||
button('↶').click();cell(1,1).focus();button('−↧').click();assert(PagesCSV.parse(e.text()).rows.length===28,'Row delete failed');
|
||||
button('↶').click();
|
||||
// Spreadsheet clipboard paste is one atomic undo step, including new rows.
|
||||
e.setText(original);await e.renderPreview();
|
||||
const paste=(r,c,text)=>{const data=new DataTransfer();data.setData('text/plain',text);data.setData('text/html','<img src=x onerror=alert(1)>');const target=cell(r,c);target.focus();const event=new ClipboardEvent('paste',{clipboardData:data,bubbles:true,cancelable:true});target.dispatchEvent(event);return event;};
|
||||
assert(paste(1,0,'first\t"multi\nline"\r\n<img src=x onerror=alert(1)>\t=1+1\r\n').defaultPrevented,'Table paste not intercepted');
|
||||
const pasted=e.text();assert(PagesCSV.parse(pasted).rows.length===3,'Paste did not grow rows');
|
||||
assert(cell(1,1).value==='multi\nline','Quoted multiline clipboard broken');
|
||||
assert(!document.querySelector('.csv-edit-pane img'),'Clipboard HTML executed');
|
||||
assert(document.activeElement===cell(1,0),'Paste focus lost');
|
||||
assert(await e.saveNow(),'Pasted CSV save failed');assert((await e.state()).body===pasted,'Pasted CSV not persisted exactly');e.paused=true;
|
||||
button('↶').click();assert(e.text()===original,'Paste not undone atomically');
|
||||
button('↷').click();assert(e.text()===pasted,'Paste redo changed bytes');
|
||||
assert(paste(1,0,'valid\tdata\n"unfinished').defaultPrevented,'Malformed paste fell through');
|
||||
assert(e.text()===pasted,'Malformed paste partially applied');
|
||||
assert(paste(1,0,'a\n'.repeat(200)).defaultPrevented,'Oversize paste fell through');
|
||||
assert(e.text()===pasted,'Oversize paste partially applied');
|
||||
assert(!paste(1,0,'ordinary, text').defaultPrevented,'Single-cell text paste intercepted');
|
||||
button('↶').click();assert(e.text()===original,'Rejected paste polluted undo');
|
||||
const css=getComputedStyle(document.querySelector('.csv-edit-toolbar'));assert(css.color!==css.backgroundColor,'Toolbar lacks contrast');
|
||||
clearTimeout(e.autosaveTimer);clearInterval(e.stateTimer);e.paused=true;
|
||||
document.body.dataset.vimReady='true';
|
||||
})().catch(error=>{const p=document.createElement('pre');p.id='error';p.textContent=error.stack;document.body.append(p)});
|
||||
@@ -109,6 +109,9 @@
|
||||
e.tools();
|
||||
const style=w.getComputedStyle(d.querySelector('#editor-dialog'));
|
||||
assert(style.color!==style.backgroundColor&&style.backgroundColor!=='rgba(0, 0, 0, 0)','Dialog not themed');
|
||||
const components=d.querySelector('#editor-dialog select');components.selectedIndex=components.options.length-1;
|
||||
d.querySelector('#editor-dialog footer button:nth-child(2)').click();await wait(()=>!d.querySelector('#editor-dialog'));
|
||||
assert(e.text().includes('{{csv:/data/table.csv')&&!e.text().includes('{=html}'),'CSV macro insertion was wrapped in protected HTML');
|
||||
document.body.dataset.vimReady='true';
|
||||
} catch(error) {const box=document.createElement('div');box.id='error';box.textContent=error.stack||error.message;document.body.prepend(box)}
|
||||
})();
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
import {spawn} from 'node:child_process';
|
||||
import {writeFile} from 'node:fs/promises';
|
||||
import {setTimeout as delay} from 'node:timers/promises';
|
||||
const [url,profile,screenshot,mode]=process.argv.slice(2);
|
||||
const browser=spawn('chromium',['--headless','--no-sandbox','--disable-gpu','--disable-background-networking','--no-proxy-server','--remote-debugging-port=0',`--user-data-dir=${profile}`,'about:blank']);
|
||||
process.on('SIGTERM',()=>{browser.kill();process.exit(1);});
|
||||
let socket,logs=[];
|
||||
try {
|
||||
const endpoint=await new Promise((resolve,reject)=>{let text='';browser.stderr.on('data',c=>{text+=c;const match=text.match(/DevTools listening on (ws:\/\/[^\s]+)/);if(match)resolve(match[1]);});browser.on('error',reject);browser.on('exit',code=>reject(Error('Browser exited '+code)));});
|
||||
socket=new WebSocket(endpoint);await new Promise((resolve,reject)=>{socket.onopen=resolve;socket.onerror=reject;});
|
||||
let id=0;const pending=new Map();
|
||||
socket.onmessage=e=>{const m=JSON.parse(e.data),p=pending.get(m.id);if(p){pending.delete(m.id);m.error?p.reject(Error(JSON.stringify(m.error))):p.resolve(m.result);}else if(['Runtime.exceptionThrown','Log.entryAdded','Runtime.consoleAPICalled'].includes(m.method))logs.push(JSON.stringify(m.params));};
|
||||
const send=(method,params={},sessionId)=>new Promise((resolve,reject)=>{pending.set(++id,{resolve,reject});socket.send(JSON.stringify({id,method,params,sessionId}));});
|
||||
const {targetId}=await send('Target.createTarget',{url:'about:blank'}),{sessionId}=await send('Target.attachToTarget',{targetId,flatten:true});
|
||||
const call=(method,params)=>send(method,params,sessionId);
|
||||
const evaluate=async expression=>{const r=await call('Runtime.evaluate',{expression,returnByValue:true,awaitPromise:true});if(r.exceptionDetails)throw Error(JSON.stringify(r.exceptionDetails));return r.result.value;};
|
||||
const wait=async(expression,seconds=15)=>{for(let n=0;n<seconds*5;n++){if(await evaluate(expression))return;await delay(200);}if(screenshot){const {data}=await call('Page.captureScreenshot',{format:'png'});await writeFile(screenshot,Buffer.from(data,'base64'));}throw Error('Timeout: '+expression+'\n'+logs.slice(-30).join('\n'));};
|
||||
await call('Runtime.enable');await call('Log.enable');await call('Page.enable');
|
||||
// Only synthetic fixture diagnostics; production does not log article URLs.
|
||||
await call('Page.addScriptToEvaluateOnNewDocument',{source:`if(location.pathname.endsWith('/browser/'))import('/_/api/v1/extension/organizer.feeds/browser/assets/v0.0.1/gecko.js').then(({Gecko})=>{const init=Gecko.prototype.init;Gecko.prototype.init=function(){window.fixtureEngine=this;this.opts.printErr=console.warn;this.opts.print=console.log;return init.call(this);};});`});
|
||||
await call('Emulation.setDeviceMetricsOverride',{width:1280,height:850,deviceScaleFactor:1,mobile:false});await call('Page.navigate',{url});
|
||||
await wait(`document.querySelector('.feed-row')`);
|
||||
if(!await evaluate('crossOriginIsolated'))throw Error('Parent not isolated');
|
||||
await evaluate(`window.geckoReady=false;addEventListener('message',e=>{if(e.data?.type==='pageswiki-gecko'&&e.data.ready)geckoReady=true;});document.querySelector('.feed-row').click()`);
|
||||
await wait(`document.querySelector('.feed-original')`);await evaluate(`document.querySelector('.feed-original').click()`);
|
||||
await wait(`document.querySelector('.feed-external iframe')?.contentWindow.crossOriginIsolated`);
|
||||
if(mode==='startup-failure'){
|
||||
await wait(`document.querySelector('.feed-external [role=alert]')&&!document.querySelector('.feed-external iframe')`);
|
||||
if(!await evaluate(`document.querySelector('.feed-external a[target=_blank]').href==='http://fixture.invalid/first'`))throw Error('Failure lost original fallback');
|
||||
await evaluate(`document.querySelector('.feed-external').close()`);
|
||||
console.log('Gecko startup failure discarded iframe and retained original fallback');
|
||||
}else{
|
||||
await wait(`geckoReady || document.querySelector('.feed-external iframe')?.contentDocument?.querySelector('#status')?.textContent.includes('Viewer failed')`,100);
|
||||
if(!await evaluate('geckoReady'))throw Error('Gecko startup failed\n'+logs.slice(-8).join('\n'));
|
||||
if(mode==='public-https'){
|
||||
const engine=`document.querySelector('.feed-external iframe').contentWindow.fixtureEngine`;
|
||||
await wait(`(async()=>/documentation examples/i.test(String(await ${engine}.evalChrome('document.body.textContent'))))()`,30);
|
||||
await evaluate(`${engine}.load('https://expired.badssl.com/')`);
|
||||
await wait(`(async()=>/^about:(neterror|certerror)/.test(String(await ${engine}.evalChrome('String(document.documentURI)'))))()`,30);
|
||||
const location=await evaluate(`${engine}.evalChrome('String(document.documentURI)')`);
|
||||
if(!String(location).startsWith('about:neterror')&&!String(location).startsWith('about:certerror'))throw Error('Expired certificate was not rejected: '+location);
|
||||
await wait(`document.querySelector('.feed-external iframe').contentDocument.querySelector('canvas').hidden && document.querySelector('.feed-external iframe').contentDocument.querySelector('#status').textContent.length>20`);
|
||||
await evaluate(`document.querySelector('.feed-external').close()`);
|
||||
console.log('Public HTTPS example.com rendered; expired.badssl.com certificate rejected; closed');
|
||||
}else{
|
||||
const pixel=`(()=>{const c=document.querySelector('.feed-external iframe').contentDocument.querySelector('canvas');return Array.from(c.getContext('2d').getImageData(400,200,1,1).data)})()`;
|
||||
await wait(`${pixel}[0]===255 && ${pixel}[1]===0`);
|
||||
await evaluate(`document.querySelector('.feed-external button[title*="Ctrl+F"]').click();document.querySelector('.feed-gecko-find input').value='学舎の園';document.querySelector('.feed-gecko-find').requestSubmit()`);
|
||||
await wait(`(async()=>String(await document.querySelector('.feed-external iframe').contentWindow.fixtureEngine.evalChrome('String(window.getSelection())'))==='学舎の園')()`);
|
||||
await wait(`getComputedStyle(document.querySelector('.feed-gecko-find')).display==='flex'`);
|
||||
await evaluate(`document.querySelector('.feed-gecko-find input').value='missing-synthetic-word';document.querySelector('.feed-gecko-find').requestSubmit()`);
|
||||
await wait(`document.querySelector('.feed-gecko-find output').textContent.length>0`);
|
||||
await evaluate(`document.querySelector('.feed-gecko-find button:last-child').click()`);
|
||||
await wait(`getComputedStyle(document.querySelector('.feed-gecko-find')).display==='none'`);
|
||||
const rect=await evaluate(`(()=>{const r=document.querySelector('.feed-external iframe').getBoundingClientRect();return {x:r.x+100,y:r.y+50}})()`);
|
||||
await call('Input.dispatchMouseEvent',{type:'mousePressed',...rect,button:'left',buttons:1,clickCount:1});await call('Input.dispatchMouseEvent',{type:'mouseReleased',...rect,button:'left',buttons:0,clickCount:1});
|
||||
await wait(`${pixel}[0]===0 && ${pixel}[1]===255`);
|
||||
await wait(`document.querySelector('.feed-external a').href==='http://fixture.invalid/next'`);
|
||||
await evaluate(`[...document.querySelectorAll('.feed-external-bar button')].find(b=>b.textContent==='←').click()`);
|
||||
await wait(`${pixel}[0]===255 && ${pixel}[1]===0`);
|
||||
if(screenshot){const {data}=await call('Page.captureScreenshot',{format:'png'});await writeFile(screenshot,Buffer.from(data,'base64'));}
|
||||
await evaluate(`document.querySelector('.feed-external').close()`);await wait(`!document.querySelector('.feed-external')`);
|
||||
console.log('Real Gecko: isolation, Japanese find/missing match, Wisp article render, click navigation, viewer-local back and teardown passed');
|
||||
}
|
||||
}
|
||||
}finally{socket?.close();browser.kill();await new Promise(resolve=>browser.once('exit',resolve));await delay(300);}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import {memoryProfile} from '../../../static/js/feed-gecko-profile.mjs';
|
||||
import assert from 'node:assert/strict';
|
||||
const p=memoryProfile(10);
|
||||
await p.mkdir('cache');await p.writeFile('cache/a',new Uint8Array([1,2,3]));
|
||||
const copy=await p.readFile('cache/a');copy[0]=99;
|
||||
assert.equal((await p.readFile('cache/a'))[0],1);
|
||||
assert.deepEqual(await p.readdir(''),['cache/']);
|
||||
assert.deepEqual(await p.readdir('cache'),['a']);
|
||||
await p.rename('cache','new');assert.equal(await p.stat('cache'),null);
|
||||
assert.equal((await p.readFile('new/a')).length,3);
|
||||
await p.writeFile('b',new Uint8Array(5));await p.rename('new/a','b');
|
||||
await p.writeFile('c',new Uint8Array(7));
|
||||
await assert.rejects(p.writeFile('d',new Uint8Array(1)));
|
||||
for(const path of ['../secret','/absolute','new/../x','a\\b','a\0b'])await assert.rejects(p.stat(path));
|
||||
await p.unlink('b');await p.writeFile('d',new Uint8Array(3));
|
||||
assert.equal(await memoryProfile().stat('d'),null);
|
||||
console.log('Ephemeral profile bounds, isolation and rename passed');
|
||||
Vendored
+60
-3
@@ -4,8 +4,12 @@
|
||||
const frame=document.createElement('iframe');frame.style='display:block;width:100%;height:100vh;border:0';document.body.append(frame);
|
||||
try{
|
||||
await new Promise(resolve=>{frame.onload=resolve;frame.src='/v/feeds';});const d=frame.contentDocument,w=frame.contentWindow;
|
||||
// Let fixture requests finish before destroying a viewport's browser context.
|
||||
const fetch=w.fetch.bind(w);let pendingRequests=0;
|
||||
w.fetch=async(...args)=>{pendingRequests++;try{const response=await fetch(...args);await response.clone().arrayBuffer();return response;}finally{pendingRequests--;}};
|
||||
for(const key of Object.keys(w.localStorage))if(key.startsWith('pageswiki.feed-folders.v1:'))w.localStorage.removeItem(key);
|
||||
await wait(()=>d.querySelectorAll('.feed-row').length===100);
|
||||
const published=d.querySelector('.feed-published-time');assert(/^\d{2}:\d{2}$/.test(published.textContent),'Publication time missing');assert(published.title.includes('2026')&&published.title.includes('JST'),'Publication timezone/full tooltip missing');assert(w.getComputedStyle(published).display!=='none','Publication time hidden on mobile');assert(d.querySelector('.feed-row').children.length===5,'Publication time column missing');
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Viewport overflow');
|
||||
assert(d.title.startsWith('RSS ·'),'RSS title');assert(d.getElementById('feed-status').textContent==='','Unrequested status copy');assert(w.getComputedStyle(d.getElementById('feed-status')).display==='none','Empty status takes space');
|
||||
for(const a of d.querySelectorAll('.organizer-nav a')){assert(a.getAttribute('aria-label'),'Unnamed navigation');if(w.innerWidth<=700)assert(w.getComputedStyle(a.querySelector('span')).display==='none','Mobile tab label visible');}
|
||||
@@ -35,6 +39,59 @@
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'OPML preview overflow');
|
||||
const freshButton=()=>[...d.querySelectorAll('.feed-source>button:first-child')].find(b=>b.textContent==='FreshRSS fixture');freshButton().click();await wait(()=>d.querySelectorAll('.feed-folder').length===4&&d.querySelectorAll('.feed-row').length===2);
|
||||
const folder=id=>[...d.querySelectorAll('.feed-folder')].find(n=>n.dataset.category===id),tech=()=>folder('user/alice/label/Tech');
|
||||
const folderKey=(key,target=d,extra={})=>target.dispatchEvent(new w.KeyboardEvent('keydown',{key,shiftKey:true,bubbles:true,cancelable:true,...extra}));
|
||||
const activeFolder=()=>d.querySelector('.feed-folder-name[aria-current="true"]');
|
||||
const folderNames=()=>[...d.querySelectorAll('.feed-folder-name')];
|
||||
assert(help.textContent.includes('Shift+j/k'),'Folder shortcuts missing from help');
|
||||
// All subscriptions has no folder: start at either end, including empty/uncategorized.
|
||||
folderKey('K');await wait(()=>activeFolder()===folderNames().at(-1)&&d.querySelectorAll('.feed-row').length===0);
|
||||
folderKey('J');await delay(80);assert(activeFolder()===folderNames().at(-1),'Folder navigation wrapped past end');
|
||||
folderKey('K');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name')&&d.querySelector('.feed-row')?.textContent.includes('Catalog first'));
|
||||
assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false','Keyboard navigation expanded folder');
|
||||
folderKey('k');await wait(()=>activeFolder()===folderNames()[1]&&d.querySelector('.feed-row')?.textContent.includes('Catalog second'));
|
||||
folderKey('K');await wait(()=>activeFolder()===folderNames()[0]&&d.querySelectorAll('.feed-row').length===0);
|
||||
folderKey('K');await delay(80);assert(activeFolder()===folderNames()[0],'Folder navigation wrapped before start');
|
||||
const articleFilter=d.querySelector('#feed-toolbar select');articleFilter.value='starred';articleFilter.dispatchEvent(new w.Event('change'));await delay(80);
|
||||
folderKey('J');await wait(()=>activeFolder()===folderNames()[1]);await delay(80);assert(articleFilter.value==='starred'&&d.querySelectorAll('.feed-row').length===0,'Folder navigation lost starred filter');
|
||||
articleFilter.value='';articleFilter.dispatchEvent(new w.Event('change'));await wait(()=>d.querySelector('.feed-row')?.textContent.includes('Catalog second'));
|
||||
folderKey('K');await wait(()=>activeFolder()===folderNames()[0]&&d.querySelectorAll('.feed-row').length===0);
|
||||
const keep=activeFolder();for(const extra of [{ctrlKey:true},{metaKey:true},{altKey:true},{isComposing:true}])folderKey('J',d,extra);
|
||||
const catalogFind=d.querySelector('.feed-catalog input');folderKey('J',catalogFind);
|
||||
const editable=d.createElement('div');editable.setAttribute('contenteditable','');editable.innerHTML='<span>editing</span>';d.body.append(editable);folderKey('J',editable.firstChild);editable.remove();
|
||||
await delay(80);assert(activeFolder()===keep,'Modifier or editable input triggered folder shortcut');
|
||||
// Preserve article filters while moving from a selected subscription to the next folder.
|
||||
tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('[data-feed="feed/1"]'));
|
||||
tech().querySelector('[data-feed="feed/1"]').click();await wait(()=>d.querySelector('.feed-row')?.textContent.includes('Catalog first'));
|
||||
const globalSearch=d.querySelector('#feed-toolbar input');globalSearch.value='Catalog';globalSearch.dispatchEvent(new w.Event('input',{bubbles:true}));await delay(220);
|
||||
folderKey('H');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name'));
|
||||
folderKey('K');await wait(()=>activeFolder()===folderNames()[1]&&d.querySelector('.feed-row')?.textContent.includes('Catalog second'));
|
||||
assert(globalSearch.value==='Catalog'&&!d.querySelector('button[data-feed][aria-current="true"]'),'Folder navigation lost search or kept subscription filter');
|
||||
d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
||||
const selectedTitle=d.querySelector('#feed-reader h1').textContent;
|
||||
d.querySelector('#feed-reader .feed-actions button:last-child').click();await wait(()=>d.querySelector('.feed-capture[open]'));
|
||||
folderKey('J');await delay(80);assert(activeFolder()===folderNames()[1]&&d.querySelector('#feed-reader h1').textContent===selectedTitle,'Shortcut escaped capture modal');
|
||||
d.querySelector('.feed-capture').close();await wait(()=>!d.querySelector('.feed-capture'));
|
||||
folderKey('J');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name')&&d.querySelector('.feed-row')?.textContent.includes('Catalog first'));
|
||||
assert(!d.querySelector('.feed-layout').classList.contains('reading')&&!d.querySelector('#feed-reader .feed-body'),'Folder navigation left old article open');
|
||||
const currentCatalogFind=d.querySelector('.feed-catalog input');currentCatalogFind.value='Other';currentCatalogFind.dispatchEvent(new w.Event('input',{bubbles:true}));assert(!activeFolder(),'Catalog filter setup');
|
||||
folderKey('K');await wait(()=>activeFolder()===folderNames()[1]&&d.querySelector('.feed-row')?.textContent.includes('Catalog second'));
|
||||
assert(d.querySelector('.feed-catalog input').value==='','Folder navigation left selected folder hidden by catalog filter');
|
||||
globalSearch.value='';globalSearch.dispatchEvent(new w.Event('input',{bubbles:true}));await delay(220);
|
||||
// Rapid repeats must settle on the latest folder rather than an older request.
|
||||
folderKey('J');folderKey('J');folderKey('K');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name')&&d.querySelector('.feed-row')?.textContent.includes('Catalog first'));await delay(100);
|
||||
assert(d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog first'),'Stale folder request won');
|
||||
// Horizontal hierarchy navigation, with unchanged article filters and bounded siblings.
|
||||
folderKey('L');await wait(()=>tech().querySelector('button[data-feed="feed/1"][aria-current="true"]'));
|
||||
assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='true','L did not expand folder');
|
||||
folderKey('L');folderKey('J');folderKey('K');await delay(80);
|
||||
assert(tech().querySelector('button[data-feed="feed/1"][aria-current="true"]'),'Leaf keys escaped the current folder');
|
||||
folderKey('H');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name'));
|
||||
folderKey('H');await wait(()=>d.querySelector('.feed-tree-all[aria-current="true"]'));
|
||||
assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false','H did not collapse folder');
|
||||
folderKey('H');await delay(80);assert(d.querySelector('.feed-tree-all[aria-current="true"]'),'H escaped catalog root');
|
||||
folderKey('L');await wait(()=>activeFolder()===folderNames()[0]);
|
||||
folderKey('L');await delay(80);assert(activeFolder()===folderNames()[0]&&!folderNames()[0].closest('.feed-folder').querySelector('button[data-feed]'),'L fabricated an empty-folder child');
|
||||
tech().querySelector('.feed-folder-name').click();await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name'));
|
||||
tech().querySelector('.feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog first'));
|
||||
assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false','Selecting folder expands it unexpectedly');tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('button[data-feed="feed/1"]'));
|
||||
const empty=folder('user/-/label/Empty/Folder');assert(empty.querySelector('.feed-folder-name span').textContent==='Empty/Folder','Slash label split');empty.querySelector('.feed-folder-toggle').click();assert(!empty.querySelector('button[data-feed]'),'Empty folder fabricated a feed');empty.querySelector('.feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===0);
|
||||
@@ -62,9 +119,9 @@
|
||||
assert((await w.fetch('/fixture/check-feed-history',{method:'POST'})).status===204,'Recheck worker failed');d.getElementById('feed-history-reload').click();await wait(()=>!receipt(seed.missing)&&receipt(seed.orphan));
|
||||
const hs=d.getElementById('feed-history-state');hs.value='all';hs.dispatchEvent(new w.Event('change'));await wait(()=>receipt(seed.missing)?.querySelector('[data-state=confirmed]'));
|
||||
d.dispatchEvent(new w.KeyboardEvent('keydown',{key:'Escape',bubbles:true}));assert(!d.querySelector('.feed-layout').classList.contains('action-history'),'History escape');
|
||||
d.getElementById('feed-history').click();await wait(()=>receipt(seed.orphan));d.getElementById('feed-history-state').value='all';d.getElementById('feed-history-state').dispatchEvent(new w.Event('change'));await wait(()=>receipt(seed.missing)?.querySelector('[data-state=confirmed]'));
|
||||
const previousHistory=d.getElementById('feed-history-panel');d.getElementById('feed-history').click();await wait(()=>d.getElementById('feed-history-panel')!==previousHistory&&receipt(seed.orphan));d.getElementById('feed-history-state').value='all';d.getElementById('feed-history-state').dispatchEvent(new w.Event('change'));await wait(()=>receipt(seed.missing)?.querySelector('[data-state=confirmed]'));
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'History final overflow');
|
||||
const probe=document.createElement('iframe');probe.hidden=true;document.body.append(probe);await new Promise(resolve=>{probe.onload=resolve;probe.src='/v/feeds?source='+encodeURIComponent(source.uuid);});await wait(()=>probe.contentDocument.querySelector('.feed-folder[data-category="user/alice/label/Tech"] .feed-folder-toggle')?.getAttribute('aria-expanded')==='true');probe.remove();
|
||||
freshButton().click();await wait(()=>tech()?.querySelector('button[data-feed="feed/1"]'));if(w.innerWidth<=700){d.querySelector('#feed-toolbar button').click();await wait(()=>d.querySelector('.feed-layout').classList.contains('sources-open'));assert(w.getComputedStyle(d.getElementById('feed-sources')).display!=='none','Mobile folders hidden');}assert(d.documentElement.scrollWidth<=w.innerWidth,'Folder tree overflow');document.body.dataset.vimReady='1';
|
||||
const probe=document.createElement('iframe');probe.hidden=true;document.body.append(probe);await new Promise(resolve=>{probe.onload=resolve;probe.src='/v/feeds?source='+encodeURIComponent(source.uuid);});await wait(()=>probe.contentDocument.querySelector('.feed-folder[data-category="user/alice/label/Tech"] .feed-folder-toggle')?.getAttribute('aria-expanded')==='true'&&probe.contentDocument.querySelectorAll('.feed-row').length===2);probe.remove();
|
||||
const previousCatalog=d.querySelector('.feed-catalog');freshButton().click();await wait(()=>d.querySelector('.feed-catalog')!==previousCatalog&&tech()?.querySelector('button[data-feed="feed/1"]')&&d.querySelectorAll('.feed-row').length===2);if(w.innerWidth<=700){d.querySelector('#feed-toolbar button').click();await wait(()=>d.querySelector('.feed-layout').classList.contains('sources-open'));assert(w.getComputedStyle(d.getElementById('feed-sources')).display!=='none','Mobile folders hidden');}assert(d.documentElement.scrollWidth<=w.innerWidth,'Folder tree overflow');await wait(()=>pendingRequests===0);await delay(100);document.body.dataset.vimReady='1';
|
||||
}catch(e){const out=document.createElement('pre');out.id='error';out.textContent=e.stack;document.body.append(out);}
|
||||
})();
|
||||
@@ -40,6 +40,8 @@ window.addEventListener('load',async()=>{const wait=async(fn)=>{for(let i=0;i<12
|
||||
}else if(path==='/v/plan/dashboard'){
|
||||
await wait(()=>document.querySelectorAll('.productivity-day').length>300);if(!document.querySelector('.productivity-day[data-level="2"]'))throw Error('Seven-point completion missing');
|
||||
if(document.querySelectorAll('[data-widget]').length!==6)throw Error('Widget registry missing');
|
||||
await wait(()=>document.querySelector('[data-widget=progress] .dashboard-progress'));
|
||||
if(document.querySelector('[data-widget=progress] .widget-body small'))throw Error('Completion widget explanation should not be displayed');
|
||||
const tab=document.querySelector('[data-tab=done]');tab.click();await wait(()=>document.querySelector('#widget-panel-tasks').textContent.includes('Browser work task'));if(location.pathname!=='/v/plan/dashboard'||document.querySelector('#organizer-dashboard iframe'))throw Error('Tab navigation escaped widget');
|
||||
document.querySelector('#dashboard-controls button[aria-pressed]').click();const width=document.querySelector('[data-widget=tasks] [data-size=width]');width.value='6';width.dispatchEvent(new Event('change'));const height=document.querySelector('[data-widget=tasks] [data-size=height]');height.value='5';height.dispatchEvent(new Event('change'));
|
||||
document.querySelector('[data-widget=tasks] .widget-arrange button').click();document.querySelector('#dashboard-controls button:last-child').click();await wait(()=>document.querySelector('#dashboard-status').textContent.includes('保存しました'));const layout=await fetch('/_/api/v1/extension/organizer.tasks/dashboard').then(r=>r.json());if(layout.widgets[2].id!=='tasks'||layout.widgets[2].width!==6||layout.widgets[2].height!==5||layout.widgets[2].tab!=='done')throw Error('Layout did not persist');
|
||||
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
(async()=>{
|
||||
const assert=(ok,msg)=>{if(!ok)throw Error(msg)},delay=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
const wait=async fn=>{for(let n=0;n<300;n++){if(fn())return;await delay(25)}throw Error('Timeout '+fn)};
|
||||
const ready=()=>document.querySelector('.slides-frame[data-ready=true]');
|
||||
await wait(()=>window.PagesSlides);
|
||||
const e=window.PagesEditor;
|
||||
if(e){await wait(()=>document.querySelector('[data-editor-action=slides]')&&e.preview);e.paused=true;document.querySelector('[data-editor-action=slides]').click();}
|
||||
await wait(ready);
|
||||
const frame=ready(),source=e?.text(),historyLength=history.length;
|
||||
assert(frame.dataset.count==='2','Wrong slide count');
|
||||
assert(frame.sandbox.contains('allow-scripts')&&!frame.sandbox.contains('allow-same-origin'),'Isolation missing');
|
||||
let isolated=false;try{isolated=!frame.contentDocument}catch{isolated=true}assert(isolated,'Frame can access parent origin');
|
||||
assert(frame.getBoundingClientRect().height>=240,'Slide frame collapsed');
|
||||
assert(frame.getBoundingClientRect().width<=innerWidth,'Mobile slide overflow');
|
||||
if(e&&innerWidth<=700){assert(getComputedStyle(document.querySelector('.editor-pane')).display==='none','Mobile preview not full width');setEditorPreviewVisible(false);assert(getComputedStyle(document.querySelector('.editor-pane')).display!=='none','Mobile source inaccessible');setEditorPreviewVisible(true);}
|
||||
const host=frame.parentElement;
|
||||
// Verify the defensive DOM boundary independently of server sanitization.
|
||||
PagesSlides.render(host,'<h1 onclick="alert(1)" data-background-iframe="https://evil.invalid">Safe</h1><script>alert(1)</scr'+'ipt><iframe src="https://evil.invalid"></iframe><img src="https://evil.invalid/x"><hr><p>Next</p>','/deck');
|
||||
await wait(ready);
|
||||
let projected=ready().srcdoc;
|
||||
assert(!projected.includes('evil.invalid')&&!projected.includes('onclick=')&&!projected.includes('alert(1)'),'Unsafe content entered frame');
|
||||
assert(!projected.includes('data-background-iframe'),'Reveal directives leaked');
|
||||
assert(history.length===historyLength,'Slide render changed history');
|
||||
let rejected=false;try{PagesSlides.render(host,'<p>x</p><hr>'.repeat(101),'/deck')}catch{rejected=true}assert(rejected,'Too many slides accepted');
|
||||
if(e){
|
||||
assert(e.text()===source,'Preview mutated canonical source');
|
||||
e.setText('<h1>Edited</h1><hr><p>Second</p><hr><p>Third</p>');await e.renderPreview();await wait(ready);assert(ready().dataset.count==='3','Live preview stale');
|
||||
document.querySelector('[data-editor-action=slides]').click();await wait(()=>!document.querySelector('.slides-frame'));assert(e.preview.textContent.includes('Edited'),'Normal preview not restored');
|
||||
document.querySelector('[data-editor-action=slides]').click();await wait(ready);
|
||||
clearTimeout(e.autosaveTimer);clearInterval(e.stateTimer);e.paused=true;
|
||||
}else{PagesSlides.render(host,document.querySelector('[data-slides-source]').value,'/deck');await wait(ready);}
|
||||
document.body.dataset.vimReady='true';
|
||||
})().catch(error=>{const p=document.createElement('pre');p.id='error';p.textContent=error.stack;document.body.append(p)});
|
||||
+32
@@ -130,6 +130,38 @@ window.addEventListener('load', async () => {
|
||||
document.body.dataset.vimReady='true';return;
|
||||
}
|
||||
await wait(()=>$('status').textContent.includes('ありません'));
|
||||
// Deletion shares the archive footer, not a UUID-search workflow.
|
||||
$('new').click();await wait(()=>document.querySelector('#tasks-form [name=title]'));
|
||||
if(!$('delete').hidden)throw Error('Unsaved task must not offer deletion');if(!$('page-open').hidden||$('page-open').hasAttribute('href'))throw Error('New task leaked a related page');$('close').click();
|
||||
$('quick-title').value='Disposable deletion fixture';$('capture').requestSubmit();
|
||||
await wait(()=>$('list').querySelector('[data-action=detail]'));$('list').querySelector('[data-action=detail]').click();
|
||||
await wait(()=>!$('delete').hidden);
|
||||
if($('delete').parentElement!==$('archive').parentElement||$('delete').textContent!=='削除')throw Error('Delete action is not beside archive');
|
||||
const deletionID=$('list').querySelector('[data-task-id]').dataset.taskId;
|
||||
window.confirm=()=>false;$('delete').click();
|
||||
if(!$('dialog').open)throw Error('Cancelled deletion closed the editor');
|
||||
const deletionAPI='/_/api/v1/extension/organizer.tasks/items/'+deletionID;
|
||||
const deletionItem=(await fetch(deletionAPI).then(r=>r.json())).item;
|
||||
if(!$('page-open').hidden)throw Error('Unlinked task offered related page');
|
||||
// The footer link uses the saved, authorized path, never unsaved input.
|
||||
value('page_path','/projects/browser');$('form').requestSubmit();await wait(()=>!$('dialog').open);
|
||||
$('list').querySelector('[data-action=detail]').click();await wait(()=>!$('page-open').hidden);
|
||||
const link=$('page-open');if(link.parentElement!==$('save').parentElement||link.pathname!=='/projects/browser'||link.target!=='_blank'||!link.rel.includes('noopener'))throw Error('Unsafe or misplaced related page navigation');
|
||||
value('title','Unsaved title kept');if(link.hidden||!$('dialog').open)throw Error('Editing task hid the saved page navigation');
|
||||
if(innerWidth<761&&link.getBoundingClientRect().height<44)throw Error('Related page touch target too small');
|
||||
document.querySelector('.task-editor-advanced').open=true;
|
||||
value('page_path','//external.invalid/unsaved');if(!link.hidden||link.hasAttribute('href'))throw Error('Unsaved path exposed a link');
|
||||
value('page_path','/projects/browser');if(link.hidden)throw Error('Restored path did not restore related link');
|
||||
window.confirm=()=>true;$('close').click();$('list').querySelector('[data-action=detail]').click();await wait(()=>!$('page-open').hidden);
|
||||
const freshDeletionItem=(await fetch(deletionAPI).then(r=>r.json())).item;
|
||||
const changed=await fetch(deletionAPI,{method:'PUT',headers:{'Content-Type':'application/json','If-Match':'"'+freshDeletionItem.version+'"'},body:JSON.stringify({...freshDeletionItem,title:'Updated deletion fixture'})});
|
||||
if(!changed.ok)throw Error('Deletion conflict fixture failed');
|
||||
window.confirm=()=>true;$('delete').click();await wait(()=>$('error').textContent.includes('別の画面'));
|
||||
if(!$('dialog').open||$('delete').disabled)throw Error('Deletion failure did not keep a usable editor');
|
||||
$('close').click();$('refresh').click();await wait(()=>$('list').querySelector('input[name=title]')?.value==='Updated deletion fixture');
|
||||
$('list').querySelector('[data-action=detail]').click();await wait(()=>!$('delete').hidden);$('delete').click();
|
||||
await wait(()=>!$('dialog').open&&!$('list').querySelector('[data-task-id]'));
|
||||
if((await fetch(deletionAPI)).status!==404)throw Error('Deleted task remains readable');
|
||||
$('quick-title').value='Write the first task';$('capture').requestSubmit();
|
||||
await wait(()=>$('list').querySelector('[data-action=detail]'));
|
||||
$('list').querySelector('[data-action=detail]').click();
|
||||
|
||||
+12
@@ -58,6 +58,18 @@ try {
|
||||
const layout=await evaluate(`fetch('/_/api/v1/extension/organizer.tasks/dashboard').then(r=>r.json())`);if(layout.widgets[0].id!=='today'||layout.widgets.find(w=>w.id==='tasks').height!==4)throw Error('Pointer layout persistence failed');
|
||||
await evaluate(`document.querySelector('#dashboard-controls button[aria-pressed]').click();scrollTo(0,0)`);
|
||||
}
|
||||
if (ready && process.env.PAGESWIKI_SLIDES_BROWSER === '1') {
|
||||
const evaluate = async expression => (await call('Runtime.evaluate', {expression, returnByValue:true})).result.value;
|
||||
const initialHistory = await evaluate('history.length');
|
||||
await evaluate("document.querySelector('.slides-frame').focus()");
|
||||
const key = async (key, code) => {await call('Input.dispatchKeyEvent',{type:'keyDown',key,code:key,windowsVirtualKeyCode:code});await call('Input.dispatchKeyEvent',{type:'keyUp',key,code:key,windowsVirtualKeyCode:code});};
|
||||
await key('ArrowRight',39);
|
||||
let advanced=false;for(let n=0;n<30;n++){if(await evaluate("document.querySelector('.slides-frame').parentElement.dataset.slideIndex") === '1'){advanced=true;break;}await delay(100);}
|
||||
if(!advanced)throw Error('Slide keyboard navigation failed');
|
||||
await key('ArrowLeft',37);await delay(150);
|
||||
if(await evaluate("document.querySelector('.slides-frame').parentElement.dataset.slideIndex") !== '0')throw Error('Slide previous navigation failed');
|
||||
if(await evaluate('history.length') !== initialHistory)throw Error('Slides polluted browser history');
|
||||
}
|
||||
if (screenshot) {
|
||||
const {data} = await call('Page.captureScreenshot', {format: 'png'});
|
||||
await writeFile(screenshot, Buffer.from(data, 'base64'));
|
||||
|
||||
@@ -39,6 +39,7 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
defer r.MultipartForm.RemoveAll()
|
||||
file, header, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
http.Error(w, "file is required", http.StatusBadRequest)
|
||||
@@ -83,6 +84,11 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
objectUUID, err := s.store.ResolvePathInDomain(domainUUID, targetPath)
|
||||
createOnly := r.Header.Get("If-None-Match") == "*"
|
||||
if err == nil && createOnly {
|
||||
http.Error(w, "file already exists", http.StatusPreconditionFailed)
|
||||
return
|
||||
}
|
||||
if err == nil && mode == "enforcing" {
|
||||
// upload and write-once grants never overwrite an existing object.
|
||||
if s.store.Authorize(store.AuthorizationRequest{DomainUUID: domainUUID, PrincipalUUID: principal.UUID, Capability: "write", TargetType: "path", TargetID: targetPath}) != nil {
|
||||
@@ -92,6 +98,13 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
objectUUID, err = s.store.CreatePageAtPathInDomain(domainUUID, targetPath)
|
||||
if err != nil && createOnly {
|
||||
// A concurrent creator wins; never turn this into an overwrite.
|
||||
if _, resolveErr := s.store.ResolvePathInDomain(domainUUID, targetPath); resolveErr == nil {
|
||||
http.Error(w, "file already exists", http.StatusPreconditionFailed)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
@@ -113,17 +126,23 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.TrimSpace(language) == "" {
|
||||
language = "und"
|
||||
}
|
||||
if _, err := s.store.SaveRevisionContent(
|
||||
revision, err := s.store.SaveRevisionContent(
|
||||
objectUUID,
|
||||
payload,
|
||||
"web upload: "+originalName,
|
||||
language,
|
||||
contentType,
|
||||
originalName,
|
||||
); err != nil {
|
||||
)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if strings.Contains(r.Header.Get("Accept"), "application/json") {
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
writeEventJSON(w, http.StatusCreated, map[string]string{"path": targetPath, "object_uuid": objectUUID, "revision_uuid": revision.UUID})
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, targetPath, http.StatusSeeOther)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -85,6 +86,51 @@ func TestWebUploadCreatesAndRevisesSpecifiedPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebUploadCreateOnlyJSON(t *testing.T) {
|
||||
s, token, domain := configFixture(t)
|
||||
upload := func(payload string, authenticated bool) *httptest.ResponseRecorder {
|
||||
var body bytes.Buffer
|
||||
writer := multipart.NewWriter(&body)
|
||||
writer.WriteField("path", "/uploads/日本語 #1.txt")
|
||||
file, _ := writer.CreateFormFile("file", "日本語 #1.txt")
|
||||
file.Write([]byte(payload))
|
||||
writer.Close()
|
||||
r := httptest.NewRequest("POST", "http://localhost/v/upload", &body)
|
||||
r.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
r.Header.Set("Accept", "application/json")
|
||||
r.Header.Set("If-None-Match", "*")
|
||||
if authenticated {
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
s.handleUpload(w, r)
|
||||
return w
|
||||
}
|
||||
if w := upload("denied", false); w.Code != 403 {
|
||||
t.Fatalf("unauthorized: %d", w.Code)
|
||||
}
|
||||
w := upload("original", true)
|
||||
var result map[string]string
|
||||
if w.Code != 201 || json.Unmarshal(w.Body.Bytes(), &result) != nil || result["path"] != "/uploads/日本語 #1.txt" || result["revision_uuid"] == "" {
|
||||
t.Fatalf("JSON upload %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
if w = upload("overwrite", true); w.Code != 412 {
|
||||
t.Fatalf("duplicate: %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
object, err := s.store.ResolvePathInDomain(domain, result["path"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
revisions, err := s.store.ListRevisions(object)
|
||||
if err != nil || len(revisions) != 1 {
|
||||
t.Fatalf("unexpected revisions %d %v", len(revisions), err)
|
||||
}
|
||||
rev, err := s.store.GetRevision(revisions[0].UUID)
|
||||
if err != nil || rev.Body != "original" {
|
||||
t.Fatal("overwritten", err)
|
||||
}
|
||||
}
|
||||
|
||||
func mustServerDomainUUID(t *testing.T, st *store.Store) string {
|
||||
t.Helper()
|
||||
domain, err := st.GetDefaultDomain()
|
||||
|
||||
@@ -164,6 +164,10 @@ func (s *Store) CreateBrowserAuthSession(domainUUID, principalUUID string, mfaLe
|
||||
}
|
||||
|
||||
func (s *Store) createTypedAuthSession(domainUUID, principalUUID string, mfaLevel int, prefix string) (string, error) {
|
||||
return s.createTypedAuthSessionForLifetime(domainUUID, principalUUID, mfaLevel, prefix, s.AuthSessionLifetime(domainUUID))
|
||||
}
|
||||
|
||||
func (s *Store) createTypedAuthSessionForLifetime(domainUUID, principalUUID string, mfaLevel int, prefix string, lifetime time.Duration) (string, error) {
|
||||
raw, _, err := authToken()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -177,7 +181,7 @@ func (s *Store) createTypedAuthSession(domainUUID, principalUUID string, mfaLeve
|
||||
result, err := s.DB.Exec(`INSERT INTO auth_sessions(uuid,token_hash,principal_uuid,domain_uuid,auth_time_ms,expires_at_ms,last_seen_at_ms,mfa_level)
|
||||
SELECT ?,?,p.uuid,m.domain_uuid,?,?,?,? FROM principals p JOIN domain_memberships m ON m.principal_uuid=p.uuid
|
||||
WHERE p.uuid=? AND p.state IN ('active','readonly') AND m.domain_uuid=? AND m.state='active'`,
|
||||
uuid.NewString(), hash, now, now+s.AuthSessionLifetime(domainUUID).Milliseconds(), now, mfaLevel, principalUUID, domainUUID)
|
||||
uuid.NewString(), hash, now, now+lifetime.Milliseconds(), now, mfaLevel, principalUUID, domainUUID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@ var cliAuthMigrations = []db.SQLMigration{{Version: 1, Name: "cli_oidc_handoff",
|
||||
schemaUnique("auth_cli_requests", "id"), schemaUnique("auth_cli_requests", "device_hash"),
|
||||
schemaIndex("auth_cli_requests", "auth_cli_domain_created", "domain_uuid,created_ms"),
|
||||
schemaIndex("auth_cli_requests", "auth_cli_expiry", "expires_ms"),
|
||||
}}}
|
||||
}}, {Version: 2, Name: "cli_trusted_session_choice", Statements: []string{
|
||||
`ALTER TABLE auth_cli_requests ADD COLUMN remember INTEGER NOT NULL DEFAULT 0 CHECK(remember IN (0,1))`,
|
||||
}, Assertions: []string{schemaColumns("auth_cli_requests", "remember")}}}
|
||||
|
||||
var (
|
||||
ErrCLIPending = errors.New("authorization_pending")
|
||||
@@ -39,11 +41,16 @@ var (
|
||||
type CLIAuthRequest struct {
|
||||
ID, Origin, State, BrowserHash, PrincipalUUID string
|
||||
ExpiresMS int64
|
||||
Remember bool
|
||||
}
|
||||
|
||||
// Admission is one write statement; concurrent unauthenticated requests cannot
|
||||
// race the caps. Requests are retained for ten minutes for issuance accounting.
|
||||
func (s *Store) StartCLIAuth(ctx context.Context, domain, origin, challenge string) (id, device, code string, err error) {
|
||||
return s.StartCLIAuthForLogin(ctx, domain, origin, challenge, false)
|
||||
}
|
||||
|
||||
func (s *Store) StartCLIAuthForLogin(ctx context.Context, domain, origin, challenge string, remember bool) (id, device, code string, err error) {
|
||||
if s.ReadOnly {
|
||||
return "", "", "", ErrReadOnly
|
||||
}
|
||||
@@ -66,10 +73,10 @@ func (s *Store) StartCLIAuth(ctx context.Context, domain, origin, challenge stri
|
||||
return
|
||||
}
|
||||
var result sql.Result
|
||||
result, err = s.DB.ExecContext(ctx, `INSERT INTO auth_cli_requests(id,domain_uuid,origin,device_hash,challenge,code_hash,created_ms,expires_ms)
|
||||
SELECT ?,?,?,?,?,?,?,? WHERE (SELECT count(*) FROM auth_cli_requests)<4096
|
||||
result, err = s.DB.ExecContext(ctx, `INSERT INTO auth_cli_requests(id,domain_uuid,origin,device_hash,challenge,code_hash,created_ms,expires_ms,remember)
|
||||
SELECT ?,?,?,?,?,?,?,?,? WHERE (SELECT count(*) FROM auth_cli_requests)<4096
|
||||
AND (SELECT count(*) FROM auth_cli_requests WHERE domain_uuid=? AND created_ms>?)<64`,
|
||||
id, domain, origin, hashAuthToken(device), challenge, hashAuthToken(code), now, now+300000, domain, now-300000)
|
||||
id, domain, origin, hashAuthToken(device), challenge, hashAuthToken(code), now, now+300000, remember, domain, now-300000)
|
||||
if err == nil {
|
||||
if n, e := result.RowsAffected(); e != nil {
|
||||
err = e
|
||||
@@ -82,7 +89,7 @@ func (s *Store) StartCLIAuth(ctx context.Context, domain, origin, challenge stri
|
||||
|
||||
func (s *Store) CLIAuthRequest(ctx context.Context, domain, origin, id string) (*CLIAuthRequest, error) {
|
||||
var grant CLIAuthRequest
|
||||
err := s.DB.QueryRowContext(ctx, `SELECT id,origin,state,browser_hash,principal_uuid,expires_ms FROM auth_cli_requests WHERE id=? AND domain_uuid=? AND origin=? AND expires_ms>?`, id, domain, origin, time.Now().UnixMilli()).Scan(&grant.ID, &grant.Origin, &grant.State, &grant.BrowserHash, &grant.PrincipalUUID, &grant.ExpiresMS)
|
||||
err := s.DB.QueryRowContext(ctx, `SELECT id,origin,state,browser_hash,principal_uuid,expires_ms,remember FROM auth_cli_requests WHERE id=? AND domain_uuid=? AND origin=? AND expires_ms>?`, id, domain, origin, time.Now().UnixMilli()).Scan(&grant.ID, &grant.Origin, &grant.State, &grant.BrowserHash, &grant.PrincipalUUID, &grant.ExpiresMS, &grant.Remember)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, ErrCLIExpired
|
||||
}
|
||||
@@ -168,15 +175,17 @@ func (s *Store) ExchangeCLIAuth(ctx context.Context, domain, origin, device, ver
|
||||
}
|
||||
now := time.Now().UnixMilli()
|
||||
lifetime := s.AuthSessionLifetime(domain).Milliseconds()
|
||||
trustedLifetime := s.LoginSessionLifetime(domain, true).Milliseconds()
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer tx.Rollback()
|
||||
var id, state, browser string
|
||||
var remember bool
|
||||
err = tx.QueryRowContext(ctx, `UPDATE auth_cli_requests SET next_poll_ms=?,state=CASE WHEN state='approved' THEN 'consumed' ELSE state END
|
||||
WHERE device_hash=? AND challenge=? AND domain_uuid=? AND origin=? AND expires_ms>? AND next_poll_ms<=? AND state IN ('pending','approved','denied')
|
||||
RETURNING id,state,browser_hash`, now+5000, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now, now).Scan(&id, &state, &browser)
|
||||
RETURNING id,state,browser_hash,remember`, now+5000, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now, now).Scan(&id, &state, &browser, &remember)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
var exists int
|
||||
e := tx.QueryRowContext(ctx, `SELECT count(*) FROM auth_cli_requests WHERE device_hash=? AND challenge=? AND domain_uuid=? AND origin=? AND expires_ms>? AND state IN ('pending','approved','denied')`, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now).Scan(&exists)
|
||||
@@ -204,6 +213,9 @@ func (s *Store) ExchangeCLIAuth(ctx context.Context, domain, origin, device, ver
|
||||
return
|
||||
}
|
||||
var raw string
|
||||
if remember {
|
||||
lifetime = trustedLifetime
|
||||
}
|
||||
raw, _, err = authToken()
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -8,10 +8,68 @@ import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"pageswiki/internal/db"
|
||||
)
|
||||
|
||||
const cliTestOrigin = "https://wiki.example"
|
||||
|
||||
func TestCLIAuthTrustedMigrationPreservesExistingRequests(t *testing.T) {
|
||||
s := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if err := db.ApplySQLiteMigrations(ctx, s.DB, "cli-auth", cliAuthMigrations[:1]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.DB.Exec(`INSERT INTO auth_cli_requests(id,domain_uuid,origin,device_hash,challenge,code_hash,created_ms,expires_ms) VALUES('old','domain','https://wiki.example','device','challenge','code',1,2)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := db.ApplySQLiteMigrations(ctx, s.DB, "cli-auth", cliAuthMigrations); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var remember int
|
||||
var challenge string
|
||||
if err := s.DB.QueryRow(`SELECT remember,challenge FROM auth_cli_requests WHERE id='old'`).Scan(&remember, &challenge); err != nil || remember != 0 || challenge != "challenge" {
|
||||
t.Fatalf("old grant changed: %d %q %v", remember, challenge, err)
|
||||
}
|
||||
if _, err := s.DB.Exec(`UPDATE auth_cli_requests SET remember=2`); err == nil {
|
||||
t.Fatal("invalid remember flag accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTOTPLoginBindsTrustedChoice(t *testing.T) {
|
||||
for _, remember := range []bool{false, true} {
|
||||
s, p, _ := cliAuthFixture(t)
|
||||
secret, err := s.BeginTOTPEnrollment(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
code, err := totpCode(secret, time.Now().Unix()/30)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.ConfirmTOTPEnrollment(p, code); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Synthetic fixture: permit this time step once for login after enrollment.
|
||||
if _, err = s.DB.Exec(`UPDATE auth_credentials SET parameters_json='{"last_counter":0}' WHERE principal_uuid=? AND kind='totp'`, p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
challenge, err := s.CreateTOTPLoginChallengeForLogin("domain", p, remember)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, choice, err := s.CompleteTOTPLoginChallengeForLogin("domain", challenge, code)
|
||||
if err != nil || got != p || choice != remember {
|
||||
t.Fatalf("bound choice: %q %v %v", got, choice, err)
|
||||
}
|
||||
if _, _, err = s.CompleteTOTPLoginChallengeForLogin("domain", challenge, code); err == nil {
|
||||
t.Fatal("challenge replay accepted")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cliAuthFixture(t *testing.T) (*Store, string, string) {
|
||||
t.Helper()
|
||||
s := newSchemaTestStore(t)
|
||||
|
||||
@@ -30,3 +30,37 @@ func (s *Store) SetAuthSessionLifetimeMinutes(domain string, minutes int) error
|
||||
func (s *Store) AuthSessionLifetime(domain string) time.Duration {
|
||||
return time.Duration(s.AuthSessionLifetimeMinutes(domain)) * time.Minute
|
||||
}
|
||||
|
||||
// Opt-in persistent sessions have a separate, administrator-controlled ceiling.
|
||||
// Zero disables the option. Existing sessions retain their original expiry.
|
||||
func (s *Store) TrustedSessionDays(domain string) int {
|
||||
raw, err := s.GetConfigInDomain(domain, "auth_trusted_session_days")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
if raw == "" {
|
||||
return 30
|
||||
}
|
||||
days, err := strconv.Atoi(raw)
|
||||
if err != nil || days < 0 || days > 30 {
|
||||
return 0
|
||||
}
|
||||
return days
|
||||
}
|
||||
|
||||
func (s *Store) LoginSessionLifetime(domain string, remember bool) time.Duration {
|
||||
if days := s.TrustedSessionDays(domain); remember && days > 0 {
|
||||
return time.Duration(days) * 24 * time.Hour
|
||||
}
|
||||
return s.AuthSessionLifetime(domain)
|
||||
}
|
||||
|
||||
func (s *Store) CreateLoginSession(domain, principal string, mfa int, browser, remember bool) (string, time.Duration, error) {
|
||||
lifetime := s.LoginSessionLifetime(domain, remember)
|
||||
prefix := "pw_api_"
|
||||
if browser {
|
||||
prefix = "pw_browser_"
|
||||
}
|
||||
token, err := s.createTypedAuthSessionForLifetime(domain, principal, mfa, prefix, lifetime)
|
||||
return token, lifetime, err
|
||||
}
|
||||
@@ -176,36 +176,51 @@ func TOTPURI(secret, account, issuer string) string {
|
||||
}
|
||||
|
||||
func (s *Store) CreateTOTPLoginChallenge(domainUUID, principalUUID string) (string, error) {
|
||||
return s.CreateTOTPLoginChallengeForLogin(domainUUID, principalUUID, false)
|
||||
}
|
||||
|
||||
func (s *Store) CreateTOTPLoginChallengeForLogin(domainUUID, principalUUID string, remember bool) (string, error) {
|
||||
token, hash, err := authToken()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
now := time.Now().UnixMilli()
|
||||
payload, _ := json.Marshal(map[string]string{"principal_uuid": principalUUID})
|
||||
payload, _ := json.Marshal(map[string]any{"principal_uuid": principalUUID, "remember": remember})
|
||||
_, err = s.DB.Exec(`INSERT INTO auth_challenges(uuid,domain_uuid,principal_uuid,kind,token_hash,payload_json,expires_at_ms,created_at_ms) VALUES(?,?,?,?,?,?,?,?)`, uuid.NewString(), domainUUID, principalUUID, "totp-login", hash, string(payload), now+5*60*1000, now)
|
||||
return token, err
|
||||
}
|
||||
func (s *Store) CompleteTOTPLoginChallenge(domainUUID, token, code string) (string, error) {
|
||||
id, _, err := s.CompleteTOTPLoginChallengeForLogin(domainUUID, token, code)
|
||||
return id, err
|
||||
}
|
||||
|
||||
func (s *Store) CompleteTOTPLoginChallengeForLogin(domainUUID, token, code string) (string, bool, error) {
|
||||
sum := sha256.Sum256([]byte(token))
|
||||
hash := base64.RawURLEncoding.EncodeToString(sum[:])
|
||||
var challengeUUID, principalUUID string
|
||||
var challengeUUID, principalUUID, payload string
|
||||
var expires int64
|
||||
var attempts int
|
||||
err := s.DB.QueryRow(`SELECT uuid,principal_uuid,expires_at_ms,attempt_count FROM auth_challenges WHERE domain_uuid=? AND kind='totp-login' AND token_hash=? AND consumed_at_ms=0`, domainUUID, hash).Scan(&challengeUUID, &principalUUID, &expires, &attempts)
|
||||
err := s.DB.QueryRow(`SELECT uuid,principal_uuid,expires_at_ms,attempt_count,payload_json FROM auth_challenges WHERE domain_uuid=? AND kind='totp-login' AND token_hash=? AND consumed_at_ms=0`, domainUUID, hash).Scan(&challengeUUID, &principalUUID, &expires, &attempts, &payload)
|
||||
if err != nil || expires < time.Now().UnixMilli() || attempts >= 5 {
|
||||
return "", ErrAccessDenied
|
||||
return "", false, ErrAccessDenied
|
||||
}
|
||||
var options struct {
|
||||
Remember bool `json:"remember"`
|
||||
}
|
||||
if json.Unmarshal([]byte(payload), &options) != nil {
|
||||
return "", false, ErrAccessDenied
|
||||
}
|
||||
if err = s.VerifyTOTP(principalUUID, code); err != nil {
|
||||
_, _ = s.DB.Exec(`UPDATE auth_challenges SET attempt_count=attempt_count+1,consumed_at_ms=CASE WHEN attempt_count+1>=5 THEN ? ELSE consumed_at_ms END WHERE uuid=? AND consumed_at_ms=0`, time.Now().UnixMilli(), challengeUUID)
|
||||
return "", err
|
||||
return "", false, err
|
||||
}
|
||||
result, err := s.DB.Exec(`UPDATE auth_challenges SET consumed_at_ms=? WHERE uuid=? AND consumed_at_ms=0`, time.Now().UnixMilli(), challengeUUID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", false, err
|
||||
}
|
||||
changed, _ := result.RowsAffected()
|
||||
if changed != 1 {
|
||||
return "", ErrAccessDenied
|
||||
return "", false, ErrAccessDenied
|
||||
}
|
||||
return principalUUID, nil
|
||||
return principalUUID, options.Remember, nil
|
||||
}
|
||||
@@ -81,7 +81,11 @@ func minInt64(a, b int64) int64 {
|
||||
}
|
||||
|
||||
func (s *Store) GetRevisionMetadata(revisionUUID string) (*Revision, error) {
|
||||
row := s.DB.QueryRow(`SELECT uuid,object_uuid,COALESCE(document_hash,''),COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),'',COALESCE(message,''),COALESCE(created_at,0),COALESCE(created_at_ms,COALESCE(created_at,0)*1000) FROM revisions WHERE uuid=?`, revisionUUID)
|
||||
return s.GetRevisionMetadataContext(context.Background(), revisionUUID)
|
||||
}
|
||||
|
||||
func (s *Store) GetRevisionMetadataContext(ctx context.Context, revisionUUID string) (*Revision, error) {
|
||||
row := s.DB.QueryRowContext(ctx, `SELECT uuid,object_uuid,COALESCE(document_hash,''),COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),'',COALESCE(message,''),COALESCE(created_at,0),COALESCE(created_at_ms,COALESCE(created_at,0)*1000) FROM revisions WHERE uuid=?`, revisionUUID)
|
||||
return scanRevision(row)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
@@ -69,6 +70,10 @@ func (s *Store) ResolvePathInDomain(
|
||||
domainUUID string,
|
||||
path string,
|
||||
) (string, error) {
|
||||
return s.ResolvePathInDomainContext(context.Background(), domainUUID, path)
|
||||
}
|
||||
|
||||
func (s *Store) ResolvePathInDomainContext(ctx context.Context, domainUUID, path string) (string, error) {
|
||||
path = normalizePath(path)
|
||||
if err := s.ensureLocalDomain(domainUUID); err != nil {
|
||||
return "", err
|
||||
@@ -76,7 +81,7 @@ func (s *Store) ResolvePathInDomain(
|
||||
|
||||
var objectUUID string
|
||||
|
||||
err := s.DB.QueryRow(`
|
||||
err := s.DB.QueryRowContext(ctx, `
|
||||
SELECT object_uuid
|
||||
FROM paths
|
||||
WHERE domain_uuid = ?
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
@@ -324,6 +325,10 @@ func (s *Store) GetRevision(
|
||||
}
|
||||
|
||||
func (s *Store) GetLatestRevisionMetadataForLanguages(objectUUID string, rawLanguages []string) (*Revision, error) {
|
||||
return s.GetLatestRevisionMetadataForLanguagesContext(context.Background(), objectUUID, rawLanguages)
|
||||
}
|
||||
|
||||
func (s *Store) GetLatestRevisionMetadataForLanguagesContext(ctx context.Context, objectUUID string, rawLanguages []string) (*Revision, error) {
|
||||
candidates := make([]string, 0, len(rawLanguages)+1)
|
||||
seen := map[string]bool{}
|
||||
for _, rawLanguage := range rawLanguages {
|
||||
@@ -336,7 +341,7 @@ func (s *Store) GetLatestRevisionMetadataForLanguages(objectUUID string, rawLang
|
||||
candidates = append(candidates, "und")
|
||||
}
|
||||
for _, lang := range candidates {
|
||||
row := s.DB.QueryRow(`SELECT uuid,object_uuid,COALESCE(document_hash,''),COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),'',COALESCE(message,''),COALESCE(created_at,0),COALESCE(created_at_ms,COALESCE(created_at,0)*1000) FROM revisions WHERE object_uuid=? AND COALESCE(NULLIF(lang,''),'und')=? ORDER BY COALESCE(created_at_ms,created_at*1000) DESC,rowid DESC LIMIT 1`, objectUUID, lang)
|
||||
row := s.DB.QueryRowContext(ctx, `SELECT uuid,object_uuid,COALESCE(document_hash,''),COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),'',COALESCE(message,''),COALESCE(created_at,0),COALESCE(created_at_ms,COALESCE(created_at,0)*1000) FROM revisions WHERE object_uuid=? AND COALESCE(NULLIF(lang,''),'und')=? ORDER BY COALESCE(created_at_ms,created_at*1000) DESC,rowid DESC LIMIT 1`, objectUUID, lang)
|
||||
revision, err := scanRevision(row)
|
||||
if err == nil {
|
||||
return revision, nil
|
||||
|
||||
Loaded 100 of 158 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user