Replies: 2 comments
-
|
Hi @SpraxDev! I'm Dosu and I’m helping the orpc team. The CORSPlugin in oRPC is mainly responsible for setting CORS headers on responses, not for blocking or rejecting requests from disallowed origins. The key options you can configure are: The If you want to strictly block requests from disallowed origins (e.g., for security or API rate limiting), you need to add your own logic—such as a plugin or interceptor that checks the origin and throws an exception if it's not allowed. Example for a strict allowlist: const allowedOrigins = ["http://example.com"];
const corsPlugin = new oRpcPlugins.CORSPlugin({
origin: (origin) => allowedOrigins.includes(origin) ? origin : ""
});
// To strictly block, add a rootInterceptor before CORSPlugin:
const blockDisallowedOrigins = async (opts) => {
const origin = opts.request.headers.origin;
if (!allowedOrigins.includes(origin)) {
throw new Error("Origin not allowed");
}
return opts.next();
};
handlerOptions.plugins = [
{ rootInterceptors: [blockDisallowedOrigins] },
corsPlugin
];This way, you get both the correct CORS headers and strict enforcement. Let me know if you want a more detailed example or have questions about other options! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
I feel stupid ,_, I think my dev setup (Vite or the frontend framework) seem to overwrite the CORS header(s) set by oRPC. My bad. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I was looking at the
CORSPluginforRPCHandlerand had it 'enabled' with default options (plugins: [new oRpcPlugins.CORSPlugin()}).I was looking into configuring it properly now, but the documentation does not explain what the options are for, and even looks like you don't need to configure anything?
I expected the
originoption to act as an allowlist of allowed origins, but it doesn't seem to do anything.When configuring
http://example.comas my origin, and visiting my app athttp://localhost:8080, POST requests still succeed (AAccess-Control-Allow-Originresponse header is sent, with the app's origin instead of the configured one).When instead configuring a method as origin, I can log the origin of the request, but oRPC does not seem to check for it?
Am I expected to throw my own Exception?
Thanks for any advice and Happy New Year 🎇
Beta Was this translation helpful? Give feedback.
All reactions