我正在从 X-Frame-Options 迁移到内容安全策略以修复点击劫持漏洞。我的应用程序曾经SAMEORIGIN在 hteX-Frame-Options标头中设置策略。中的等效选项是Content-Security-Policy什么?
我正在从我的客户端向 google oauth 2 API'https://accounts.google.com/o/oauth2/auth?redirect_uri=http://blah.com&response_type=token&client_id....'进行ajax 调用以获取访问令牌,但出现以下错误:
对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问来源 ' http://blah-blah.com '
我希望调用是 ajax,以便在调用时不会打扰用户,url或者window.location.href换句话说,我如何获取访问令牌以使整个页面不加载,并且是否可以解决上述问题错误???
根据我的理解,使用CORS模块将从Access-Control-Allow-Origin资源中删除标头,导致XmlHttp请求从浏览器失败.
但是,这是否会阻止来自CURL或其他本机应用程序/ Web服务器的Http请求(即通过PHP编写并运行的请求)成功从该资源检索数据?
我正在尝试编写一个拦截器,以使用Angular向所有HTTP请求添加令牌。我大致使用这里给出的食谱-https: //thinkster.io/interceptors
因此代码使用http模块工厂和一个tokenInterceptor()函数。我可以成功地将令牌添加为请求的标头-但是现在,当令牌通过拦截器时,它会被某种CORS阻止机制阻止。我在Chrome控制台中收到此错误-
XMLHttpRequest无法加载http://127.0.0.1:/。对预检请求的响应未通过访问控制检查:请求的资源上不存在“ Access-Control-Allow-Origin”标头。因此,不允许访问源“ http://127.0.0.1:/ ”。响应的HTTP状态码为403。
我尝试将拦截器如下所示的访问控制允许源标头设置为无效:
config.headers['Access-Control-Allow-Origin'] = '*';
Run Code Online (Sandbox Code Playgroud)
我在网上尝试了一些建议,但没有帮助。要解决与CORS相关的问题,客户端是否需要做任何事情-还是服务器方面的问题?
我正在尝试修复具有 onblur 事件侦听器的代码,该事件侦听器执行 setSelectionRange。我注意到,在 Chrome 上使用此功能时,模糊事件会将光标移动到下一个选项卡索引。然而,在 safari 上,光标保留在同一元素上,并且光标移动到 setSelectionRange 中指定的位置。
问题:
下面是一段 hello world 代码,显示了当我在 Safari 和 Chrome 中按 Tab 键移出某个字段时,光标的行为有何不同:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
function handleBlur() {
event.target.setSelectionRange(1,1)
};
</script>
</head>
<body>
<input value="First Name" onblur="handleBlur()">
<input value="Last Name" onblur="handleBlur()">
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我启用了内容安全策略meteor包meteor/browser-policy-common
现在我从ostrio收到这个错误:与CSP相关的文件
拒绝从'blob:http:// localhost:3000/ef628f55-736b-4b36-a32d-b1056adfaa8c ' 创建一个worker,因为它违反了以下内容安全策略指令:"default- src'self'http :// fonts. googleapis.com https://fonts.googleapis.com http://fonts.gstatic.com https://fonts.gstatic.com http://code.ionicframework.com https://code.ionicframework.com ".请注意,'worker-src'未明确设置,因此'default-src'用作后备.
我的实际browser-policy-common配置看起来像这样
import { BrowserPolicy } from 'meteor/browser-policy-common';
// e.g., BrowserPolicy.content.allowOriginForAll( 's3.amazonaws.com' );
// BrowserPolicy.content.allowFontOrigin("data:");
BrowserPolicy.framing.disallow();
BrowserPolicy.content.disallowInlineScripts();
BrowserPolicy.content.disallowEval();
BrowserPolicy.content.allowInlineStyles();
BrowserPolicy.content.allowFontDataUrl();
const trusted = [
'fonts.googleapis.com',
'fonts.gstatic.com',
'code.ionicframework.com',
];
_.each(trusted, (origin) => {
BrowserPolicy.content.allowOriginForAll(origin);
});
Run Code Online (Sandbox Code Playgroud)
你能告诉我应该更改哪个配置以允许ostrio:文件blob:http:// localhost:3000 / ...工作?
非常感谢!
有谁遇到过Google Chrome和SRI Hash这个问题,它在控制台窗口中不断抛出相同的错误:
无法找到在“诚信”属性的有效消化资源“ https://fonts.googleapis.com/css?family=Indie+Flower ”与计算SHA-256诚信“yxJPuU / cJi0 / 8FoS + agssT / MtC4P3SGuU + JOzbTejqQ ='。资源已被阻止。
我正在从https://report-uri.io/home/sri_hash生成代码,并且还尝试过https://www.srihash.org/
根据这个网站https://glebbahmutov.com/blog/subresource-integrity/,作者有同样的问题,因此添加了多个散列<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Indie+Flower" integrity="sha256-CoGIUDlbZltnYk6u/wQKXOszdOOWImA1XzSERnNzHlc= sha384-vk+perBz0d5g0G+x7+4BxElvHeiaLNX7jegOI63Bg53TxNYaUzLGEsSQ4AmIwVr4 sha512-h+9Z3+9s3jtPJjXU9phAXFQwYYFSYhXlnkPwkuubLFf5kfeXWIRC32YkRdB08xmut/dJG/RjPoiR/r4DAtm3PQ==" crossorigin="anonymous">
TL;DR:网站通过 HTTPS 提供服务,需要通过未加密的通道 (ws:// url) 访问 WebSockets 服务器。浏览器不喜欢这样。
加密 Websocket 是可能的,但不方便 - 没有可以签署证书的可信机构,因此需要为每个客户端手动安装它。我想把它作为最后的手段。
该网站必须通过 HTTPS 提供服务,并且不能降级为 HTTP。
有没有其他方法可以绕过这个限制?我尝试了内容安全策略,但它不起作用。
我的 Django 网站使用 Nginx 托管在 digitalocean ubuntu 16.04 中。
我已经在这里设置了 digitalocean CORS 配置https://www.digitalocean.com/docs/spaces/how-to/cors/我在“来源”中添加了我的域名,检查了“允许的方法”中的所有选项,我唯一没有做的就是在“Alowed Headers”中添加标题,因为我不知道要添加什么。
当我使用 digitalocean Spaces(一种基于并与 Amazon S3 非常相似的服务)作为我的静态和媒体文件存储时。请求的资源错误中不存在“Access-Control-Allow-Origin”标头:
CORS 政策已阻止从来源“ https://kjmg.co ”访问“ https://nyc3.digitaloceanspaces.com/kjmgstorage/kjmgstorage/fonts/fontawesome-webfont.woff2?v=4.7.0 ”上的字体:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' https://kjmg.co '。
我尝试使用 django-cors-headers,但我收到:
502 错误网关 nginx/1.10.3 (Ubuntu)
所以只好卸载了。
有朋友知道吗?非常感谢!
我正在使用 ReactJS 发出放置请求,但是,当我输入错误的电子邮件/密码组合时,即使我试图捕获所有错误并将它们显示在 Chrome 上,我也会将其登录errorDiv:
async connect(event) {
try {
const userObject = {
username: this.state.userName,
password: this.state.password
};
if (!userObject.username || !userObject.password) {
throw Error('The username/password is empty.');
}
let response = await fetch(('someurl.com'), {
method: "PUT",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(userObject)
});
let resJSON = await response.json();
if (!response.ok) {
throw Error(resJSON.message);
}
console.info(resJSON.message);
console.info(resJSON.message.auth_token);
window.location = "/ledger/home";
} catch (e) {
document.getElementById("errorDiv").style.display = 'block';
document.getElementById("errorDiv").innerHTML = e;
}
}Run Code Online (Sandbox Code Playgroud)
javascript ×4
cors ×3
reactjs ×2
ajax ×1
angularjs ×1
asp.net-core ×1
django ×1
encryption ×1
fetch-api ×1
google-api ×1
hash ×1
html-input ×1
http-headers ×1
interceptor ×1
meteor ×1
nginx ×1
oauth ×1
oauth-2.0 ×1
put ×1
safari ×1
security ×1
websocket ×1