当前位置:首页 > 电脑知识

Calibre-Web修复跨域问题

canca2个月前 (01-20)电脑知识112
  1. 修改D:\calibre-web-master\cps\web.py文件

    原来代码

    def add_security_headers(resp):
        default_src = ([host.strip() for host in config.config_trustedhosts.split(',') if host] +
                       ["'self'", "'unsafe-inline'", "'unsafe-eval'"])
        csp = "default-src " + ' '.join(default_src)
        if request.endpoint == "web.read_book" and config.config_use_google_drive:
            csp +=" blob: "
        csp += "; font-src 'self' data:"
        if request.endpoint == "web.read_book":
            csp += " blob: "
        csp += "; img-src 'self'"
        if request.path.startswith("/author/") and config.config_use_goodreads:
            csp += " images.gr-assets.com i.gr-assets.com s.gr-assets.com"
        csp += " data:"
        if request.endpoint == "edit-book.show_edit_book" or config.config_use_google_drive:
            csp += " *"
        if request.endpoint == "web.read_book":
            csp += " blob: ; style-src-elem 'self' blob: 'unsafe-inline'"
        csp += "; object-src 'none';"
        resp.headers['Content-Security-Policy'] = csp
        resp.headers['X-Content-Type-Options'] = 'nosniff'
        resp.headers['X-Frame-Options'] = 'SAMEORIGIN'
        resp.headers['X-XSS-Protection'] = '1; mode=block'
        resp.headers['Strict-Transport-Security'] = 'max-age=31536000'
        return resp

    修改为以下代码

    def add_security_headers(resp):
        default_src = ([host.strip() for host in config.config_trustedhosts.split(',') if host] +
                       ["'self'", "'unsafe-inline'", "'unsafe-eval'"])
        csp = "default-src " + ' '.join(default_src)
        if request.endpoint == "web.read_book" and config.config_use_google_drive:
            csp +=" blob: "
        csp += "; font-src 'self' data:"
        if request.endpoint == "web.read_book":
            csp += " blob: "
        csp += "; img-src 'self'"
        if request.endpoint == "web.read_book":
            csp += " https: http: blob:"  
        if request.path.startswith("/author/") and config.config_use_goodreads:
            csp += " images.gr-assets.com i.gr-assets.com s.gr-assets.com"
        csp += " data:"
        if request.endpoint == "edit-book.show_edit_book" or config.config_use_google_drive:
            csp += " *"
        if request.endpoint == "web.read_book":
            csp += " ; style-src-elem 'self' blob: 'unsafe-inline'"
        csp += "; object-src 'none';"
        resp.headers['Content-Security-Policy'] = csp
        resp.headers['X-Content-Type-Options'] = 'nosniff'
        resp.headers['X-Frame-Options'] = 'SAMEORIGIN'
        resp.headers['X-XSS-Protection'] = '1; mode=block'
        resp.headers['Strict-Transport-Security'] = 'max-age=31536000'
        return resp

    cps增加http:和https:,支持外部图片资源

  2. 修复JS报错:D:\calibre-web-master\cps\static\js\libs\reader.min.js

    将原来

    this.rendition=c.renderTo("viewer",{ignoreClass:"annotator-hl",width:"100%",height:"100%"})
  3. 修改为

    this.rendition=c.renderTo("viewer",{ignoreClass:"annotator-hl",width:"100%",height:"100%",allowScriptedContent:true})

    增加 allowScriptedContent:true 参数

扫描二维码推送至手机访问。

版权声明:本文由Ant.Master's Blog发布,如需转载请注明出处。

本文链接:https://iant.work/post/899.html

分享给朋友:

“Calibre-Web修复跨域问题” 的相关文章

主板电容的作用

    电容又称电容器(Capacitor)。它在电路中起着隔直流、通交流的重要作用。电容根据其在电路中不同位置的不同功能,分为耦合电容、滤波电容、谐振电容、旁路电容等类别。另外,电容也可按照填充材料(电介质)进行…

0X????????”指令引用的“0x00000000”内存,该内存不能为“read

使用Windows操作系统的人有时会遇到这样的错误信息: 「“0X????????”指令引用的“0x00000000”内存,该内存不能为“read”或“written”」,然后应用程序被关闭。 如果去请教一些「高手」,得到的回答往往是「Windows就是这样不稳定…

电脑启动报鸣声说明

当打开电脑时,听到的不是平时清脆的启动声,而是一次又一次重复的奇怪的报警声时,你能不能马上判断出故障的所在呢?虽然现在多家厂商都设计出一些智能化的功能,能将报警声转换成语音或是指示灯等,但是有这种功能...…

office2003无法正常安装卸载问题解决

一、症状:1。点OFFICE里面的任何一个,比如WORD就会弹出一个错误的提示筐,说的是:这个操作只对当前安装的产品有效,无法运行该命令。系统里面的一些 OFFICE文档也是无法识别的。现在想把OFFICE2003删除,可在控制面板的"添加/删除程…

杀掉进程---介绍微软一个罕为人知的无敌命令

    问:怎么才能关掉一个用任务管理器关不了的进程?  我前段时间发现我的机子里多了一个进程,只要开机就在,我用任务管理器却怎么关也关不了。     答1:杀进程很容易,随便找个工具都行。比如IceSwor...…

通过注册表来修改IE安全设置

系统环境:Windows 2003 sp1 IE版本:IE 6.0 HKLM,"SoftwareMicrosoftWindowsCurrentVersionInternet SettingsZones下 安全级别currentlevel值:0安全级为自定义,12000安全级为高,11000安全级为…

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。