Sudden CORS errors in Production - azure

I have a webapp, frontend Angular, backend nest.js, deployed on Azure.
This morning it suddenly started throwing CORS errors in both Production and UAT (locally it works fine, I am not trying to make API calls from my local environment). I didn't change any settings, I didn't do any deployments.
Access to XMLHttpRequest at 'https://example-backend-production.azurewebsites.net/graphql/'
from origin 'https://example-production.azurewebsites.net' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
In my request headers I can see this:
Request URL: https://example-backend-production.azurewebsites.net/graphql/
Referrer Policy: strict-origin-when-cross-origin
Is this related to some Azure settings? Where should I add 'Access-Control-Allow-Origin' header? It's been working fine for the last 6 months.

Probably AppService settings might have got changed, go to your AppService and
enable CORS

Related

Getting CORS error when using Passport Azure AD

I have my Express API server as well as the SPA hosted on Heroku. The SPA uses Azure ad authentication using MSAL. The APIs are secured using Passport-azure-ad. Everything was working well in my localhost and the requests made where getting a success response. However on uploading the changes to Heroku I am now getting the CORS error. I have registered the API on Azure AD and exposed the API to my SPA. Any reason why I am still getting the error?
Access to fetch at 'https://myTestApp-server.herokuapp.com/getUsers' from origin 'https://myTestApp.herokuapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
To avoid the CORS error, make sure to add the header like below:
While adding the Allowed origins use * to allow all like below:
Otherwise, add particular origins like below:
Make sure to restart the Api after making the above changes.
Check whether you are using correct version of NodeJs that matches the runtime you’re developing and testing.
Try modifying CORS policy by adding .SetIsOriginAllowed((host)=> true)"
If you are adding header via Nodejs code make use of below command:
res.setHeader('Access-Control-Allow-Origin', '*');
Or
res.setHeader('Access-Control-Allow-Origin',
https://myTestApp-server.herokuapp.com:4200');
For more in detail, please refer below link:
Azure App Service No ‘Access-Control-Allow-Origin’ header is present
No 'Access-Control-Allow-Origin' header is present on the requested resource in angular app
3 Ways to Fix the CORS Error and How the Access-Control-Allow-Origin Header Works

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at XYZ api(Reason: CORS header ‘Access-Control-A

I am getting this error while calling api through React JS.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://xyze.com/login/oauth2 (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
The functionality I want is, when I call a api through React JS it should get redirect to another api (redirection of the api has been taken care at the node js backend). While calling the redirected api I am facing CORS policy issue.
eg.
When I click on log in button below api gets called
axios.get('https://exampleabc.com/oauth')
and at the backend it recognises 'oauth' and redirect to 'https://xyze.com/login/oauth2'.
So here while redirecting to https://xyze.com/login/oauth2 it is giving CORS policy issue.
Note: I have added Access-Control-Allow-Origin’ in the api call and tried adding Proxy in package.json but still facing the issue. Also cannot share the actual API due to security reasons
This is mainly a backend server side issue that you are facing. Check in the Response headers of your pre-flight request what value you are getting in Access-Control-Allow-Origin header and if it is matching with your request origin.
You can allow the origin in the preflight request headers to get through this error.
I got same error while using google OAuth2.0, but opening the login window from the react application worked for me.
you can directly redirect browser using
window.open("URL","_self","","")

How do I send a POST request to an app hidden behind Azure Web Proxy?

I am trying to communicate with an app that is hidden behind an Azure Web Proxy/Active Directory setup.
I have tried the following so far:
Written an app in Ionic (Angular)
Set up Ionic's AuthConnect plugin so I am able to get hold of an access token from AD
Set the access token in an 'Authorization' header which this link appears to suggest
Send POST requests which works fine with any other API, just not the one behind the Web Proxy
Tried to set up IIS CORS module on the server-side. I have attached an image of the current config below.
When I try to send a POST request to the Web Proxy app URL, I get a 403 forbidden error on the preflight request.
I'm getting the error "Access to XMLHttpRequest at 'https://www.testurl.com/test' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
Is anyone able to point me in the right direction please? Any help would be greatly appreciated.
You might be facing CORS (Cross-Origin Resource Sharing) issues. You should try turning off CORS in whichever browser you are using. Also, as the error statement says, “No ‘Access-Control-Allow-Origin’ header is present on the requested resource”, you should check the domain or site from where you are sending a POST request to your web proxy app url and whether CORS is disabled/bypassed for your web proxy resource or not. Try sending a POST request from your domain only, not from outside or another domain with CORS enabled.
Also, might be you are sending a POST request from a ‘http’ web server which doesn’t has an SSL certificate installed, so try installing an SSL certificate on your local host and then send a POST request.
You can also check the app virtual directory permissions for web proxy resource access and correct accessibility as you have received a forbidden 403 error while accessing the web app page.
Please refer below threads for more clarification on your issue: -
Response to preflight request doesn't pass access control check
Access to XMLHttpRequest has been blocked by CORS policy
How does Access-Control-Allow-Origin header work?
Thanking you,

HTTP 1.1 Gateway Timeout 504

I have developed an MERN Application so we have ReactJS as frontend and backend as NodeJS. The Application is working on Heroku server.
But now i am scaling things up and I have moved to AWS. I have deployed the frontend in S3 and using it as Static Web Hosting. I have deployed backend in EC2 instance and it is running on NGINX.
We have few resources required such as Camera to be accessed from the browser so I have added SSL certificates on both ends. In EC2 I have used loadbalancer to add SSL certificate.
Now the issue is when ever i make an API call from frontend to backend i am getting GATEWAY TIMEOUT 504 exception.
Frontend : https://portal.visitplan.in
Backend: https://api.visitplan.in
Can you help us out in resolving this? or is this the right way to deploy the application? Is there any other way?
Ok, first of all, your certificate is invalid, you might wanna check on that.
I might know what is happen even thought you are not providing any code.
You might have deployed the frontend and the backend but you might have forgotten to change the request, however, the only request I can make from the portal is the login and this is the console response:
Access to XMLHttpRequest at 'https://api.visitplan.in/account/login' from origin 'https://portal.visitplan.in' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
You need to add the header Access-Control-Allow-Originas stated here. CORS header 'Access-Control-Allow-Origin' missing
One of those reasons might be the problem.

Azure Application Proxy CORs

Hi I am calling an Azure Application Proxy endpoint (myapp.msappproxy.net) through the browser and am running into a CORs issue. How/where can I configure CORs for the Azure Application Proxy endpoint? I've looked in both the old and new Azure portals.
The error I'm getting is on the OPTIONS preflight request.
XMLHttpRequest cannot load https://myapp.msappproxy.net. Response for
preflight is invalid (redirect)
I realize that you set the access-control headers on the API endpoint, in this case the App Proxy, but I can not find where to do so. Additionally, I must set a custom header in my request, because am using bearer token authentication.
Thanks!
Just had the same issue. I have an Azure Application Proxy. So an internal page is available for externals. But normally the Application Body is set to No. With that setting browsers having huge CORS errors. To fix these CORS problems you have to set the Application Body to Yes. Now the body is correctly set and all browsers are able to show the website without CORS issues.
Also good hints you can find in the Enable link translation section.

Resources