添加严格的域名访问限制
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { type ActionFunctionArgs, json } from "@remix-run/node";
|
||||
import { OAuthClient } from "~/api/login/oauth-client";
|
||||
import { OAUTH_CONFIG } from "~/config/api-config";
|
||||
import { validateRequest, logSecurityEvent } from "~/middleware/host-validation";
|
||||
|
||||
/**
|
||||
* 这个Action作为获取OAuth Access Token的服务器端代理。
|
||||
@@ -8,7 +9,15 @@ import { OAUTH_CONFIG } from "~/config/api-config";
|
||||
* 以避免在网络策略限制服务器直接访问外部服务时出现问题。
|
||||
*/
|
||||
export async function action({ request }: ActionFunctionArgs) {
|
||||
// 1. 只允许POST请求
|
||||
// 1. Host头验证
|
||||
const hostValidation = validateRequest(request);
|
||||
if (!hostValidation.valid) {
|
||||
logSecurityEvent('host_validation_failed', hostValidation.error || 'Unknown validation error', request);
|
||||
console.error('❌ OAuth Token API Host验证失败:', hostValidation.error);
|
||||
return json({ success: false, error: "Forbidden: Invalid Host header" }, { status: 403 });
|
||||
}
|
||||
|
||||
// 2. 只允许POST请求
|
||||
if (request.method !== "POST") {
|
||||
return json({ success: false, error: "Method Not Allowed" }, { status: 405 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user