flawiddsouza / Restfox

Offline-First Minimalistic HTTP & Socket Testing Client for the Web & Desktop
https://restfox.dev
MIT License
1.9k stars 96 forks source link

Request failed on local domain because of DNS resolution #119

Open mrt-prodz opened 2 months ago

mrt-prodz commented 2 months ago

Greetings,

I tried to look into past issues and found a couple which unfortunately didn't resolve my current problem.

I have a local server with a self signed certificate let's call it : https://test.local

I use a local DNS server redirecting all my local domains to the proper local servers and everything works fine.

When I attempt to use Restfox on any local domain with a self signed certificate I get the following error :

Error: Request failed

Possible causes for this error:

  1. Given request URL is incorrect or invalid
  2. The server for the url isn't returning a valid response for the created request
  3. The server for the url has an expired or invalid ssl certificate

In Restfox settings I enabled Disable SSL Verification and enabled Switch to Chromium Fetch but it stil won't work either with GET, PUT, POST etc..

If I right click and copy the CURL command, I don't see the -k flag to disable SSL check. If I add it manually the command works fine in the terminal.

Restfox refuse to make request to any local domain with a self-signed certificate even with the proper settings applied.

Thank you.

note: version v0.10.1 (c228d75)

edit: I changed the title to reflect the real issue.

flawiddsouza commented 2 months ago

Hi. You should not enable "Switch to Chromium Fetch" if you want to use "Disable SSL Verification" setting. Switch to Chromium was provided to address an old issue, which should be fixed now. Please try with just "Disable SSL Verification" checked. Let me know if it works.

mrt-prodz commented 2 months ago

Greetings @flawiddsouza ,

I tried with only Disable SSL Verification as well and it was not working. I should have mentioned that in my initial issue. I tried again just to make sure and I have the same Request failed result unfortunately.

Thank you.

mrt-prodz commented 2 months ago

I can confirm it's an issue with the DNS and not self-signed certificate. I tried on another local domain with no certificate and it's not working either.

I opened the console dev tools and there is a getaddrinfo ENOTFOUND error.

Restfox doesn't seem to use local system DNS settings hence the reason I'm unable to reach local domains. All my other tools can reach these domains properly, any idea why this is happening ?

more information : I'm running Restfox from the snap package. Is it snap related ?

flawiddsouza commented 2 months ago

Funny. I was just about to write a reply saying it's not the self signed certificate but most likely an issue with how Restfox does dns resolution. I also don't think Issue is because it's a snap.

I need to reproduce this locally. What dns server are you using locally?

mrt-prodz commented 2 months ago

I'm running dnsmasq locally.

Thank you very much for the quick reply.

edit: Just to make sure, I ran another similar tool to test things and I can confirm it's not related to snap indeed.

flawiddsouza commented 2 months ago

Hi @mrt-prodz I've pushed a fix. Please try this snap and let me know if the issue is fixed.

Download: https://restfox.s3.ap-south-1.amazonaws.com/Restfox_0.10.1_amd64.snap

Install: sudo snap install Restfox_0.10.1_amd64.snap --dangerous

Open Restfox snap

mrt-prodz commented 2 months ago

Greetings @flawiddsouza , I tried your new package v0.10.1 (016ed7f) and I unfortunately still get the same error.

We are running BookStack locally on a server at the following domain name : http://bookstack.local

And the dev tools still reports :

Error: getaddrinfo ENOTFOUND bookstack.local

Thank you

flawiddsouza commented 2 months ago

Heyo, well that's not good news. You can see realtime dns lookup logs from restfox using this command:

snap run --shell restfox -c "tail -f ~/.config/Restfox/logs/main.log "

Run this command in a terminal and trigger a request - see what logs are printed - they might help.

mrt-prodz commented 2 months ago

Here is the log output :

[2024-04-19 14:50:45.573] [info]  lookup bookstack.local
[2024-04-19 14:50:50.583] [error] request failed TypeError: fetch failed
    at fetch
(/snap/restfox/x1/resources/app.asar/node_modules/undici/index.js:109:13)
    at process.processTicksAndRejections
(node:internal/process/task_queues:95:5)
    at async Object.handleSendRequest
(/snap/restfox/x1/resources/app.asar/src/request.js:55:26)
    at async WebContents.<anonymous>
(node:electron/js2c/browser_init:2:78167)

Note :

I tried with http://bookstack.local using only /etc/hosts instead of my DNS server and it's working without any issue.

Seems like the real problem is the DNS resolution with my own DNS server.

flawiddsouza commented 2 months ago

I wonder why nodejs is not able to get the dns records from dnsmasq. It's very bizarre. I only did the /etc/hosts check, which seems to have worked for you as well. This time I'll set up dnsmasq and see what happens.

flawiddsouza commented 2 months ago

By way, can you also try:

curl --verbose http://bookstack.local

Config for it should be not in /etc/hosts when you run this.

I want to see how curl is resolving the dns. It usually shows it at the top when we provide the verbose flag.

mrt-prodz commented 2 months ago

Here is the output :

*   Trying 10.77.10.40:80...
* Connected to bookstack.local (10.77.10.40) port 80 (#0)
 GET / HTTP/1.1
 Host: bookstack.local
 User-Agent: curl/8.0.1
 Accept: */*

< HTTP/1.1 200 OK
< Cache-Control: no-cache, no-store, private
< Content-Security-Policy: frame-ancestors 'self'; frame-src 'self' 
https://*.draw.io https://*.youtube.com https://*.youtube-nocookie.com 
https://*.vimeo.com https://embed.diagrams.net; script-src http: https: 
'nonce-AeWSdduiNhvtsotQpcukeBOc' 'strict-dynamic'; object-src 'self'; 
base-uri 'self'
< Content-Type: text/html; charset=UTF-8
< Date: Fri, 19 Apr 2024 13:56:59 GMT
< Expires: Sun, 12 Jul 2015 19:01:00 GMT
< Server: Caddy
< Server: Apache/2.4.57 (Debian)
< Set-Cookie: XSRF-TOKEN=...[TOKEN]...; expires=Fri, 19-Apr-2024 
15:56:59 GMT; Max-Age=7200; path=/; samesite=lax
< Set-Cookie: bookstack_session=...[SESSION]... expires=Fri, 19-Apr-2024 
15:56:59 GMT; Max-Age=7200; path=/; httponly; samesite=lax
< Vary: Accept-Encoding
< X-Powered-By: PHP/8.3.2
< Transfer-Encoding: chunked
<
<!DOCTYPE html>
...[HTML CONTENT]...
* Connection #0 to host bookstack.local left intact
mrt-prodz commented 2 months ago

Here is the nslookup output :

nslookup bookstack.local
Server:        10.77.10.21
Address:    10.77.10.21#53

Name:    bookstack.local
Address: 10.77.10.40

However I am not sure it will help you unfortunately.

flawiddsouza commented 2 months ago

Just to update here. I'm kinda blocked by not being able to set up dnsmasq correctly. I've tried on two systems but dnsmasq is unable to resolve the mapped entries. Every other dns request resolves through the dnsmasq resolver address without any issues. Just the "address=" entries I add don't get resolved. Not sure what I'm doing wrong. I'll keep you update if I find a way to reproduce this.