CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识 & 商标
  • 商业解决方案
  • 礼品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙坊
    • 特色资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 新闻
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助 & 支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 FormProtector

防止表单篡改。它确保

  • 表单的操作 (URL) 不会被修改。
  • 未知/额外的字段不会被添加到表单中。
  • 现有的字段不会从表单中移除。
  • 隐藏输入的值不会被更改。
命名空间: Cake\Form

属性摘要

  • $debugMessage protected
    string|null

    提供验证失败详细信息的错误消息。

  • $fields protected
    array

    字段列表。

  • $unlockedFields protected
    list<string>

    解锁的字段。

方法摘要

  • __construct() public

    构造。

  • __debugInfo() public

    返回调试信息

  • addField() public

    确定表单中哪些字段应该用于哈希。

  • buildTokenData() public

    生成令牌数据。

  • debugCheckFields() protected

    迭代数据数组以检查预期

  • debugExpectedFields() protected

    为预期字段生成调试消息

  • debugTokenNotMatching() protected

    创建一条消息,供人类理解为什么安全令牌不匹配

  • extractFields() protected

    返回用于哈希计算的字段列表

  • extractHashParts() protected

    返回用于令牌生成的哈希部分

  • extractToken() protected

    从数据中提取令牌。

  • generateHash() protected

    生成验证哈希。

  • getError() public

    获取验证错误消息。

  • getFieldNameArray() protected

    解析字段名以创建用于字段哈希的点分隔名称值。如果字段名为表单 Model[field] 或 Model.field,则返回一个包含字段名部分的数组,例如 ['Model', 'field']。

  • matchExistingFields() protected

    为 POST 数据中存在的字段生成消息数组,与 $expectedFields 中的数据字段匹配的字段将被 unset

  • sortedUnlockedFields() protected

    获取排序后的解锁字符串

  • unlockField() public

    添加到当前解锁的字段列表中。

  • validate() public

    验证提交的表单数据。

方法详情

__construct() ¶ public

__construct(array<string, mixed> $data = [])

构造。

参数
array<string, mixed> $data optional

数据数组,可以包含键 unlockedFields,其中包含解锁字段列表。

__debugInfo() ¶ public

__debugInfo(): array<string, mixed>

返回调试信息

返回值
array<string, mixed>

addField() ¶ public

addField(list<string>|string $field, bool $lock = true, mixed $value = null): $this

确定表单中哪些字段应该用于哈希。

参数
list<string>|string $field

要保护的字段的引用。可以是点分隔字符串,表示嵌套,也可以是字段名部分的数组。

bool $lock optional

此字段是否应作为验证的一部分,或作为 unlockedFields 的一部分被排除。默认值为 true。

mixed $value optional

字段值,如果值不应该被篡改。

返回值
$this

buildTokenData() ¶ public

buildTokenData(string $url = '', string $sessionId = ''): array<string, string>

生成令牌数据。

参数
string $url optional

表单 URL。

string $sessionId optional

会话 ID。

返回值
array<string, string>

debugCheckFields() ¶ protected

debugCheckFields(array $dataFields, array $expectedFields = [], string $intKeyMessage = '', string $stringKeyMessage = '', string $missingMessage = ''): list<string>

迭代数据数组以检查预期

参数
array $dataFields

字段数组,包含 POST 数据字段

array $expectedFields optional

字段数组,包含我们应该在 POST 中拥有的预期字段

string $intKeyMessage optional

如果在数据字段中通过 int(未受保护)索引发现意外值,则显示消息字符串

string $stringKeyMessage optional

如果在数据字段中通过字符串(受保护)索引发现篡改值,则显示消息字符串。

string $missingMessage optional

如果缺少字段,则显示消息字符串

返回值
list<string>

debugExpectedFields() ¶ protected

debugExpectedFields(array $expectedFields = [], string $missingMessage = ''): string|null

为预期字段生成调试消息

参数
array $expectedFields optional

预期字段

string $missingMessage optional

消息模板

返回值
string|null

debugTokenNotMatching() ¶ protected

debugTokenNotMatching(array $formData, array $hashParts): string

创建一条消息,供人类理解为什么安全令牌不匹配

参数
array $formData

数据。

array $hashParts

用于生成令牌哈希的元素

返回值
string

extractFields() ¶ protected

extractFields(array $formData): array

返回用于哈希计算的字段列表

参数
array $formData

数据数组

返回值
array

extractHashParts() ¶ protected

extractHashParts(array<string, array> $formData): array<string, array>

返回用于令牌生成的哈希部分

参数
array<string, array> $formData

表单数据。

返回值
array<string, array>

extractToken() ¶ protected

extractToken(mixed $formData): string|null

从数据中提取令牌。

参数
mixed $formData

要验证的数据。

返回值
string|null

generateHash() ¶ protected

generateHash(array $fields, list<string> $unlockedFields, string $url, string $sessionId): string

生成验证哈希。

参数
array $fields

字段列表。

list<string> $unlockedFields

解锁的字段。

string $url

表单 URL。

string $sessionId

会话 ID。

返回值
string

getError() ¶ public

getError(): string|null

获取验证错误消息。

返回值
string|null

getFieldNameArray() ¶ protected

getFieldNameArray(string $name): list<string>

解析字段名以创建用于字段哈希的点分隔名称值。如果字段名为表单 Model[field] 或 Model.field,则返回一个包含字段名部分的数组,例如 ['Model', 'field']。

参数
string $name

表单输入的 name 属性。

返回值
list<string>

matchExistingFields() ¶ protected

matchExistingFields(array $dataFields, array $expectedFields, string $intKeyMessage, string $stringKeyMessage): list<string>

为 POST 数据中存在的字段生成消息数组,与 $expectedFields 中的数据字段匹配的字段将被 unset

参数
array $dataFields

字段数组,包含 POST 数据字段

array $expectedFields

字段数组,包含我们应该在 POST 中拥有的预期字段

string $intKeyMessage

如果在数据字段中通过 int(未受保护)索引发现意外值,则显示消息字符串

string $stringKeyMessage

如果在数据字段中通过字符串(受保护)索引发现篡改值,则显示消息字符串

返回值
list<string>

sortedUnlockedFields() ¶ protected

sortedUnlockedFields(array $formData): list<string>

获取排序后的解锁字符串

参数
array $formData

数据数组

返回值
list<string>

unlockField() ¶ public

unlockField(string $name): $this

添加到当前解锁的字段列表中。

解锁的字段不会包含在字段哈希中。

参数
string $name

字段的点分隔名称。

返回值
$this

validate() ¶ public

validate(mixed $formData, string $url, string $sessionId): bool

验证提交的表单数据。

参数
mixed $formData

表单数据。

string $url

表单 POST 到的 URL。

string $sessionId

用于哈希生成的会话 ID。

返回值
布尔值

属性详情

$debugMessage ¶ 受保护

提供验证失败详细信息的错误消息。

类型
string|null

$fields ¶ 受保护

字段列表。

类型
array

$unlockedFields ¶ 受保护

解锁的字段。

类型
list<string>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识 & 商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙坊
  • 特色资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助 & 支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成