silksh/security-bundle
Composer 安装命令:
composer require silksh/security-bundle
包简介
Security related extensions for Symfony
README 文档
README
This bundle requires Symfony 3 or Symfony 4.
Bundle installation
Add the bundle to you project dependencies:
composer require silksh/security-bundle
Symfony 3. Enable the bundle:
// app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { return array( // ... new SilkSH\SecurityBundle\SilkshSecurityBundle(), ); } }
Symfony 4. It's automatic, but if Symfony did not do it for you, enable the bundle manually in bundles.php:
// config/bundles.php return [ // ... SilkSH\SecurityBundle\SilkshSecurityBundle::class => ['all' => true], ]
Validators
The bundle provides some Validators in the namespace SilkSH\SecurityBundle\Validator\Constraints.
-
FileNamevalidates filenames. Possible properties:maxFilenameLength, default: 100.maxFilenameLengthMessage: custom length error message. You can use{{ max_length }}inside.allowedExtensions, default: "pdf", "txt", "doc", "docx", "ppt", "pptx", "jpg", "jpeg", "png"allowedExtensionsMessage, custom error message about wrong extension. You can use{{ extension }}and{{ extensions }}inside.
Example:
use SilkSH\SecurityBundle\Validator\Constraints as SecurityAssert; ... /** * @Vich\UploadableField(mapping="uploads", fileNameProperty="filename") * @SecurityAssert\FileName( * maxFilenameLength=8, * maxFilenameLengthMessage="Maximal file length is {{ max_length }} characters", * allowedExtensions={"zip","bz2"}, * allowedExtensionsMessage="Extension '{{ extension }}' is not allowed. Allowed extensions: {{ extensions }}" * ) */ private $file;
-
Nameallows only international alphanumeric and some special characters (A-z 0-9 - + _ . , @ " '). Possible properties:message: custom error message. You can use{{ allowed_signs }}inside.
-
HTMLPurifierallows only whitelisted HTML tags and attributes. It uses HTML Purifier library. Possible properties:message: custom error message.
-
TagWhitelist: simple and buggy HTML tag validator that usesDOMDocument. UsingHTMLPurifierinstead is recommended. Possible properties:allowedTags, default: "html", "head", "meta", "title", "style", "body", "table", "tr", "th", "td", "h1", "h2", "h3", "h4", "h5", "h6", "p", "a", "img", "br", "span", "small".allowedTagsMessage, custom error message for non valid tags. You can use{{ allowed_tags }}inside.allowedAttributes, default: "width", "align", "cellspacing", "cellpadding", "class", "style", "href", "http-equiv", "name", "alt", "border", "content", "bgcolor", "type", "target", "src".allowedAttributesMessage, custom error message for non valid attributes. You can use{{ allowed_attributes }}inside.
Twig extension
The bundle provides purify filter for Twig.
It uses HTML Purifier to remove all unsafe tags (like <script>) and attributes (like onclick) from HTML code.
Let's say we have some HTML code in the variable value and we want to render it unescaped,
so that the user sees formatted output. Usage:
{{ value|purify|raw }}
silksh/security-bundle 适用场景与选型建议
silksh/security-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.88k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 silksh/security-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 silksh/security-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2018-06-21