google-chrome-extension - 是否可以将自定义身份验证库注入 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;
});
解决方案
推荐阅读
- javascript - Chartjs 不更新数据
- c++ - 在一行中创建和填充非常量特征矩阵?
- fetch - 如何在静态构建的 Nuxt.js SPA 中使用“获取”进行导航和页面重新加载
- python - 如何使用 Slurm/Sbatch 提交/运行多个并行作业?
- javascript - 为什么这个 .every() 方法在这里不起作用?
- java - Mapstruct 没有为 Immutables 生成的可选属性选择重载方法
- java - 如何在运行时在运行时显示文本,同时在 Java 中使用谷歌语音到文本 API 说话
- function - 函数的Modelica和事件生成
- html - sphinx-rtd-theme 中的自定义页脚问题
- elasticsearch - 删除 id 以数字开头的所有文档 Elasticsearch