10 Commits
Author SHA1 Message Date
Anya Tokugawa 02fb77f72b feat(slides): add sandboxed Reveal.js viewer and editor preview
Build and publish container images / images (push) Successful in 9m2s
Release container images / release (push) Successful in 21s
2026-11-08 22:10:52 +09:00
Anya Tokugawa 09afb438c9 feat(editor): support atomic multi-cell CSV paste 2026-11-08 21:48:32 +09:00
Anya Tokugawa 2d6ceac0d7 feat(editor): add lossless bounded CSV table editing 2026-11-08 20:58:19 +09:00
Anya Tokugawa bd80ff6a0c docs: record v0.15.0 production deployment [skip ci] 2026-11-08 20:42:17 +09:00
Anya Tokugawa b90aef79d0 feat: add browser upload queue and trusted sessions with bounded projections
Build and publish container images / images (push) Successful in 11m37s
Release container images / release (push) Successful in 22s
2026-11-08 20:27:04 +09:00
Anya Tokugawa 84d52390f9 docs: record v0.14.1 production deployment [skip ci] 2026-11-08 19:43:43 +09:00
Anya Tokugawa 4049acf76e fix(tasks): recover deleted captures without reviving tombstones
Build and publish container images / images (push) Successful in 12m0s
Release container images / release (push) Successful in 19s
2026-11-08 19:26:50 +09:00
Anya Tokugawa 43a2d8c5a1 docs: record v0.14.0 production deployment [skip ci] 2026-11-08 18:21:06 +09:00
Anya Tokugawa 38a4fcf530 feat(tasks): add explicit deletion with DAV tombstones
Build and publish container images / images (push) Successful in 11m42s
Release container images / release (push) Successful in 27s
2026-11-08 18:04:54 +09:00
Anya Tokugawa dc978231e2 docs: record v0.13.0 production deployment [skip ci] 2026-11-08 16:32:53 +09:00
142 changed files with 4426 additions and 277 deletions

No files matched your search

+16 -4
View File
@@ -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
+6
View File
@@ -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());
+5
View File
@@ -66,10 +66,15 @@ func main() {
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
View File
@@ -14,12 +14,12 @@ services:
build:
context: .
dockerfile: Dockerfile.gecko-relay
image: pageswiki-gecko-relay:dev
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 Gecko dist directory}:/gecko:ro
- ${PAGESWIKI_GECKO_ASSETS_DIR:?Set verified complete Gecko bundle directory}:/gecko:ro
networks:
gecko-front: {}
gecko-egress: {}
+3 -1
View File
@@ -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 詳細設計・採用ライブラリ・同時変換ルールを確定した後に
+16 -2
View File
@@ -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を明示します。
+4 -2
View File
@@ -396,11 +396,13 @@ Wiki単独は親Path配下の `rss-{request UUID}` に新規作成します。
- [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・コピー・find・証明書エラー・HTTPS互換性、配布license/notice整備。
- [ ] 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、本番配備。
- [ ] RSS-8d2:初回/再表示・低メモリ端末の性能評価、実行中の切断・複数タブのUX、本番配備。起動上限と起動失敗時のiframe破棄・原文リンクへの退避は実装済み。
一覧には配信日と配信時刻(HH:mm)を分けて表示します。Domainの設定タイムゾーンを使い、tooltipには年・秒・タイムゾーンを含めます。配信日時不明は「—」とし、取得日時で補いません。モバイルでも時刻欄を残します。
隔離試験はRSS/Atom・FreshRSS login/read、欠落ID・巨大/不正feed、条件付きGET、失敗時cache保持、
本人分離・失効・readonly、二重送信・版競合・旧worker拒否、migration再実行/失敗rollback、
+4 -4
View File
@@ -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へ向ける切戻しは禁止。
## 実装と分けて管理する受入
+2 -1
View File
@@ -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を、各々の安全境界を維持したまま段階的に接続する。
## 検証と反映
+8
View File
@@ -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に適応します。
+6
View File
@@ -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契約、再認証、既存セッションへの即時適用を別途設計する。
+8
View File
@@ -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
+34 -1
View File
@@ -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トランザクションです。
+30 -6
View File
@@ -1,8 +1,9 @@
# Gecko連携の再配布条件
PagesWiki v0.13.0は、自作の連携コードと中継サービスのソースを配布し、Geckoエンジンは同梱しません。
実験機能`viewer.gecko`は既定無効のままです。既存3イメージのリリースにエンジンを追加せず、
専用relayも上流エンジンを含まないDockerfileとして提供します。
PagesWiki v0.13.0ではGeckoエンジンの配布を保留しました。
現在は固定版のエンジン、対応ソース、第三者NOTICE、日本語フォントを含む配布bundleを生成できます。
実験機能`viewer.gecko`は既定無効のままです。relayイメージとbundleは別物で、
起動時にbundle全体を検証してから資産を配信します。
本書は今回追加した部品の配布判断と残件を整理するもので、プロジェクト全体の法務監査ではありません。
## 部品と適用条件
@@ -17,6 +18,8 @@ PagesWiki v0.13.0は、自作の連携コードと中継サービスのソース
| 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は
@@ -62,9 +65,28 @@ MPLはファイル単位の義務であり、別実装のWiki全体をMPLへ変
4. 提供するsourceとnoticeの可用性・保全、配布物とのhash対応を検査する。
5. Mozillaの商標はコードlicenseとは別に扱い、Firefoxの公式配布であるとの表現やロゴの流用をしない。
現時点では2・3・4の配布用bundleが未完成です。今回のrelease artifactにエンジンは載せず、
本番では中継用鍵・資産mount・`viewer.gecko`の有効化を追加しません。
エンジン非同梱の連携コードと、通常のRSSフォルダショートカットはリリース対象です。
### 配布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を上書きしません。
## 一次資料
@@ -75,3 +97,5 @@ MPLはファイル単位の義務であり、別実装のWiki全体をMPLへ変
- [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)
+34 -8
View File
@@ -28,7 +28,8 @@ WebSocketではOriginも検査し、grantは一回限りです。既存接続の
bac28056a00ef6e5fb4345117e73d3629e75aca00dac71389fabbce39c018a73
```
展開後の`gecko.js/dist/`をread-onlyで`/gecko`へmountします。起動時に次の両ファイルのhashを確認し、
エンジン単体の`dist/`ではなく、後述するsource/notice付きbundleをread-onlyで`/gecko`へmountします。
起動時に次の両ファイルに加え、manifestに列挙された全ソース・NOTICE・フォントをhash検査し、
欠損・改変・異なる版の混在があれば中継は起動しません。
| ファイル | SHA-256 |
@@ -37,13 +38,27 @@ bac28056a00ef6e5fb4345117e73d3629e75aca00dac71389fabbce39c018a73
| gecko.wasm.zst | ebd6c75179152624d9644865e11792ed25cadc714d9e0985f412baf9c637a086 |
資産URLにも`assets/v0.0.1/`を含め、版をまたいだJS/WASMのcache混在を避けます。
初回にはJSと圧縮WASMの合計38,175,359 bytes(約36.4MiB)の転送とWASMの展開・compileが必要です。
初回には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の本番配備ではエンジンを配信せず、機能の有効化も行いません。
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の提供を含めて不変の単位で保全します。
## 配置
@@ -55,7 +70,8 @@ v0.13.0の本番配備ではエンジンを配信せず、機能の有効化も
| 変数 | 内容 |
| --- | --- |
| PAGESWIKI_GECKO_KEY_PATH | 32文字以上の十分ランダムな共有鍵のファイル絶対Path。appとrelayへ同じread-only mount |
| PAGESWIKI_GECKO_ASSETS_DIR | hash確認した`gecko.js/dist`の絶対Path |
| 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` |
@@ -100,7 +116,8 @@ UDP、80/443以外のTCP、単一ラベルのホスト名は拒否します。
| WebSocket受信idle | 90秒 |
| 宛先接続 | 名前解決込み8秒、個別dial 2秒 |
| relayコンテナ | 256MiB、0.5 CPU、64 PIDs、read-only、capabilitiesなし |
| 閲覧プロファイル | volatileな32MiB・2,048 entries、端末のOPFSへ永続化しない |
| 閲覧プロファイル | 日本語フォントを含むvolatileな32MiB・2,048 entries、端末のOPFSへ永続化しない |
| source/noticeダウンロード | 全体2接続まで。ETag・Range対応。閲覧streamの枠とは分離 |
relayの稼働状態・接続数・送受信bytes・拒否数は、コンテナ内の次の操作でJSON取得できます。
鍵はファイルから読み、標準出力には含めません。counterは再起動でリセットします。
@@ -134,7 +151,10 @@ extension viewer.gecko off
```sh
go test -race ./internal/geckorelay ./internal/server -run 'TestGrant|TestDestinations|TestRelay|TestAssets|TestFeedGeckoAuthorization|TestFeedGeckoWebsocket'
PAGESWIKI_BROWSER_TEST=1 PAGESWIKI_GECKO_TEST_ASSETS=/verified/gecko.js/dist go test ./internal/server -run '^TestFeedGeckoChromium$' -count=1
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
```
@@ -144,6 +164,12 @@ node internal/server/testdata/feed-gecko-profile.mjs
標準のhistory.back()が失敗するため、フォーム内容やスクロール位置を復元する履歴ではありません。
画面のcanvasは最大1920×1080、experimental WASM JITとGPUは無効です。
本番の標準機能に昇格する前に、HTTPSサイトと証明書エラーの表示、Safari/iPhone SE、IME、コピー、
find、実サイト互換性、複数タブ・起動失敗時のUX、低メモリ端末の測定、コンテナ外向きfirewallを検証します。
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拒否とは別の仕組みですが、すべてのサイトでの動作や軽さを保証するものではありません。
+3
View File
@@ -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、手動実行でビルド・公開する。
@@ -37,3 +37,56 @@ Safari、IME/copy/find、実HTTPSの互換性と証明書エラー、低メモ
本番の外向き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` |
+8
View File
@@ -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
+7
View File
@@ -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=
+1
View File
@@ -21,6 +21,7 @@ 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"},
+85
View File
@@ -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
}
+83
View File
@@ -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)
}
}
+45 -1
View File
@@ -9,6 +9,7 @@ import (
"io"
"net"
"net/http"
"os"
"path/filepath"
"strings"
"sync"
@@ -28,6 +29,8 @@ const (
type Relay struct {
Key, Assets string
Distribution map[string]DistributionFile
downloads chan struct{}
mu sync.Mutex
active map[string]bool
used map[string]int64
@@ -40,7 +43,7 @@ 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{}}
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()
@@ -72,6 +75,47 @@ func (r *Relay) ServeHTTP(w http.ResponseWriter, req *http.Request) {
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")
+6 -1
View File
@@ -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 }})
}
+1 -1
View File
@@ -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"
+3
View File
@@ -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",
+11
View File
@@ -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"))
+4
View File
@@ -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)
}
}
+4 -1
View File
@@ -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 -2
View File
@@ -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)
}
+19 -7
View File
@@ -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
+12 -11
View File
@@ -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
}
+4 -9
View File
@@ -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")
}
}
+12
View File
@@ -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
}
}
}
+88
View File
@@ -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")
}
}
+1 -1
View File
@@ -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)
}
+44 -43
View File
@@ -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)),
},
)
}
+150
View File
@@ -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)
}
})
}
}
+169
View File
@@ -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を表示できません(権限・形式・サイズ制限)。"
}
+111
View File
@@ -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, "&lt;script&gt;") || !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 -2
View File
@@ -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
+16 -2
View File
@@ -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)
}
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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 == "" {
+3 -2
View File
@@ -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
}
@@ -61,7 +62,7 @@ func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
linkMode = "tab"
}
}
s.renderWithContext(w, r, "feeds.gohtml", map[string]any{"Title": "RSS", "FeedWritable": active, "FeedWikiPrefix": prefix, "FeedLinkMode": linkMode, "FeedShareX": s.systemExtensionEnabled(domain, "sharing.x")})
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)
+9 -5
View File
@@ -48,7 +48,10 @@ func geckoIsolation(w http.ResponseWriter) {
}
func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domain, actor string, active bool) {
if !active || !s.geckoAvailable(domain) {
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
}
@@ -56,7 +59,6 @@ func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domai
http.Error(w, "invalid request", 400)
return
}
path := strings.TrimPrefix(r.URL.Path, geckoAPI)
switch path {
case "":
geckoIsolation(w)
@@ -73,8 +75,10 @@ func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domai
return
}
default:
http.NotFound(w, r)
return
if !distribution {
http.NotFound(w, r)
return
}
}
cfg := s.geckoConfig()
ctx, cancel := context.WithCancel(r.Context())
@@ -129,7 +133,7 @@ func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domai
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=1"></script></body></html>`
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)"
+53 -4
View File
@@ -23,17 +23,44 @@ import (
// 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/") {
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
}
@@ -67,7 +94,7 @@ func TestFeedGeckoChromium(t *testing.T) {
if !strings.Contains(requests[id], "\r\n\r\n") {
continue
}
body := `<!doctype html><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>Private fixture</h1>`
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>`
}
@@ -96,11 +123,26 @@ func TestFeedGeckoChromium(t *testing.T) {
if e != nil {
t.Fatal(e)
}
if e = s.store.CompleteFeed(context.Background(), claim, []store.FeedItem{{ID: "synthetic", Title: "Gecko synthetic fixture", URL: "http://fixture.invalid/first", Body: "No external network access."}}, "", "", "", false); e != nil {
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")
}
@@ -111,7 +153,14 @@ func TestFeedGeckoChromium(t *testing.T) {
defer web.Close()
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second)
defer cancel()
out, e := exec.CommandContext(ctx, "node", "internal/server/testdata/feed-gecko-browser.mjs", web.URL+"/v/feeds", t.TempDir(), "/tmp/pageswiki-feed-gecko.png").CombinedOutput()
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)
}
+16 -1
View File
@@ -57,7 +57,7 @@ func TestFeedGeckoAuthorizationAndHeaders(t *testing.T) {
t.Error("credential/header leaked", h)
}
}
if r.URL.Path != "/assets/v0.0.1/gecko.js" {
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")
@@ -133,6 +133,18 @@ func TestFeedGeckoAuthorizationAndHeaders(t *testing.T) {
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)
}
@@ -142,6 +154,9 @@ func TestFeedGeckoAuthorizationAndHeaders(t *testing.T) {
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) {
+3
View File
@@ -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)
+15 -2
View File
@@ -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]
+1 -1
View File
@@ -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
+1
View File
@@ -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
+3
View File
@@ -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)
+44 -9
View File
@@ -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,
+1
View File
@@ -257,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,
+68
View File
@@ -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})
}
+12
View File
@@ -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
}
}
}
+143
View File
@@ -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(), "&lt;h1&gt;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(), "&lt;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)
}
})
}
}
}
+3 -2
View File
@@ -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)
}
}
+272
View File
@@ -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)
}
}
+32 -16
View File
@@ -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) {
@@ -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
+31 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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)});
+3
View File
@@ -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)}
})();
+30 -4
View File
@@ -1,7 +1,7 @@
import {spawn} from 'node:child_process';
import {writeFile} from 'node:fs/promises';
import {setTimeout as delay} from 'node:timers/promises';
const [url,profile,screenshot]=process.argv.slice(2);
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=[];
@@ -17,24 +17,50 @@ try {
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(){this.opts.printErr=console.warn;this.opts.print=console.log;return init.call(this);};});`});
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.querySelector('.feed-external button').click()`);
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, Wisp article render, click navigation, viewer-local back and teardown passed');
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);}
+15 -2
View File
@@ -9,6 +9,7 @@
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');}
@@ -62,6 +63,7 @@
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'));
@@ -71,14 +73,25 @@
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');
catalogFind.value='Other';catalogFind.dispatchEvent(new w.Event('input',{bubbles:true}));assert(!activeFolder(),'Catalog filter setup');
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');
tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false');
// 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);
+2
View File
@@ -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');
+33
View File
@@ -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
View File
@@ -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
View File
@@ -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'));
+21 -2
View File
@@ -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)
}
+46
View File
@@ -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()
+5 -1
View File
@@ -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
}
+18 -6
View File
@@ -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
+58
View File
@@ -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)
+34
View File
@@ -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
}
+23 -8
View File
@@ -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
}
+5 -1
View File
@@ -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)
}
+6 -1
View File
@@ -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 = ?
+6 -1
View File
@@ -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
+54
View File
@@ -0,0 +1,54 @@
package store
import (
"context"
"database/sql"
"errors"
"github.com/google/uuid"
)
// A receipt without a live task or a deletion marker needs repair, not an
// implicit create that could silently revive an inconsistent record.
var ErrTaskCaptureMissing = errors.New("captured task is missing without a deletion record")
func TaskRecreationID(request string) string {
return uuid.NewSHA1(uuid.NameSpaceURL, []byte("pages:task-recreate:"+request)).String()
}
func deletedCapture(ctx context.Context, q interface {
QueryRowContext(context.Context, string, ...any) *sql.Row
}, domain, actor, request string) error {
var id string
if err := q.QueryRowContext(ctx, `SELECT item_uuid FROM organizer_capture_receipts WHERE domain_uuid=? AND owner_uuid=? AND request_uuid=?`, domain, actor, request).Scan(&id); err != nil {
return err
}
var live, deleted bool
if err := q.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_items WHERE domain_uuid=? AND uuid=?), EXISTS(SELECT 1 FROM organizer_task_deletions WHERE domain_uuid=? AND owner_uuid=? AND item_uuid=?)`, domain, id, domain, actor, id).Scan(&live, &deleted); err != nil {
return err
}
if live {
return ErrTaskConflict
}
if !deleted {
return ErrTaskCaptureMissing
}
return nil
}
// RecreateCapturedTask never removes old receipts, tombstones or DAV identity
// reservations. A deterministic successor ID makes a lost response retry safe.
// The caller authorizes read/create/write for target, including retained pages.
func (s *Store) RecreateCapturedTask(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body, replaces string) (TaskRecord, error) {
id, err := uuid.Parse(replaces)
if err != nil || id.String() != replaces || request != TaskRecreationID(replaces) {
return TaskRecord{}, ErrTaskInvalid
}
if err = taskActor(ctx, s.DB, domain, actor, true); err != nil {
return TaskRecord{}, err
}
if err = deletedCapture(ctx, s.DB, domain, actor, replaces); err != nil {
return TaskRecord{}, err
}
return s.captureTaskWithWiki(ctx, domain, actor, request, hash, item, target, body, replaces)
}
+5 -1
View File
@@ -77,8 +77,12 @@ func ValidTaskMailSuffix(s string) bool {
return mailListSuffix.MatchString(s) || (mailMonthSuffix.MatchString(s) && !strings.HasPrefix(s, "0000/"))
}
func validCapturedTaskWiki(target, body string) bool {
return target != "" && ValidTaskWikiPrefix(path.Dir(target)) && path.Clean(target) == target && len(body) <= 256<<10 && utf8.ValidString(body) && strings.IndexByte(body, 0) < 0
}
func (s *Store) createCapturedTaskWiki(ctx context.Context, tx *sql.Tx, domain, actor string, item *TaskRecord, target, body string) error {
if target == "" || !ValidTaskWikiPrefix(path.Dir(target)) || path.Clean(target) != target || item.PageUUID != "" || len(body) > 256<<10 || !utf8.ValidString(body) || strings.IndexByte(body, 0) >= 0 {
if !validCapturedTaskWiki(target, body) || item.PageUUID != "" {
return ErrTaskInvalid
}
var exists bool
+3
View File
@@ -54,6 +54,9 @@ func (s *Store) ensureTaskDAVSchema() error {
`DELETE FROM organizer_dav_collections`,
`INSERT INTO organizer_dav_collections(domain_uuid,path,owner_uuid,project_uuid) SELECT domain_uuid,COALESCE(NULLIF(json_extract(data,'$.dav_collection'),''),'tasks/projects/'||uuid),owner_uuid,uuid FROM organizer_items WHERE kind='project'`,
`INSERT INTO organizer_dav_resources(domain_uuid,owner_uuid,item_uuid,name,uid) SELECT domain_uuid,owner_uuid,uuid,CASE WHEN project_uuid='' THEN '' ELSE char(0)||project_uuid||char(0) END||COALESCE(json_extract(data,'$.caldav.name'),uuid||'.ics'),CASE WHEN project_uuid='' THEN '' ELSE char(0)||project_uuid||char(0) END||COALESCE(json_extract(data,'$.caldav.uid'),uuid) FROM organizer_items WHERE kind='task'`,
// Deleted identities remain reserved after an index rebuild. A stale
// client PUT must not silently resurrect a deliberately removed task.
`INSERT INTO organizer_dav_resources(domain_uuid,owner_uuid,item_uuid,name,uid) SELECT domain_uuid,owner_uuid,item_uuid,dav_name,dav_uid FROM organizer_task_deletions`,
} {
if _, err = tx.Exec(q); err != nil {
return err
+117
View File
@@ -0,0 +1,117 @@
package store
import (
"context"
"database/sql"
"encoding/json"
"errors"
"time"
"github.com/google/uuid"
)
var ErrTaskDeleted = errors.New("task has been deleted")
var ErrTaskHasChildren = errors.New("move or delete subtasks first")
var ErrTaskWorking = errors.New("stop task work and focus sessions first")
// DeleteTask is deliberately separate from reversible archiving. The head and
// revision references are removed; minimal identity tombstones prevent offline
// clients from resurrecting the same task. Wiki documents, calendar events and
// completed work records are independent resources and are not deleted here.
// CAS blobs/backups are not securely erased by this operation.
func (s *Store) DeleteTask(ctx context.Context, domain, actor, id string, expected int64) error {
if s.ReadOnly {
return ErrReadOnly
}
u, err := uuid.Parse(id)
if err != nil || u.String() != id || expected < 1 {
return ErrTaskInvalid
}
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
tx, err := s.DB.BeginTx(ctx, nil)
if err != nil {
return err
}
defer tx.Rollback()
if _, err = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=? AND principal_uuid=?`, domain, actor); err != nil {
return err
}
if err = taskActor(ctx, tx, domain, actor, true); err != nil {
return err
}
enabled, err := taskReminderExtensionEnabled(ctx, tx, domain)
if err != nil {
return err
}
if !enabled {
return ErrAccessDenied
}
var raw string
err = tx.QueryRowContext(ctx, `SELECT data FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=?`, domain, actor, id).Scan(&raw)
if errors.Is(err, sql.ErrNoRows) {
// A lost successful DELETE response can be retried with its original
// precondition, without disclosing another owner's tombstone.
var version int64
if e := tx.QueryRowContext(ctx, `SELECT version FROM organizer_task_deletions WHERE domain_uuid=? AND owner_uuid=? AND item_uuid=?`, domain, actor, id).Scan(&version); e != nil {
return e
}
if version-1 != expected {
return ErrTaskConflict
}
return nil
}
if err != nil {
return err
}
var item TaskRecord
if err = json.Unmarshal([]byte(raw), &item); err != nil {
return err
}
if item.Kind != "task" {
return ErrTaskInvalid
}
if item.Version != expected {
return ErrTaskConflict
}
var children, working bool
if err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND parent_uuid=?)`, domain, actor, id).Scan(&children); err != nil {
return err
}
if children {
return ErrTaskHasChildren
}
if err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_focus WHERE domain_uuid=? AND owner_uuid=? AND task_uuid=? AND state IN ('running','paused')) OR EXISTS(SELECT 1 FROM organizer_work_sessions WHERE domain_uuid=? AND owner_uuid=? AND task_uuid=? AND end_ms=0 AND cancelled_ms=0)`, domain, actor, id, domain, actor, id).Scan(&working); err != nil {
return err
}
if working {
return ErrTaskWorking
}
name, uid := id+".ics", id
if item.CalDAV != nil {
name, uid = item.CalDAV.Name, item.CalDAV.UID
}
now := time.Now().UnixMilli()
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_task_deletions(domain_uuid,owner_uuid,item_uuid,dav_name,dav_uid,version,deleted_at_ms) VALUES(?,?,?,?,?,?,?)`, domain, actor, id, taskDAVIndexKey(item.ProjectUUID, name), taskDAVIndexKey(item.ProjectUUID, uid), item.Version+1, now)
if err != nil {
return err
}
for _, q := range []string{
`DELETE FROM organizer_reminders WHERE domain_uuid=? AND item_uuid=?`,
`DELETE FROM organizer_task_metrics WHERE domain_uuid=? AND task_uuid=?`,
`UPDATE organizer_time_blocks SET state='unlinked' WHERE domain_uuid=? AND task_uuid=?`,
`DELETE FROM organizer_revisions WHERE domain_uuid=? AND item_uuid=?`,
`DELETE FROM organizer_items WHERE domain_uuid=? AND uuid=?`,
} {
if _, err = tx.ExecContext(ctx, q, domain, id); err != nil {
return err
}
}
if _, err = tx.ExecContext(ctx, `INSERT INTO organizer_changes(domain_uuid,item_uuid,version,actor_uuid,created_at_ms) VALUES(?,?,?,?,?)`, domain, id, item.Version+1, actor, now); err != nil {
return err
}
if _, err = s.appendTaskActivityTx(tx, domain, actor, id, "task", item.Version+1, now); err != nil {
return err
}
return tx.Commit()
}
+39 -3
View File
@@ -227,10 +227,22 @@ func (s *Store) CapturedTask(ctx context.Context, domain, actor, request, hash s
if err != nil {
return TaskRecord{}, err
}
// Check lifecycle before payload equality. A retained receipt must not
// disguise a deleted task as an editable version conflict.
item, err := s.GetTask(ctx, domain, actor, id)
if errors.Is(err, sql.ErrNoRows) {
if err = deletedCapture(ctx, s.DB, domain, actor, request); err != nil {
return TaskRecord{}, err
}
return TaskRecord{}, ErrTaskDeleted
}
if err != nil {
return TaskRecord{}, err
}
if stored != hash {
return TaskRecord{}, ErrTaskConflict
}
return s.GetTask(ctx, domain, actor, id)
return item, nil
}
func (s *Store) CaptureTask(ctx context.Context, domain, actor, request, hash string, item TaskRecord) (TaskRecord, error) {
@@ -240,6 +252,10 @@ func (s *Store) CaptureTask(ctx context.Context, domain, actor, request, hash st
// CaptureTaskWithWiki commits the task, receipt and optional Wiki page together.
// The HTTP caller must authorize read/create/write for the exact target path.
func (s *Store) CaptureTaskWithWiki(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body string) (TaskRecord, error) {
return s.captureTaskWithWiki(ctx, domain, actor, request, hash, item, target, body, "")
}
func (s *Store) captureTaskWithWiki(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body, replaces string) (TaskRecord, error) {
if _, err := uuid.Parse(request); err != nil {
return TaskRecord{}, ErrTaskInvalid
}
@@ -252,11 +268,31 @@ func (s *Store) CaptureTaskWithWiki(ctx context.Context, domain, actor, request,
}
item.UUID = request
out, err := s.saveTask(ctx, domain, actor, item, 0, func(tx *sql.Tx, current *TaskRecord, _ TaskRecord) error {
if target != "" {
if e := s.createCapturedTaskWiki(ctx, tx, domain, actor, current, target, body); e != nil {
if replaces != "" {
if e := deletedCapture(ctx, tx, domain, actor, replaces); e != nil {
return e
}
}
if target != "" {
if !validCapturedTaskWiki(target, body) || current.PageUUID != "" {
return ErrTaskInvalid
}
// Explicit recreation may reuse a surviving Wiki page. Its content
// and revisions are independent of task deletion and never replaced.
reused := false
if replaces != "" {
e := tx.QueryRowContext(ctx, `SELECT p.object_uuid FROM paths p JOIN objects o ON o.uuid=p.object_uuid WHERE p.domain_uuid=? AND p.path=? AND o.kind='page'`, domain, target).Scan(&current.PageUUID)
if e != nil && !errors.Is(e, sql.ErrNoRows) {
return e
}
reused = e == nil
}
if !reused {
if e := s.createCapturedTaskWiki(ctx, tx, domain, actor, current, target, body); e != nil {
return e
}
}
}
_, e := tx.ExecContext(ctx, `INSERT INTO organizer_capture_receipts VALUES(?,?,?,?,?)`, domain, actor, request, hash, item.UUID)
return e
})
+15
View File
@@ -81,6 +81,10 @@ func (s *Store) EnsureTasksSchema() error {
UNIQUE(domain_uuid,item_uuid,version))`,
`CREATE TABLE IF NOT EXISTS organizer_activity_bridge(id INTEGER PRIMARY KEY CHECK(id=1),last_sequence INTEGER NOT NULL DEFAULT 0)`,
`INSERT OR IGNORE INTO organizer_activity_bridge(id,last_sequence) VALUES(1,0)`,
`CREATE TABLE IF NOT EXISTS organizer_task_deletions (
domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,item_uuid TEXT NOT NULL,
dav_name TEXT NOT NULL,dav_uid TEXT NOT NULL,version INTEGER NOT NULL,deleted_at_ms INTEGER NOT NULL,
PRIMARY KEY(domain_uuid,item_uuid))`,
} {
if _, err := s.DB.Exec(q); err != nil {
return err
@@ -227,6 +231,17 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
if enabled, exists := states["organizer.tasks"]; exists && !enabled {
return TaskRecord{}, ErrAccessDenied
}
var deletedOwner string
err = tx.QueryRowContext(ctx, `SELECT owner_uuid FROM organizer_task_deletions WHERE domain_uuid=? AND item_uuid=?`, domain, item.UUID).Scan(&deletedOwner)
if err == nil {
if deletedOwner != actor {
return TaskRecord{}, sql.ErrNoRows
}
return TaskRecord{}, ErrTaskDeleted
}
if !errors.Is(err, sql.ErrNoRows) {
return TaskRecord{}, err
}
if item.NotifyDue || item.NotifyPlanned {
item.ReminderTimezone = "UTC"
err = tx.QueryRowContext(ctx, `SELECT value FROM config WHERE domain_uuid=? AND key='timezone'`, domain).Scan(&item.ReminderTimezone)
+1 -1
View File
@@ -44,7 +44,7 @@ func (s *Store) PublishTaskActivity(ctx context.Context, limit int) (int, int, e
if _, err = tx.ExecContext(ctx, `UPDATE organizer_activity_bridge SET last_sequence=last_sequence WHERE id=1`); err != nil {
return 0, 0, err
}
rows, err := tx.QueryContext(ctx, `SELECT c.sequence,c.domain_uuid,c.item_uuid,c.version,c.actor_uuid,c.created_at_ms,COALESCE(i.kind,'') FROM organizer_changes c LEFT JOIN organizer_items i ON i.domain_uuid=c.domain_uuid AND i.uuid=c.item_uuid WHERE c.sequence>(SELECT last_sequence FROM organizer_activity_bridge WHERE id=1) ORDER BY c.sequence LIMIT ?`, limit)
rows, err := tx.QueryContext(ctx, `SELECT c.sequence,c.domain_uuid,c.item_uuid,c.version,c.actor_uuid,c.created_at_ms,COALESCE(i.kind,CASE WHEN d.item_uuid IS NOT NULL THEN 'task' ELSE '' END) FROM organizer_changes c LEFT JOIN organizer_items i ON i.domain_uuid=c.domain_uuid AND i.uuid=c.item_uuid LEFT JOIN organizer_task_deletions d ON d.domain_uuid=c.domain_uuid AND d.item_uuid=c.item_uuid WHERE c.sequence>(SELECT last_sequence FROM organizer_activity_bridge WHERE id=1) ORDER BY c.sequence LIMIT ?`, limit)
if err != nil {
return 0, 0, err
}
+38 -12
View File
@@ -32,7 +32,7 @@ import urllib.parse as url
import urllib.request as http
import webbrowser
VERSION = '0.4.0'
VERSION = '0.4.2'
class Failure(Exception):
def __init__(self, message, status=0, payload=None):
@@ -144,9 +144,11 @@ class Client:
except (ValueError, UnicodeError):
raise Failure('Invalid JSON response.') from None
def login(self, username, password, otp=getpass.getpass):
def login(self, username, password, otp=getpass.getpass, *, remember=False):
form={'username':username,'password':password}
if remember:form['remember']='1'
try:
result = self.json('/_/auth/login', method='POST', form={'username': username, 'password': password})
result = self.json('/_/auth/login', method='POST', form=form)
except Failure as e:
if e.status != 401 or not e.payload.get('mfa_required') or not e.payload.get('challenge_token'):
raise
@@ -164,12 +166,13 @@ class Client:
self.token = token
return time.time() + duration
def login_oidc(self, no_browser=False, expected_username='', *, sleep=time.sleep, clock=time.monotonic):
def login_oidc(self, no_browser=False, expected_username='', *, remember=False, sleep=time.sleep, clock=time.monotonic):
verifier = secrets.token_urlsafe(32)
challenge = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).decode().rstrip('=')
try:
started = self.json('/_/auth/cli/start', method='POST', form={
'code_challenge': challenge, 'code_challenge_method': 'S256'})
form={'code_challenge':challenge,'code_challenge_method':'S256'}
if remember:form['remember']='1'
started = self.json('/_/auth/cli/start', method='POST', form=form)
except Failure as e:
if e.status in (404, 405, 501):
raise Failure('CLI OIDC login is unavailable on this server. Check the configured server URL and deploy a server version supporting /_/auth/cli/start.', e.status) from None
@@ -569,7 +572,7 @@ def tasks(client, profile, words):
for name in ('done','reopen','archive','start'):
p=sub.add_parser(name);p.add_argument('uuid',type=task_uuid)
sub.add_parser('stop');sub.add_parser('status')
p=sub.add_parser('retry');p.add_argument('request_id',type=task_uuid)
p=sub.add_parser('retry');p.add_argument('request_id',type=task_uuid);p.add_argument('--recreate-deleted',action='store_true',help='Explicitly recreate a deleted capture with a new UUID; preserve and relink any existing Wiki page')
p=sub.add_parser('report');p.add_argument('--from',dest='start');p.add_argument('--to',dest='end')
p=sub.add_parser('preferences');p.add_argument('--wiki-prefix');p.add_argument('--project');p.add_argument('--assignee');p.add_argument('--due-days',type=int);p.add_argument('--start-days',type=int);p.add_argument('--planned-days',type=int);p.add_argument('--review-days',type=int);p.add_argument('--estimate',type=int);p.add_argument('--complexity',type=int);p.add_argument('--digest',choices=['on','off']);p.add_argument('--at');p.add_argument('--timezone')
for child in sub.choices.values():child.add_argument('--json',action='store_true')
@@ -578,10 +581,19 @@ def tasks(client, profile, words):
def capture(payload):
pending=profile.data.setdefault('task_outbox',{})
if len(pending)>=20 and payload['request_id'] not in pending:raise Failure('20 pending captures retained. Retry them before adding more.')
if payload['request_id'] in pending and pending[payload['request_id']] != payload:raise Failure('A different draft with this request ID is retained. Use pages task retry '+payload['request_id'])
replaced=payload['request_id'] in pending and pending[payload['request_id']] != payload
pending[payload['request_id']]=payload;profile.save()
if replaced:print('Replaced the retained draft with the current input.',file=sys.stderr)
try: result=client.json(TASK_API+'capture',method='POST',data=payload)
except Failure as e:
if e.status==410 and e.payload.get('error')=='deleted':
raise Failure('Draft retained. This task was deleted; normal retry will not restore it. To explicitly create a new task (preserving any existing Wiki body), use: pages task retry '+payload['request_id']+' --recreate-deleted',e.status,e.payload) from e
if e.status==409 and e.payload.get('error')=='capture_missing':
raise Failure('Draft retained. The server has a capture receipt but no task or deletion record. Server-side consistency repair is required; retry will not fix it.',e.status,e.payload) from e
if e.status==412:
raise Failure('Draft retained. This request ID conflicts with a server capture or task. An unchanged retry will not resolve it; inspect with: pages task show '+payload['request_id'],e.status,e.payload) from e
if e.status==409 and e.payload.get('error')=='note_exists':
raise Failure('Draft retained. A Wiki page already occupies the destination; it was not overwritten.',e.status,e.payload) from e
print('Draft retained; retry with: pages task retry '+payload['request_id'],file=sys.stderr)
if e.payload.get('error') == 'wiki_prefix_required': raise Failure('Set a private Wiki destination first: pages task preferences --wiki-prefix /YOUR/MAIL/PATH',e.status) from e
raise
@@ -606,6 +618,19 @@ def tasks(client, profile, words):
if action=='retry':
payload=profile.data.get('task_outbox',{}).get(a.request_id)
if not payload:raise Failure('No retained task capture with this request ID.')
if a.recreate_deleted:
pending=profile.data['task_outbox']
replacement=str(uuid.uuid5(uuid.NAMESPACE_URL,'pages:task-recreate:'+a.request_id))
payload=dict(payload,request_id=replacement,replaces_deleted=a.request_id)
if replacement in pending and pending[replacement]!=payload:
raise Failure('A different recreation draft already exists; inspect or retry it first: '+replacement)
previous=pending.copy()
pending[replacement]=payload;del pending[a.request_id]
try:profile.save()
except Exception:
profile.data['task_outbox']=previous
raise
print('Recreation draft saved. Existing Wiki content will be preserved. Retry ID: '+replacement,file=sys.stderr)
emit(capture(payload));return
if action in ('add','from-mail'):
payload={'request_id':getattr(a,'request_id',None) or str(uuid.uuid4()),'title':a.title,'notes':a.notes or ''}
@@ -622,7 +647,7 @@ def tasks(client, profile, words):
value=getattr(a,attr)
if value is not None:payload[key]=task_project(client,value) if attr=='project' else value
# A retry of the same pending mail must not drift across a month boundary
# when Date was missing. Other changed options still fail closed.
# when Date was missing. Changed input replaces the pending draft below.
old=profile.data.get('task_outbox',{}).get(payload['request_id'])
if action=='from-mail' and old and {k:v for k,v in old.items() if k!='wiki_suffix'}=={k:v for k,v in payload.items() if k!='wiki_suffix'}:
payload=old.copy()
@@ -834,6 +859,7 @@ def main(argv=None):
login = argparse.ArgumentParser(prog='pages login', description='Log into the configured connection. Password and TOTP are prompted privately.')
login.add_argument('--oidc', action='store_true', help='Authenticate and approve in a browser; no local password required')
login.add_argument('--no-browser', action='store_true', help='Print the browser login URL without opening it (requires --oidc)')
login.add_argument('--remember', action='store_true', help='Keep this trusted device signed in for up to 30 days, subject to server policy')
login_args = login.parse_args(args.args)
if login_args.no_browser and not login_args.oidc: login.error('--no-browser requires --oidc')
elif '--help' in args.args:
@@ -852,13 +878,13 @@ def main(argv=None):
print('WARNING: --insecure disables TLS certificate and hostname verification for this invocation. Credentials and data can be intercepted; this option is not saved.', file=sys.stderr)
if args.command == 'login':
if not login_args.oidc and not spec.get('username'): raise Failure('Set your account with pages configure --username NAME, or use pages login --oidc.')
if profile.data.get('token'): raise Failure('Log out this profile before replacing its session.')
if profile.data.get('token') and profile.data.get('expires',0)>time.time(): raise Failure('Log out this profile before replacing its active session.')
client = Client(spec['origin'], lang=lang, insecure=args.insecure)
if login_args.oidc:
expires, username = client.login_oidc(login_args.no_browser, spec.get('username', ''))
expires, username = client.login_oidc(login_args.no_browser, spec.get('username', ''), remember=login_args.remember)
else:
username = spec['username']
expires = client.login(username, getpass.getpass('Password: '))
expires = client.login(username, getpass.getpass('Password: '), remember=login_args.remember)
same_identity = profile.data.get('origin') == client.base and profile.data.get('username') == username
pending = profile.data.get('task_outbox', {})
if pending and not same_identity:
+148 -4
View File
@@ -9,6 +9,74 @@ import unittest
m=runpy.run_path(str(Path(__file__).with_name('pages')))
class ProductivityTests(unittest.TestCase):
def test_deleted_capture_message_retains_draft_without_retry_loop(self):
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
original={'request_id':ident,'title':'Private title','notes':'Private notes'}
for status,code,message in [(410,'deleted','--recreate-deleted'),(409,'capture_missing','consistency repair'),(412,'conflict','unchanged retry'),(409,'note_exists','not overwritten')]:
profile=SimpleNamespace(data={'task_outbox':{ident:original.copy()}},save=lambda:None)
calls=[]
def send(*args,**kw):
calls.append(kw)
raise m['Failure']('old generic message',status,{'error':code})
output=io.StringIO()
with contextlib.redirect_stderr(output),self.assertRaises(m['Failure']) as error:
m['tasks'](SimpleNamespace(json=send),profile,['retry',ident])
self.assertIn(message,str(error.exception))
self.assertNotIn('Private',str(error.exception)+output.getvalue())
self.assertNotIn('retry with:',output.getvalue())
self.assertEqual(profile.data['task_outbox'][ident],original)
self.assertEqual(len(calls),1)
def test_recreate_deleted_persists_successor_and_retries_same_id(self):
import uuid
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
replacement=str(uuid.uuid5(uuid.NAMESPACE_URL,'pages:task-recreate:'+ident))
payload={'request_id':ident,'title':'Private title','wiki_body':'Private body','wiki_suffix':'2030/01/'+ident}
saved,calls=[],[]
profile=SimpleNamespace(data={'task_outbox':{ident:payload.copy()}})
profile.save=lambda:saved.append(json.loads(json.dumps(profile.data)))
def send(route,**kw):
calls.append(kw['data'].copy())
self.assertEqual(saved[-1]['task_outbox'][replacement],kw['data'])
self.assertNotIn(ident,saved[-1]['task_outbox'])
if len(calls)==1:raise m['Failure']('Connection lost')
return {'item':{'uuid':replacement}}
output,error=io.StringIO(),io.StringIO()
with contextlib.redirect_stdout(output),contextlib.redirect_stderr(error):
with self.assertRaises(m['Failure']):m['tasks'](SimpleNamespace(json=send),profile,['retry',ident,'--recreate-deleted'])
self.assertEqual(len(profile.data['task_outbox']),1)
m['tasks'](SimpleNamespace(json=send),profile,['retry',replacement])
self.assertEqual(calls[0],calls[1])
self.assertEqual(calls[0]['request_id'],replacement)
self.assertEqual(calls[0]['replaces_deleted'],ident)
self.assertEqual(calls[0]['wiki_suffix'],payload['wiki_suffix'])
self.assertEqual(calls[0]['wiki_body'],payload['wiki_body'])
self.assertEqual(profile.data['task_outbox'],{})
self.assertIn(replacement,error.getvalue())
self.assertNotIn('Private',error.getvalue())
def test_recreate_deleted_save_failure_keeps_original_and_sends_nothing(self):
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
payload={'request_id':ident,'title':'Draft'}
def fail():raise m['Failure']('disk full')
profile=SimpleNamespace(data={'task_outbox':{ident:payload.copy()}},save=fail)
calls=[]
with self.assertRaises(m['Failure']):m['tasks'](SimpleNamespace(json=lambda *a,**kw:calls.append(kw)),profile,['retry',ident,'--recreate-deleted'])
self.assertEqual(calls,[])
self.assertEqual(profile.data['task_outbox'],{ident:payload})
def test_recreate_deleted_never_clobbers_different_successor_draft(self):
import uuid
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
replacement=str(uuid.uuid5(uuid.NAMESPACE_URL,'pages:task-recreate:'+ident))
pending={ident:{'request_id':ident,'title':'Original'},replacement:{'request_id':replacement,'title':'Different'}}
before=json.loads(json.dumps(pending))
calls=[]
profile=SimpleNamespace(data={'task_outbox':pending},save=lambda:calls.append('save'))
with self.assertRaises(m['Failure']):m['tasks'](SimpleNamespace(json=lambda *a,**kw:calls.append('send')),profile,['retry',ident,'--recreate-deleted'])
self.assertEqual(calls,[])
self.assertEqual(pending,before)
def test_mail_path_priority_and_dates(self):
import datetime,hashlib
ident='06cb3a24-61f8-4a9f-a0bf-89eea9632f25'
@@ -24,7 +92,7 @@ class ProductivityTests(unittest.TestCase):
raw=b'Subject: [../unsafe 123] Title\r\n'+date+b'\r\nbody'
self.assertEqual(suffix(raw,ident,now),'2030/02/'+hashlib.sha256(raw).hexdigest())
def test_pending_mail_month_and_options_are_preserved(self):
def test_pending_mail_keeps_month_but_replaces_changed_options(self):
from unittest.mock import patch
raw=b'Subject: Test\r\nMessage-ID: <same@example.invalid>\r\n\r\nbody'
calls=[]
@@ -37,10 +105,86 @@ class ProductivityTests(unittest.TestCase):
with patch.dict(m['tasks'].__globals__,task_mail_suffix=lambda raw,ident:month+'/'+ident),patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
m['tasks'](client,profile,['from-mail'])
self.assertEqual(calls[0],calls[1])
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),self.assertRaises(m['Failure']):
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
m['tasks'](client,profile,['from-mail','--wiki-prefix','/changed'])
self.assertEqual(len(calls),2)
self.assertEqual(next(iter(profile.data['task_outbox'].values())),calls[0])
self.assertEqual(len(calls),3)
self.assertEqual(calls[2]['request_id'],calls[0]['request_id'])
self.assertEqual(calls[2]['wiki_prefix'],'/changed')
self.assertEqual(next(iter(profile.data['task_outbox'].values())),calls[2])
def test_changed_capture_is_saved_before_send_and_retained_on_conflict(self):
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
saved,calls=[],[]
old={'request_id':ident,'title':'Old draft','notes':'Old private notes'}
profile=SimpleNamespace(data={'task_outbox':{ident:old}})
profile.save=lambda:saved.append(json.loads(json.dumps(profile.data)))
def send(route,**kw):
payload=kw['data'].copy();calls.append(payload)
self.assertEqual(saved[-1]['task_outbox'][ident],payload)
if len(calls)==1:raise m['Failure']('conflict',412,{'error':'conflict'})
return {'item':{'uuid':ident}}
client=SimpleNamespace(json=send)
out,err=io.StringIO(),io.StringIO()
with contextlib.redirect_stdout(out),contextlib.redirect_stderr(err):
with self.assertRaises(m['Failure']) as failure:
m['tasks'](client,profile,['add','New draft','--request-id',ident,'--notes','New private notes'])
self.assertEqual(failure.exception.status,412)
self.assertEqual(profile.data['task_outbox'][ident],calls[0])
self.assertEqual(len(calls),1) # No automatic server overwrite/retry.
m['tasks'](client,profile,['retry',ident])
self.assertEqual(calls[0],calls[1])
self.assertEqual(calls[0]['title'],'New draft')
self.assertEqual(profile.data['task_outbox'],{})
self.assertIn('Replaced the retained draft',err.getvalue())
self.assertNotIn('private notes',err.getvalue())
self.assertEqual(json.loads(out.getvalue())['item']['uuid'],ident)
def test_replacing_draft_does_not_send_when_local_save_fails(self):
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
def fail_save():raise m['Failure']('local write failed')
profile=SimpleNamespace(data={'task_outbox':{ident:{'request_id':ident,'title':'Old','notes':''}}},save=fail_save)
calls=[]
client=SimpleNamespace(json=lambda *a,**kw:calls.append(kw))
with self.assertRaises(m['Failure']):m['tasks'](client,profile,['add','New','--request-id',ident])
self.assertEqual(calls,[])
def test_full_outbox_allows_replacement_but_not_new_id(self):
import uuid
pending={str(uuid.uuid4()):{'title':'Old'} for _ in range(20)}
ident=next(iter(pending))
profile=SimpleNamespace(data={'task_outbox':pending},save=lambda:None)
calls=[]
def send(route,**kw):
calls.append(kw['data'].copy())
raise m['Failure']('offline')
client=SimpleNamespace(json=send)
with contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
m['tasks'](client,profile,['add','Replacement','--request-id',ident])
self.assertEqual(len(calls),1)
self.assertEqual(pending[ident]['title'],'Replacement')
with self.assertRaises(m['Failure']):m['tasks'](client,profile,['add','Another'])
self.assertEqual(len(calls),1)
self.assertEqual(len(pending),20)
def test_reimported_mail_replaces_body_and_removes_obsolete_options(self):
from unittest.mock import patch
raw=b'Subject: Old\r\nMessage-ID: <same@example.invalid>\r\n\r\nOLD BODY'
calls=[]
def send(route,**kw):
calls.append(kw['data'].copy())
raise m['Failure']('offline')
client=SimpleNamespace(base='https://example.invalid',json=send)
profile=SimpleNamespace(data={'username':'test'},save=lambda:None)
changed=raw.replace(b'Subject: Old',b'Subject: New').replace(b'OLD BODY',b'NEW BODY')
for mail,args in [(raw,['--wiki-prefix','/old']),(changed,['--wiki-prefix','/new']),(changed,['--metadata-only'])]:
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(mail))),contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
m['tasks'](client,profile,['from-mail',*args])
self.assertEqual(len({c['request_id'] for c in calls}),1)
self.assertEqual(calls[1]['title'],'New')
self.assertIn('NEW BODY',calls[1]['wiki_body'])
self.assertNotIn('OLD BODY',calls[1]['wiki_body'])
for key in ('wiki_body','wiki_prefix','wiki_suffix'):self.assertNotIn(key,calls[2])
self.assertEqual(next(iter(profile.data['task_outbox'].values())),calls[2])
def test_mail_privacy_and_long_subject_override(self):
raw=b'Subject: Test\r\nFrom: Person <person@example.invalid>\r\nMessage-ID: <id@example.invalid>\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nPRIVATE BODY'
+55
View File
@@ -0,0 +1,55 @@
import contextlib
import io
import os
from pathlib import Path
import runpy
import time
import tempfile
import unittest
from unittest.mock import patch
m = runpy.run_path(str(Path(__file__).with_name('pages')))
class RememberTests(unittest.TestCase):
def test_expired_login_retains_same_account_drafts_and_path(self):
with tempfile.TemporaryDirectory() as root, patch.dict(os.environ, {'XDG_CONFIG_HOME': root}), contextlib.redirect_stdout(io.StringIO()):
with m['Configuration']().locked() as config:
config.data = {'version': 1, 'default_profile': 'default', 'profiles': {'default': {'origin': 'https://wiki.example', 'username': 'anya', 'lang': 'auto'}}}
config.save()
with m['Profile']('default').locked() as profile:
profile.data = {'origin': 'https://wiki.example', 'username': 'anya', 'token': 'expired', 'expires': 1,
'cwd': '/projects/demo', 'task_outbox': {'request': {'title': 'synthetic draft'}}}
profile.save()
def login(client, username, password, *, remember=False):
self.assertTrue(remember)
client.token = 'pw_api_'+'x'*43
return time.time()+2592000
with patch.object(m['Client'], 'login', login), patch.object(m['getpass'], 'getpass', return_value='synthetic'):
m['main'](['login', '--remember'])
with m['Profile']('default').locked() as profile:
self.assertEqual(profile.data['cwd'], '/projects/demo')
self.assertEqual(profile.data['task_outbox']['request']['title'], 'synthetic draft')
self.assertTrue(profile.data['token'].startswith('pw_api_'))
def test_password_choice_is_explicit_and_bound_before_totp(self):
for remember in (False, True):
client = m['Client']('https://wiki.example')
challenge = m['Failure']('MFA', 401, {'mfa_required': True, 'challenge_token': 'challenge'})
result = {'access_token': 'pw_api_' + 'x'*43, 'token_type': 'Bearer', 'expires_in': 2592000}
with patch.object(client, 'json', side_effect=[challenge, result]) as api:
expiry = client.login('anya', 'synthetic-password', lambda _: '123456', remember=remember)
self.assertEqual(api.call_args_list[0].kwargs['form'].get('remember'), '1' if remember else None)
self.assertNotIn('remember', api.call_args_list[1].kwargs['form'])
self.assertAlmostEqual(expiry - time.time(), 2592000, delta=2)
def test_oidc_choice_is_bound_at_start(self):
for remember in (False, True):
client = m['Client']('https://wiki.example')
start = {'device_code': 'd'*43, 'verification_uri': '/_/auth/cli/verify?request='+'r'*43,
'user_code': 'ABCD-1234', 'expires_in': 300, 'interval': 5}
result = {'access_token': 'pw_api_'+'x'*43, 'token_type': 'Bearer', 'expires_in': 2592000, 'username': 'anya'}
with patch.object(client, 'json', side_effect=[start, result]) as api, contextlib.redirect_stdout(io.StringIO()):
client.login_oidc(True, remember=remember, sleep=lambda _: None, clock=lambda: 0)
self.assertEqual(api.call_args_list[0].kwargs['form'].get('remember'), '1' if remember else None)
self.assertNotIn('remember', api.call_args_list[1].kwargs['form'])
+46
View File
@@ -5,6 +5,7 @@ import json
from pathlib import Path
import runpy
import sys
import uuid
from types import SimpleNamespace
from unittest.mock import patch
from email.message import EmailMessage
@@ -61,5 +62,50 @@ def run():
output=io.StringIO()
with contextlib.redirect_stdout(output):m['contacts'](client,['export',contact['uuid']])
assert 'UID:urn:test:cli' in output.getvalue()
# Failed captures can be replaced locally; committed receipts remain protected.
request_id=str(uuid.uuid4())
with contextlib.redirect_stderr(io.StringIO()):
try:task('add','Rejected draft','--request-id',request_id,'--estimate','-1')
except m['Failure'] as error:assert error.status==422
else:raise AssertionError('Invalid estimate accepted')
assert profile.data['task_outbox'][request_id]['estimate_minutes']==-1
corrected=task('add','Corrected draft','--request-id',request_id,'--estimate','15')['item']
assert corrected['uuid']==request_id and corrected['title']=='Corrected draft'
assert request_id not in profile.data['task_outbox']
try:task('add','Changed after commit','--request-id',request_id,'--estimate','30')
except m['Failure'] as error:assert error.status==412
else:raise AssertionError('Committed capture silently overwritten')
assert profile.data['task_outbox'][request_id]['title']=='Changed after commit'
stored=task('show',request_id)['item']
assert stored['title']=='Corrected draft' and stored['estimate_minutes']==15
# Deleted receipts must not be mistaken for editable conflicts. An
# explicit recreation preserves the old tombstone and changes identity.
client.request(m['TASK_API']+'items/'+request_id,method='DELETE',etag='"'+str(stored['version'])+'"')
with contextlib.redirect_stderr(io.StringIO()):
try:task('retry',request_id)
except m['Failure'] as error:
assert error.status==410 and '--recreate-deleted' in str(error)
else:raise AssertionError('Deleted task implicitly recreated')
recreated=task('retry',request_id,'--recreate-deleted')['item']
replacement=str(uuid.uuid5(uuid.NAMESPACE_URL,'pages:task-recreate:'+request_id))
assert recreated['uuid']==replacement and recreated['title']=='Changed after commit'
assert recreated['estimate_minutes']==30 and not profile.data.get('task_outbox')
try:task('show',request_id)
except m['Failure'] as error:assert error.status==404
else:raise AssertionError('Deleted UUID resurrected')
# Reimport a deleted mail with a changed body: reconnect the surviving
# Wiki note, without overwriting its independent content or revision.
mail_id=captured['item']['uuid']
client.request(m['TASK_API']+'items/'+mail_id,method='DELETE',etag='"1"')
changed_mail=mail.replace(b'Private mail body',b'Changed private body')
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(changed_mail))),contextlib.redirect_stderr(io.StringIO()):
try:task('from-mail')
except m['Failure'] as error:assert error.status==410
else:raise AssertionError('Deleted mail task recreated implicitly')
with contextlib.redirect_stderr(io.StringIO()):recreated_mail=task('retry',mail_id,'--recreate-deleted')
assert recreated_mail['item']['page_uuid']==captured['item']['page_uuid']
assert recreated_mail['page_path']==captured['page_path']
body,_=client.raw('path:'+recreated_mail['page_path'])
assert 'Private mail body' in body.decode() and 'Changed private body' not in body.decode()
if __name__=='__main__':run()
+3
View File
@@ -191,3 +191,6 @@
backdrop-filter: none;
}
}
/* Keep the persistent-session control compact and touchable in all themes. */
.auth-form label.auth-remember{display:flex;flex-direction:row;align-items:center;gap:.65rem;min-height:44px;font-size:.85rem;cursor:pointer}
.auth-form label.auth-remember input{width:1.15rem;height:1.15rem;min-height:0;flex:0 0 auto;padding:0;margin:0;accent-color:var(--accent)}
+13
View File
@@ -0,0 +1,13 @@
.browser-upload-target{outline:2px dashed var(--accent,var(--link));outline-offset:-4px;background:color-mix(in srgb,var(--accent,var(--link)) 8%,var(--bg))}
.browser-upload-queue{position:fixed;right:1rem;bottom:1rem;z-index:950;width:min(27rem,calc(100vw - 2rem));box-sizing:border-box;background:var(--bg);color:var(--fg);border:1px solid var(--border,var(--border-soft));border-radius:.6rem;box-shadow:0 .5rem 2rem #0005;padding:.5rem}
.browser-upload-queue[hidden],.browser-upload-queue [hidden]{display:none}
.browser-upload-queue header,.browser-upload-queue footer{display:flex;align-items:center;gap:.5rem}
.browser-upload-queue header strong{flex:1}.browser-upload-queue footer{justify-content:flex-end}
.browser-upload-queue button{font:inherit;color:inherit;background:transparent;border:1px solid var(--border-soft);border-radius:.3rem;min-width:2rem;min-height:2rem;cursor:pointer}
.browser-upload-queue button:disabled{opacity:.4;cursor:default}
.browser-upload-queue ol{list-style:none;margin:.4rem 0;padding:0;max-height:40dvh;overflow:auto;overscroll-behavior:contain}
.browser-upload-queue li{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:.2rem .5rem;padding:.4rem 0;border-top:1px solid var(--border-soft)}
.browser-upload-queue .upload-name{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.browser-upload-queue .upload-state{font-size:.8rem;grid-column:1/-1;overflow-wrap:anywhere}
.browser-upload-queue progress{width:100%;height:.35rem;grid-column:1/-1;accent-color:var(--accent,var(--link))}.browser-upload-queue [data-state=failed] .upload-state{color:var(--danger,#e77373)}
.browser-upload-queue .upload-notice{margin:.3rem 0;font-size:.85rem}.browser-upload-queue .upload-notice:empty{display:none}
@media(max-width:600px){.browser-upload-queue{right:.5rem;bottom:.5rem;width:calc(100vw - 1rem)}.browser-upload-queue button{min-height:44px;min-width:44px}.browser-upload-queue ol{max-height:35dvh}}
Loaded 100 of 142 files, more files were not shown because too many files have changed in this diff. Show more