首页 > 解决方案 > 是否可以将自定义身份验证库注入 chrome 扩展后台脚本?

问题描述

我正在构建一个需要利用我公司内部 SSO 系统的 chrome 扩展程序。我正在使用后台脚本,因为我需要对可以返回身份验证令牌的服务进行 CORS 调用。我已经开发了一个可以为我处理这个问题的库,但是根据我所阅读的内容,无法将它注入到后台脚本中。我可以放宽内容策略以允许它,但文档指出,由于 XSS 漏洞,他们强烈建议不要这样做。我的问题是:有没有办法在不改变内容策略的情况下将我的库注入后台脚本?

//manifest.json

{
  "name": "Travelers Learning",
  "version": "1.0",
  "description": "Chrome extension to enable xAPI",
  "background": {
    "scripts": ["tx.js", "tx-auth.js", "main.js"],
    "persistent": true
  },
  "permissions": [
    "activeTab",
    "tabs"
  ],
  "content_scripts": [
    {
      "run_at": "document_end",
      "matches": ["http://*/*", "https://*/*"],
      "js": ["interactionProfile.js", "tx.js", "all.js"]
    },
    {
      "run_at": "document_end",
      "matches": ["*://*.youtube.com/*"],
      "js": ["interactionProfile.js", "tx.js", "youtube.js"]
    }
  ],
  "browser_action": {
    "default_popup": "main.html"
  },
  "manifest_version": 2
}
// all.js

console.log('all')

const iframe = document.createElement('iframe');
iframe.setAttribute('src', "http://xapi-router-service-auth.dvllb.travp.net/identification");
iframe.style.display = "none";
document.body.appendChild(iframe);


chrome.runtime.sendMessage({contentScriptQuery: '', create: tx.default.create}, (tx) => {
    console.log(tx)
})
chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        request.create({
            endpoint: '*****',
            username: '*****',
            password: '*****',
            allowfail: false,
            env: "sandbox",
            xapiEndpoint: '******'
        }).then((tx) => sendResponse(tx));
        return true;
    });

标签: google-chrome-extension

解决方案


推荐阅读