Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Postman (an electron app) get around CORS?

As most people know, Postman is made in Electron. However, it does not run into CORS issues when attempting to make API calls. If a normal user packaged a simple electron app that made API calls using Fetch/XHR however, they will be blocked by endpoints that have a CORS policy. My question is, how does Postman get around this, and is there a setting or flag in Electron that lets my own app do the same? I read here and here that "Postman is a dev tool" but that isn't a in depth response, since Postman is an Electron app that would theoretically be running in Chromium (aka a browser). I'd appreciate anyone who could provide some headway in this topic!

like image 537
erli Avatar asked Jul 16 '19 16:07

erli


People also ask

Does Postman bypass CORS?

Postman simply doesn't care about CORS headers. So CORS is just a browser concept and not a strong security mechanism. It allows you to restrict which other web apps may use your backend resources but that's all.

Does Postman give CORS error?

Install the Postman Desktop Agent for your OS on our download page. Note: The CORS error generally happens due to browser limitations regarding resources shared between different internet domains. Please refer to this blog post for more information about CORS and how the Postman Desktop Agent works.

How do I resolve invalid CORS request in Postman?

Go to https://www.getpostman.com/docs/capture in your chrome browser. Click on interceptor extension and then choose add to chrome. Once it is added there is a new icon top right of both the browser and postman that looks like a traffic light. In postman click this and it turns green.

What is Postman written in?

The Postman Sandbox is a JavaScript execution environment that's available to you while writing pre-request and test scripts for requests (both in Postman and Newman).


2 Answers

Do not forget that electron is not just Chromium, but also packages a Node. Which can also make HTTP requests. Without any Same Origin Policy, hence no CORS limitation.

I suspect Postman actually performs the HTTP request from its Node part (main process).

like image 73
ghybs Avatar answered Oct 11 '22 23:10

ghybs


You can disable web security on Electron (Chromium). That will enable you to get around CORS.

https://stackoverflow.com/a/55741491/3947422 https://github.com/electron/electron/issues/23664#issuecomment-631674094

like image 41
Ashish Avatar answered Oct 12 '22 01:10

Ashish