docs: qualify tinystruct static-root protections against pinned source

This commit is contained in:
haelyra committed 2026-10-29 17:44:54 -07:00
commit 0fae27de35
2 files changed
+12 -6

No files matched your search

@@ -323,7 +323,8 @@ default.home.page=hello
server.port=8080
default.server.open_browser=true
# 静的ファイルはこれらのディレクトリ(カンマまたはセミコロン区切り)からのみ配信されます。
# 作業ディレクトリ自体やその祖先を静的ルートに指定しないでください。デフォルト:static
# ルートや親パスにシンボリックリンクがない公開用の実ディレクトリを使ってください。
# 作業ディレクトリ自体やその祖先を公開しないでください。デフォルト:static
# server.static.dirs=static,public
# ロケール
@@ -370,7 +371,9 @@ String port = this.getConfiguration("server.port");
## 静的ファイル
組み込みの `HttpServer` は、`server.static.dirs`(カンマまたはセミコロン区切り)、それがなければ `server.static.dir` で指定されたディレクトリからのみ静的ファイルを配信します。デフォルトは `static` です。作業ディレクトリ自体とその祖先は静的ルートとして拒否され、警告が記録されます。バージョン 1.7.37 は兄弟ディレクトリなど、作業ディレクトリ外の設定済みルートも許可します。子孫ディレクトリだけに制限する実装ではありません。公開アセットには `static/` のような専用ディレクトリを推奨します。`.` や `..` のセグメントを含むリクエスト、隠しファイルやフォルダ(`.git` や `.env` など `.` で始まるもの)を指すリクエスト、`.` や空白で終わる名前、プロジェクトルート直下のファイルを指すリクエストは拒否されます。シンボリックリンクの解決後も、配信するファイルは設定済みルート内に収まる必要があります。
組み込みの `HttpServer` は、`server.static.dirs`(カンマまたはセミコロン区切り)、それがなければ `server.static.dir` で指定されたルートから静的ファイルを配信します。デフォルトは `static` です。1.7.37 の作業ディレクトリ・祖先チェックは、シンボリックリンクを解決する前の正規化されたパス名を比較します。通常の実ディレクトリを指定する `.` や `..` は拒否しますが、設定したルートがプロジェクトディレクトリや祖先へのシンボリックリンクの場合、このチェックを通過できます。作業ディレクトリ外の兄弟ディレクトリも許可され、子孫ディレクトリだけに制限する実装ではありません。
公開用アセットには、公開するファイルだけを置いた `static/` のような専用の実ディレクトリを使ってください。設定したルートやその親パスの要素が、より広いディレクトリや非公開ディレクトリへのシンボリックリンクになっていないことを確認してください。`.` や `..` のセグメント、`.git` や `.env` などの隠し名、`.` や空白で終わる名前を含むリクエストは拒否されます。配信候補のファイルは、設定したルートの解決後のパス内に収まる必要があります。ただし、ルート自体の解決先がプロジェクトディレクトリなら、この包含チェックではルート直下のファイルを保護できません。ハンドラは後段の `isProjectRootFile` チェックより先に、一致した静的ファイルを配信します。設定したルートがシンボリックリンクの場合、プロジェクトルートのファイルが常に拒否されるとは考えないでください。[固定した v1.7.37 の実装](https://github.com/tinystruct/tinystruct/blob/089ec19022f3bb5d87f1e83e30b2034b24f7e77f/src/main/java/org/tinystruct/system/HttpServer.java#L569-L720)を参照してください。
## レッドフラグとアンチパターン
@@ -390,7 +393,7 @@ String port = this.getConfiguration("server.port");
| CLI引数が認識されない | `--key value` の形で渡し、`getContext().getAttribute("--key")` でアクセスする。 |
| 同じパスの2つのメソッドで、意図しない方が呼ばれる | 明示的な `mode`(例:`HTTP_GET` と `HTTP_POST`)を設定して区別する。 |
| `bin/dispatcher` が "The action is not allowed to be executed." で失敗する | そのアクションはHTTP固有のモードを持っており、CLIからは呼び出せない。HTTPでテストする。両方に対応するには、まずHTTP専用の依存関係を共有ロジックから分離し、CLI対応のエントリポイントに `Mode.DEFAULT` を使用する。 |
| ファイルが存在するのに静的ファイルが404を返す | `server.static.dirs` / `server.static.dir`(デフォルト `static/`)のみが配信される。隠しファイル、`..` を含むパス、プロジェクトルート直下のファイルは常に拒否される。 |
| ファイルが存在するのに静的ファイルが404を返す | `server.static.dirs` / `server.static.dir`(デフォルト `static/`)、禁止されたリクエスト名、解決後のルート内への包含を確認する。公開用の実ディレクトリを使う。設定したルートがシンボリックリンクなら、プロジェクトルートのチェックより先にプロジェクトや祖先のファイルが公開される場合がある。 |
| ログファイルが書き出されない | `FileHandler` はオプトイン:`handlers` に `java.util.logging.FileHandler` を追加する。`java.util.logging.FileHandler.pattern` を設定しない場合、ファイルは `%h/java%u.log`(ホームディレクトリ)に作成される。 |
| `FINE` / デバッグメッセージが表示されない | 両方のゲートが許可する必要がある:`logging.level=FINE`(または `org.tinystruct.level=FINE` のようなパッケージ単位の上書き)を設定し、ハンドラの `.level` がそれより厳しくないことを確認する。 |
+6 -3
View File
@@ -324,7 +324,8 @@ default.home.page=hello
server.port=8080
default.server.open_browser=true
# Static files are served only from these directories (comma- or semicolon-separated),
# Do not use the working directory or an ancestor as a static root. Default: static
# Use real public directories without symlinked root components.
# Do not expose the working directory or its ancestors. Default: static
# server.static.dirs=static,public
# Locale
@@ -371,7 +372,9 @@ The framework includes a programmatic wrapper around `java.util.logging` (JUL) t
## Static Files
The built-in `HttpServer` serves static files only from the directories named by `server.static.dirs` (comma- or semicolon-separated) or, failing that, `server.static.dir`; the default is `static`. It rejects the working directory itself and its ancestors as static roots, logging a warning. Version 1.7.37 also permits configured roots outside the working directory, such as sibling directories; it does not enforce a descendants-only policy. Prefer a dedicated public-assets directory such as `static/`. Requests are rejected when they contain `.` or `..` segments, name hidden files or folders (anything starting with `.`, such as `.git` or `.env`), end in `.` or a space, or point at files in the project root. Resolved files must remain within the configured root, including after symlink resolution.
The built-in `HttpServer` serves static files from the roots named by `server.static.dirs` (comma- or semicolon-separated) or, failing that, `server.static.dir`; the default is `static`. In 1.7.37, the working-directory/ancestor check compares normalized path names before resolving symlinks. It rejects ordinary roots such as `.` or `..`, but a configured root that symlinks to the project directory or an ancestor can pass that check. Sibling directories outside the working directory are also allowed; a descendants-only policy is not enforced.
Use a real, dedicated public-assets directory such as `static/`, containing only files intended for public access. Check that the configured root and its parent path components do not symlink to a broader or private directory. Requests containing `.` or `..` segments, hidden names such as `.git` or `.env`, or names ending in `.` or a space are rejected. Candidate files must remain within the configured root's resolved path. That containment does not prevent project-root exposure when the configured root itself resolves there: the handler serves a matching static file before the later `isProjectRootFile` check. Do not rely on a blanket project-root-file denial with symlinked configured roots. See the [pinned v1.7.37 implementation](https://github.com/tinystruct/tinystruct/blob/089ec19022f3bb5d87f1e83e30b2034b24f7e77f/src/main/java/org/tinystruct/system/HttpServer.java#L569-L720).
## Red Flags & Anti-patterns
@@ -391,7 +394,7 @@ The built-in `HttpServer` serves static files only from the directories named by
| CLI arg not visible | Pass with `--key value`; access via `getContext().getAttribute("--key")`. |
| Two methods same path, wrong one fires | Set explicit `mode` (e.g., `HTTP_GET` vs `HTTP_POST`) to disambiguate. |
| `bin/dispatcher` fails with "The action is not allowed to be executed." | The action has an HTTP-specific mode; it is not reachable from the CLI. Test it over HTTP. To support both transports, first separate HTTP-only dependencies from shared logic, then use `Mode.DEFAULT` for a CLI-compatible entry point. |
| A static file returns 404 though it exists | Only `server.static.dirs` / `server.static.dir` (default `static/`) are served; hidden files, `..` paths and project-root files are always refused. |
| A static file returns 404 though it exists | Check `server.static.dirs` / `server.static.dir` (default `static/`), forbidden request names, and resolved-root containment. Use a real public directory; symlinked configured roots can expose project or ancestor files before the project-root check. |
| No log file is written | `FileHandler` is opt-in: add `java.util.logging.FileHandler` to `handlers`. Set `java.util.logging.FileHandler.pattern` or the file lands in `%h/java%u.log` (your home directory). |
| `FINE` / debug messages never appear | Both gates must allow them: set `logging.level=FINE` (or a package override like `org.tinystruct.level=FINE`) and make sure the handler's `.level` is not stricter. |