a-blog cms PHP API Reference

SetupCsrfToken
in package

FinalYes

セットアップ画面専用の CSRF トークン生成・照合。

install フローは DB 未接続の段階を含み、本体の Session::handle()(DB セッション ハンドラや session_write_close 干渉)に依存できないため、setup 独自の native $_SESSION に持たせるトークンをここで扱う。値の保持は呼び出し側(setup.php / install.php のセッション)に委ね、本クラスは生成と照合だけを行う純粋ロジックとする。

Table of Contents

Methods

generate()  : string
新しいトークンを生成する。
matches()  : bool
期待トークンと入力トークンが一致するか判定する。

Methods

generate()

新しいトークンを生成する。

public static generate() : string

本体 Common::createCsrfToken() と同じく bin2hex(random_bytes(16)) を用い、 暗号論的乱数由来の 32 文字の 16 進文字列を返す。

Return values
string

matches()

期待トークンと入力トークンが一致するか判定する。

public static matches(string|null $expected, string|null $input) : bool

空・null は「トークン未発行 / 未送信」であり一致とみなしてはならないため、 hash_equals に渡す前に弾く。比較はタイミング攻撃を避けるため hash_equals を使う (=== では文字列長・内容の差で処理時間が変わり得るため)。

Parameters
$expected : string|null

セッションが保持する期待トークン

$input : string|null

リクエストで送られてきたトークン

Return values
bool

        
On this page

Search results