我有一个运行Laravel 5.8 引擎的domain_A来在web route上返回 API 。它必须检查源以只为几个域提供服务,包括 domain_B。
Barryvdh/laravel-cors
我通过 composer安装了barryvdh/laravel-cors并配置它全局更新 Kernel.php。这也应该适用于网络路由。
内核文件
protected $middleware = [
...
\Barryvdh\Cors\HandleCors::class,
];
Run Code Online (Sandbox Code Playgroud)
然后我使用标准配置作为测试来配置Laravel Cors以允许任何域。
/config/cors.php
return [
'supportsCredentials' => false,
'allowedOrigins' => ['http:www.domain_b.com','https:www.domain_b.com','http:domain_b.com'],
'allowedHeaders' => ['Access-Control-Allow-Origin', 'X-CSRF-TOKEN', 'Content-Type', 'X-Requested-With'],
'allowedMethods' => ['*'], // ex: ['GET', 'POST', 'PUT', 'DELETE']
'exposedHeaders' => [],
'maxAge' => 0,
];
Run Code Online (Sandbox Code Playgroud)
axios 配置是:
(domain_a)/ Repository.js
import axios from 'axios/index';
const baseDomain = "https://domain_a";
const baseURL = `${baseDomain}`;
let withCredentials = …Run Code Online (Sandbox Code Playgroud) 使用桌面浏览器(仅限 Chrome)时,我有一个有效的注册和登录端点,但当尝试使用移动浏览器注册或登录时,服务器超时。我怀疑这是因为我的会话 cookie 和 csurf cookie 没有随我的获取请求一起发送。
我在手机浏览器上打开了Safari开发,它没有显示任何cookie。我现在怀疑这是因为 MaxAge——
请注意,我的 api 和客户端位于不同的域:Heroku 和 Netlify。请参阅下面的代码:
CORS 选项
const options = {
origin: "clientUrl",
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
allowedHeaders: [
"Content-Type",
"Access-Control-Allow-Headers",
"Access-Control-Allow-Origin",
"Authorization",
"csrf-token"
],
exposedHeaders: [
"Content-Type",
"Access-Control-Allow-Headers",
"Access-Control-Allow-Origin",
"Authorization",
"csrf-token"
],
maxAge: 3600,
preflightContinue: true,
credentials: true
};
Run Code Online (Sandbox Code Playgroud)
CSURF配置
app.use(
csurf({
cookie: true,
domain: "clientUrl",
sameSite: "none"
})
);
Run Code Online (Sandbox Code Playgroud)
快速会话配置
app.use(
session({
//This is our Encryption Key
secret: process.env.sessionCode,
//We set resave to false because our mongo store implements the "touch" …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成一个自签名证书,以便我的本地开发环境使用 HTTPS,但我遇到了一些问题。这样做的原因是我想通过我的本地网络(通过我的本地 IP 192.168.1.155)在我的手机上测试推送通知,并且通知只能通过安全上下文工作。
它似乎只在我去的时候工作localhost:8080,并且在导航到时仍然不安全127.0.0.1:8080。当我导航到127.0.0.1:8080Chrome 的安全页面时说:This site is missing a valid, trusted certificate (net::ERR_CERT_COMMON_NAME_INVALID).
这是我用来生成证书的设置:
请求.cnf:
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = VA
L = SomeCity
O = MyCompany
OU = MyDivision
CN = 127.0.0.1
[v3_req]
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = 127.0.0.1
DNS.3 = 192.168.1.155
Run Code Online (Sandbox Code Playgroud)
openssl req -newkey rsa:2048 -x509 …
我想通过不允许我的页面上的任何内容向托管页面的域以外的其他域发送 XHR/XMLHttpRequest(或其他?)请求,在管理上阻止一整类 XSS 攻击。那可能吗?
我以为我可以通过跨域资源共享 (CORS)做到这一点,但似乎我错了。如果托管在 domain-a.com 上的页面尝试向 domain-b.com 发出 XHR 请求,则可以在 domain-b.com页面上使用 CORS来控制是否允许这样做。
因此,如果 domain-a.com 页面上的某些内容尝试向hackers-r-us.com 发出XHR 请求,该请求将被允许,只要hackers-r-us.com 设置了适当的CORS 标头。
但是,无论hackers-r-us.com 上的CORS 标头如何,我是否可以在domain-a.com 的页面上设置任何内容来禁止对其他域(例如hackers-r-us.com)的请求?
Chrome 计划于2020 年 6 月弃用并冻结其User-Agent标头。 User-Agent在调试日志中的某些错误时非常有用,因为许多浏览器根据版本的不同而有不同的怪癖。User-Agent已被弃用,取而代之的是Accept-CH和Sec-CH-UA-*。
我需要在Accept-CH中输入哪些值才能使浏览器响应以下用户代理信息?附带的Sec-CH-UA-*标头是什么?
我正在创建一个全栈应用程序,后端使用 Ktor (Kotlin) 开发,前端使用 React (TypeScript) 开发。后端托管在 Heroku 上,而前端仍在开发中,因此我在本地运行它。
当使用 Postman 进行测试时,该 API 可以正常运行并按预期工作。这是 Ktor 配置的摘录:
@Suppress("unused")
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
install(CORS) {
anyHost()
}
install(StatusPages) {
// Status pages configuration
}
install(ContentNegotiation) {
jackson {
enable(SerializationFeature.INDENT_OUTPUT)
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES)
}
}
routing {
// Declaration of routes
}
}
Run Code Online (Sandbox Code Playgroud)
我启用了 CORS,允许每个主机访问资源。
在 React 应用程序中,我使用它axios作为我的 HTTP 库。这是向服务器发出请求的示例:
interface LoginModel {
email: string;
password: string;
}
interface TokenAuthModel {
successful: boolean;
access_token: string;
}
import * as …Run Code Online (Sandbox Code Playgroud) 我正在对我的数据集进行分析,示例数据框 df:
DOY species replicate position SLA PAR temp A1200 susPQ susNPQ FvFm
1: 46 LINGONBERRY 1 LOW 65.75638 19.70906 -2.850833 0.569690 2.147297 0.9321771 0.5263661 562.1016 0.011440 28.02628
2: 46 LINGONBERRY 2 LOW 59.45028 19.78096 -2.850833 0.893840 2.511543 1.0516496 0.5503916 533.6136 0.028930 25.40703
3: 46 LINGONBERRY 3 LOW 59.51058 17.52833 -2.850833 0.731765 2.278927 1.0678274 0.5242824 549.6316 0.020185 46.16188
4: 46 PINE 1 LOW 35.90156 20.85151 -2.850833 1.518910 2.319431 2.2168853 0.4189484 392.6067 0.059280 47.79101
5: 46 PINE 1 TOP 27.29495 90.27197 …Run Code Online (Sandbox Code Playgroud) 星期五我有一个工作开发环境。星期一我有一个坏了。我在 Chrome 开发工具控制台中为我的所有资产遇到了此错误消息:
从源“http://example.com”访问“http://localhost:8080/build/app.css”的 CSS 样式表已被 CORS 策略阻止:请求客户端不是安全上下文,资源是在更私密的地址空间
local。
有什么快速解决办法吗?我尝试在我的 webpackdevServer.headers配置中设置 access-control-allow-origin无济于事:
config.devServer.headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
}
Run Code Online (Sandbox Code Playgroud) google-chrome localhost cors private-network private-network-access
我必须编写一段代码,通过米勒-拉宾素性测试确定一个数字是否为素数。
\n代码在这里:
\n#include <iostream>\n#include <time.h>\n#include <cmath>\n#include <stdio.h> \n\nusing namespace std;\n\nint main()\n{\n srand(time(0));\n int m, r, st, a, x, t,st2;\n cout << "\xd0\x92\xd0\xb2\xd0\xb5\xd0\xb4\xd0\xb8\xd1\x82\xd0\xb5 \xd1\x87\xd0\xb8\xd1\x81\xd0\xbb\xd0\xbe m: ";\n cin >> m;\n cout << "\xd0\x92\xd0\xb2\xd0\xb5\xd0\xb4\xd0\xb8\xd1\x82\xd0\xb5 \xd1\x87\xd0\xb8\xd1\x81\xd0\xbb\xd0\xbe r: ";\n cin >> r;\n t = m - 1;\n st = 0;\n\n while (t % 2 == 0)\n {\n st = st + 1;\n t = t / 2;\n }\n\n for (int i = 0; i < r; i++)\n {\n a = rand() % (m …Run Code Online (Sandbox Code Playgroud) 我有这个功能:
pub async fn player(&self, id: &str) -> Result<Option<Box<dyn AsyncRead + Send>>> {
// use id here...
let file = tokio::fs::File::open("player.pdf").await?;
let res = Some(Box::new(file));
Ok(res)
}
Run Code Online (Sandbox Code Playgroud)
它不起作用:
error[E0308]: mismatched types
|
46 | Ok(res)
| -- ^^^ expected trait object `dyn tokio::io::AsyncRead`, found struct `tokio::fs::File`
| |
| arguments to this enum variant are incorrect
|
= note: expected enum `std::option::Option<std::boxed::Box<dyn tokio::io::AsyncRead + std::marker::Send>>`
found enum `std::option::Option<std::boxed::Box<tokio::fs::File>>`
note: tuple variant defined here
--> C:\Users\Fred\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\result.rs:508:5
|
508 | Ok(#[stable(feature = …Run Code Online (Sandbox Code Playgroud) cors ×3
axios ×2
csrf ×2
browser ×1
c++ ×1
client-hints ×1
cookies ×1
correlation ×1
cross-domain ×1
express ×1
http-headers ×1
https ×1
javascript ×1
kotlin ×1
ktor ×1
laravel ×1
largenumber ×1
lm ×1
localhost ×1
node.js ×1
openssl ×1
primes ×1
r ×1
reactjs ×1
rust ×1
ssl ×1
user-agent ×1
vue.js ×1
xss ×1