morepath的内容安全策略

more.content-securit的Python项目详细描述


用法

使用默认内容安全策略保护所有视图:

frommorepathimportAppfrommore.content_securityimportContentSecurityAppfrommore.content_securityimportContentSecurityPolicyfrommore.content_securityimportSELFclassMyApp(App,ContentSecurityApp):pass@MyApp.setting('content_security_policy','default')defdefault_policy():returnContentSecurityPolicy(default_src={SELF},script_src={SELF,'https://analytics.example.org'})

要扩展模型默认视图的默认策略:

@MyApp.view(model=Document)defview_document(self,request):# the actual default policy is not modified here!request.content_security_policy.script_src.add('https://cdnjs.com')....

我们还可以使用完全不同的策略:

@MyApp.view(model=Document)defview_document(self,request):request.content_security_policy=ContentSecurityPolicy()

此外,我们可以在内联脚本/样式表中使用nonce。那些意志 自动添加到“script src”、“style src”指令:

@MyApp.html(model=Document)defview_document(self,request):return"""
        <html>
            ...

            <script nonce="{}">...</script>
        </html>
    """.format(request.content_security_policy_nonce('script'))

请注意,我们对nonce使用自定义请求类。如果你有自己的, 您需要将其扩展如下:

frommorepath.requestimportRequestfrommore.content_securityimportContentSecurityRequestclassCustomRequest(Request,ContentSecurityRequest):passclassMyApp(App,ContentSecurityApp):request_class=CustomRequest

若要仅使用“仅内容安全策略报告”标题,请使用以下内容:

@MyApp.setting('content_security_policy','default')defdefault_policy():returnContentSecurityPolicy(report_only=True,default_src={SELF})

运行测试

安装tox并运行它:

pip install tox
tox

将测试限制为特定的python版本:

tox -e py27

约定

更多内容安全性尽可能接近PEP8。要测试它,请运行:

tox -e pep8

more.content安全使用Semantic Versioning

生成状态

Build Status

覆盖范围

Project Coverage

最新的PYPI版本

Latest PyPI Release

许可证

more.content_security在经过修订的bsd许可证下发布

更改日志

0.2.0(2018-02-02)

  • 添加重写策略应用函数的功能。 [资源]
  • 添加缺少的不安全评估常数。 [资源]

0.1.0(2018-02-01)

  • 初次发布。 [资源]

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java WebClient请求级别超时抛出名为default onErrorDropped的运算符   java JAXB外部绑定文件错误   Freemarker中的java转义宏参数值   java正在同步来自不同对象{已编辑}的线程   java如何在另一个类上更新活动中的元素   java Hibernate连接查询   java可以使用Apache Crunch创建类似于图形的数据结构吗?   java在JLabel的开头加上3个点   java 安卓应用程序显示线程错误   java@RequestBody在Spring中总是空的   java Android异步任务永远不会结束   具有多个属性的java Jaxws枚举   java中的安卓 Stripe InvalidRequestException   多线程java。util。非多线程程序中的ConcurrentModificationException   Minecraft Java插件如何删除HashMap中存储的所有块   空Java字符串的大小   从AJP连接器请求检索Shibboleth属性的java   oracle11g将Java类文件加载到Oracle数据库