Strange request URLs when running ASP.Net Core Application on Amazon Elastic Beanstalk - asp.net

I have a simple MVC ASP.Net application with a health check. The check is routed using an attribute: [HttpGet("health")]
When running it locally, I browse http://localhost:7000/health and get a successful result back. The logs look like this:
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
[00:00:34.796]: Request starting HTTP/1.1 GET http://localhost:7000/health
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: [00:00:34.796]: Request starting HTTP/1.1 GET http://localhost:7000/health
dbug: Microsoft.AspNetCore.Routing.Tree.TreeRouter[1]
Request successfully matched the route with name '(null)' and template 'health'.
However, once I deploy to Amazon Elastic Beanstalk, none of my normal request work. If I browse http://(myAppName).us-east-2.elasticbeanstalk.com/ these are the logs I get:
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
[23:56:39.079]: Request starting HTTP/1.1 GET http://172.31.27.29//(myAppName).us-east-2.elasticbeanstalk.com/health
[40m[37mdbug[39m[22m[49m: Microsoft.AspNetCore.Builder.RouterMiddleware[1]
Request did not match any routes.
Note how for some reason the request URL gets an IP address stuck in there. No idea where its coming from.

Turns out this was a misconfiguration in AWS. I had set the health check URL with an absolute address, which failed. Then when I tried to health check manually, the load balancer didn't let me through because the AWS health check was failing.
I thought the logs were from my manual check, so I assumed that amazon was adding weird things to my request. But really it was just a misconfigured health check in AWS.

Related

How to diagnose a HTTP request being services by the wrong servlet in Wildfly?

My underlying issue is: A HTTP request gets serviced by the default servlet instead of the one I'm expecting.
Logging gives me information like this during server start
WFLYUT0021: Registered web context: /some/path
and still, curl -i http://localhost/some/path doesn't end up in my servlet, but returns HTTP 302, redirecting to /some/path/, which then gets served by Undertow's DefaultServlet. So how would I diagnose this type of issue?
Is there a way to see all deployed servlets in a Wildfly with their deployment info?
Is the Admin Console any good and if so, how?

How to call http://metadata.ggogle.internal from within web app loaded over https

I have an Angular web app running on Cloud Run (nginx webserver) (more info here) from which I want to get access token from the GCP metadata server. I have tried to make a call to https://metadata.google.internal ( using curl from Cloud Shell) but the connection was rejected. Calls to HTTP are working well.
When I make the call from my app (which is loaded over https) to the metadata server over HTTP - logically I get a mixed content error. When trying to access the metadata server over HTTPS - I am getting error 504 Gateway timeout, I assume due to the reason that the metadata server refuses the calls on HTTPS.
I will really appreciate any idea of how to solve this issue.
The URL endpoint metadata.google.internal is only accessible from inside the instance (Cloud Run). This endpoint is not accessible outside of the instance such as via an HTTP or HTTPS call. A clue is the TLD (Top Level Domain) internal.
If you want to access this endpoint remotely via a web browser, you will need to make a request from the browser to Cloud Run (an endpoint in your code) which then makes the internal request to the metadata server and returns the response to the client.

Swagger UI - TypeError: Failed to fetch - on endpoint request (ASPNET Core API)

When trying to run a request through swagger UI, I receive the following response on Swagger
TypeError: Failed to fetch
After searching around, I found that a possible cause of this error is because of a CORS issue, where the origin is changed in the request (as you can see at this other post here). However, in my case, this is not running through some other proxy, it is hosted on a locally hosted server and that server is not changing any of the headers. I realized this when I tried to allow the API to just accept any CORS headers to test if this was the issue; sadly it was not and the issue persisted.
The API is running on IIS hosted on a server that is hosted locally. The API is running as an application on the default website and is accessed via the following url:
http://servername/application-name/swagger/index.html
Can anyone help with this issue?
After further investigation, I found that when I looked at the requests being sent to the server through the dev tools on the browser, that the URL was being changed from http to https on the request of the endpoint through swagger.
HTTPS, has not been set up on the server and returns a 404 (as seen in the dev tools).
It turns out, that even though the server has not been setup to serve content via HTTPS, the requests where still redirected to HTTPS and this was the reason
app.UseHttpsRedirection();
So, even though swagger was able to be loaded on HTTP, when the request was made to the API, the API responded with a 307 - for redirection and the request was redirected to HTTPS - which in turn returned 404. This 404 response was the cause the TypeError: Failed to fetch
The recommended fix for this is to turn off https redirection (ONLY FOR TESTING PURPOSES) and the other is to enable the server to serve the content correctly over HTTPS, so that when a call is made, it is not redirected, but rather sent straight to the correct API address on HTTPS - which should not return the data correctly, since the server can serve HTTPS content

Rest api returns error 403 while calling from Wordpress but works in postman

I have one server on which Apache and Tomcat both are installed to run my Wordpress and Java application respectively. Both are on same ip address and using same domain https://www.example.com only port number is different.
Wordpress is running on default port while Tomcat is runing on 8443.
A rest api on Tomcat https://www.example.com:8443/myApi.html is working fine from postman, but when calling from wordpress using ajax, it returns error 403 forbidden response.
I am stuck on searching its solution but failed.
Please help me out to solve this issue.
Thanks
You cannot use a different port, even when using the same domain. This breaks the Same origin policy.You can however use JSONP if you have access to both the daemon and the requesting site. If data needs to be returned, then the daemon needs to support a callback query parameter and return it properly formatted.
please see 1) https://stackoverflow.com/a/2099771
https://stackoverflow.com/a/2099784

When service through external host name returns wsdl html instead of the expected response envelope

I have an IIS-hosted, WCF web service deployed on a UAT web server. In IIS, I have site bindings on this same web service--one for internal access (Ex: uat-nodotsinternalonly) and one for external access (Ex: mysvc.uat.mydomain.com).
When I use SoapUI to test against the internal host name (http://uat-nodotsinternalonly/MyService.svc), it calls the service and returns the response envelope as expected.
When I use SoapUI to test against the external host name (https://mysvc.uat.mydomain.com/MyService.svc), it calls the service and returns the WSDL HTML as would be seen in the web browser instead of the response envelope as expected.
We need to expose past our firewall for testing with a vendor. Our external client can browse to our web service using the external host name and receive the WSDL back in their web browser, but when they call it, it fails with a 302 error.
I’m far from an expert on security, but I believe our firewall is handling the security then forwarding over http to the UAT server. The redirect and variations seem as though there’s something to change in how DNS is managed or settings in IIS. Does anyone have suggestions as to how to narrow it down so that the call to the external service will work?
We too had a WCF service that in SoapUI was returning the WSDL HTML instead of the expected response when invoking a method. This was an SSL-enabled service, and the solution in our case was to edit the endpoint URL after creating the request so that it used https instead of http. This is because we found that for some reason it defaults to http even when you initially specify https when creating the request. Here's how to edit the endpoint URL in SoapUI:
In the request window, click the drop-down arrow on the URL.
Select [edit current..]
Change http to https, and then try your request again.
The problem with the client getting a 302 error was because the client was not sending a SOAP request envelope to our web service. The client was just sending XML.

Resources