Skip to content

feat: Basic auth - #7

Merged
tmlksu merged 1 commit into
mainfrom
feat/basic-auth
Aug 26, 2026
Merged

tmlksu merged 1 commit into
mainfrom
feat/basic-auth

Conversation

@tmlksu

@tmlksu tmlksu commented Aug 26, 2026

Copy link
Copy Markdown
Owner

なぜ

Nextcloud と Synology はサーバ自身が資格情報を持つので、これが無いとそもそも接続できない。互換表にも「Basic 認証が要るので入れられない」と書いてあった行がそれ。

保存方針(先に確認した点)

資格情報は chrome.storage.local に平文で載る。拡張にはユーザーに紐づく保存先が無いので、暗号化しても鍵を同じ場所に置くことになる。難読化して安全に見せるより、設定画面に平文と明記し、https:// の共有にしか設定できないようにした(平文で線を流させない)。

アプリパスワードを発行できるサーバではそちらを使うよう、フォームに書いた。

実装で名前を出しておくべき点 2 つ

  • RFC 7617 は UTF-8。btoa は Latin-1 しか受け付けないので、非 ASCII のパスワードをそのまま渡すと例外になる。先に UTF-8 に符号化してから base64 している
  • 別オリジンへのリダイレクトを弾く。fetch はリダイレクトを跨いでも Authorization を落とさないので、追った先が無関係なホストだと資格情報がそこへ渡る

テスト側の変更

test/live.mjs が Authorization を自前で組み立てていたのを、拡張の createAuth を通すように変えた。そうしないと結合テストが検証しているのがテスト側のコードになってしまう。

互換表

Nextcloud 34 が 149/149 で通過。他の実装と踏む経路が違うのが価値で、Basic 認証が必須なうえサブパス配信 (/remote.php/dav/files/<user>) なので baseurl の処理も同時に通る。29MB の PDF に対する Range 検証も含む。

dufs --auth も入れた(Nextcloud は初回インストールに数分かかるので、軽い確認用)。

server      PROPFIND  Range GET  結合テスト
----------- --------  ---------  ----------
rclone      207       206        合格 (66 件)
apache      207       206        合格 (66 件)
dufs        207       206        合格 (66 件)
hacdias     207       206        合格 (66 件)
dufs-auth   207       206        合格 (66 件)
nextcloud   207       -          合格 (149 件)
nginx       405       206        対象外 (想定どおり)

compat.sh の起動待ちを「何か応答した」から「これから投げるリクエストが通った」に変えた。前者だと Nextcloud のインストール中の 503 を掴んで先へ進んでしまう。

その他

  • toProviderError で 401 → ACCESS_DENIED(今までは FAILED に落ちていた)
  • ユニットテスト 82 → 90 件
  • 既存テストが 'basic' を「未知の認証方式」の例に使っていたので 'digest' に差し替え

🤖 Generated with Claude Code

Unlocks the servers people actually ask about. Nextcloud and Synology hold
their own credentials, so until now there was no way to point the extension at
one — the compatibility table said as much.

The credentials are stored in cleartext in chrome.storage.local. An extension
has no storage keyed to the user, so encrypting them would mean keeping the key
next to them; obfuscating it would only look safe. Instead the settings page
states plainly where they are stored, and the mode is restricted to https://
shares so they are never sent over the wire in the clear.

Two details worth naming:

- Credentials are UTF-8 encoded before base64, per RFC 7617. Passing a non-ASCII
  password straight to btoa throws.
- A redirect to another origin is rejected. fetch does not drop the
  Authorization header across a redirect, so following one to an unrelated host
  would hand it the credentials.

test/live.mjs now goes through the extension's own auth instead of building an
Authorization header itself — otherwise the integration test would be exercising
test code rather than the shipped implementation.

Nextcloud joins the compatibility matrix (149/149). It exercises two paths the
other servers don't: Basic auth, and serving from a subpath, which puts the
baseurl handling under test. dufs --auth is there too as a light check that
doesn't need a multi-minute install. The readiness probe now waits for the exact
request the test will make, rather than for any response at all, so Nextcloud's
installer returning 503 no longer counts as ready.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@tmlksu
tmlksu merged commit 39b54b0 into main Aug 26, 2026
3 checks passed
@tmlksu
tmlksu deleted the feat/basic-auth branch August 26, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant