テーマ: input-validation
-
HTML 標準のフォーム検証:required、pattern、type と Constraint Validation API
HTML はスクリプトなしで送信前にフォーム部品を検証する。required、minlength、min/max、pattern、型付き入力が制約を定め、ブラウザーが送信を止めてメッセージを表示する。CSS では :user-invalid を装飾でき、Constraint Validation API は同じ状態をスクリプトに公開する。これは使いやすさの層であり、安全性の層ではない。サーバーで再度検証する。
-
Testing that profile updates cannot assign privileged account fields
Create a narrow regression for updates that accept ordinary profile data alongside fields the caller must not control. The method proposes explicit field ownership rather than a generic input-validation checklist.
-
Validating, storing and serving user file uploads
Accept only the file types the feature needs, decide type by extension allowlist plus content check rather than the client's Content-Type, rename to a random identifier, enforce size limits before and after decompression, store outside the web root or on a separate host, and serve through a handler that sets the type, nosniff and Content-Disposition, ideally from a separate origin.
-
オープンリダイレクト:next パラメーターの移動先を検証する
リクエストから移動先を取るリダイレクトは、自分のドメインに見えて攻撃者のサイトに着くリンクを作らせます。相対パスか許可したオリジンだけへ送るか、短い識別子をサーバー側で移動先に対応付けます。URL のホスト確認は見かけより難しく、Python の文書は urlsplit が入力を検証しないと警告しています。
-
ファズテストの基礎:カバレッジに基づく入力、コーパス、クラッシュの切り分け
カバレッジ誘導型ファザーは入力を変異させ、新しいコードに到達したものをコーパスへ残し、最小化した失敗入力を報告します。性質を検証する小さく決定的なターゲットを書き、コーパスに初期入力を入れてコミットし、CI では短時間、定期的には長時間実行します。すべてのクラッシュ入力を回帰テストとして残します。
-
安全なアーカイブ展開:zip と tar のパストラバーサル
アーカイブの項目には ../../etc/passwd のような名前、絶対パス、シンボリックリンクが含まれ得る。各展開先パスを解決して宛先ディレクトリ内に収まることを確認してから展開し、外を指すリンクを拒否する。総サイズと項目数にも上限を設ける。
-
XML external entities: disabling DTD processing in parsers
An XML document can declare entities that expand to local files, internal URLs or gigabytes of text; a parser that honours them on untrusted input discloses files, performs server-side requests or exhausts memory. Disable DTDs entirely where the parser allows it, otherwise disable external entities and external DTD loading, and know the defaults of the parser you actually run.
機械可読: JSON