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第三方库


热门话题
Docker&SeleniumJava:无法在Docker容器上运行的chrome浏览器中上载图像/文件   在python中运行java命令   Java垃圾收集器异常行为   java java是否根据底层操作系统执行字节码级优化?   java是否可以休眠自定义查询返回映射而不是列表?   java Spring引导RabbitMQ接收器Jackson反序列化到POJO   apache flex在ActionScript3中创建对象相等“HashMap”作为java HashMap   java如何在Eclipse集成中切换JProfiler启动器   缓存JSP页面结果的java最佳实践?   java集成jaxb绑定文件,使用CXF生成基于WSDL的客户端   java为什么在上传操作结束之前,客户端没有检测到HttpServletResponse的PrintWriter内容?   java在接口内创建类和在类内创建接口有什么用   java向文件写入错误Android Studio   java合并多个RealmList并对结果列表排序?   谷歌API视觉java。lang.NoSuchMethodError   java如何使用逗号分别存储每个值,然后将它们存储到单独的数组中?