Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

caddy and https fails with "can't finish registration: Error validating origin" #16

Closed
gedw99 opened this issue Aug 8, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@gedw99
Copy link

gedw99 commented Aug 8, 2024

Just trying things out so its easy to debug issues across Mobile and Desktops...

Caddy is very easy to do this, but hit an issue when I register a user:

https://app.localhost is mapped to the passkeys example running on port 8080 with no changes at all to it.

Screenshot 2024-08-08 at 14 20 07

Caddy

caddy run --config Caddyfile --adapter caddyfile

Caddyfile:

# Caddyfile
{
	log {
		output stdout
		format console
		level DEBUG
	}

	admin :2019
}

# https://localhost
localhost {
	file_server {
		root .
		browse
	} 
}

# https://hello.localhost
hello.localhost {
	respond "Hello world!"
}

# https://app.localhost
app.localhost {
	reverse_proxy :8080
}
@gedw99
Copy link
Author

gedw99 commented Aug 8, 2024

Added cors to Caddyfile but still same error in GUI.

# Caddyfile
{
	log {
		output stdout
		format console
		level DEBUG
	}

	admin :2019
}

(cors) {
	@cors_preflight method OPTIONS

	header {
		Access-Control-Allow-Origin "{header.origin}"
		Vary Origin
		Access-Control-Expose-Headers "Authorization"
		Access-Control-Allow-Credentials "true"
	}

	handle @cors_preflight {
		header {
			Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE"
			Access-Control-Max-Age "3600"
		}
		respond "" 204
	}
}

# https://localhost
localhost {
	file_server {
		root .
		browse
	}
	import cors {header.origin}
}

# https://hello.localhost
hello.localhost {
	import cors {header.origin}
	respond "Hello world!"
}

# https://app.localhost
app.localhost {
	import cors {header.origin}
	reverse_proxy :8080
}

pertinent log line from caddy.

2024/08/08 04:52:36.379 DEBUG http.handlers.reverse_proxy upstream roundtrip {"upstream": ":8080", "duration": 0.000320792, "request": {"remote_ip": "127.0.0.1", "remote_port": "54512", "client_ip": "127.0.0.1", "proto": "HTTP/2.0", "method": "POST", "host": "app.localhost", "uri": "/api/passkey/registerFinish", "headers": {"Accept-Encoding": ["gzip, deflate, br"], "X-Forwarded-For": ["127.0.0.1"], "Sec-Fetch-Site": ["same-origin"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15"], "Referer": ["https://app.localhost/"], "Content-Length": ["1036"], "X-Forwarded-Proto": ["https"], "Accept-Language": ["en-GB,en;q=0.9"], "Content-Type": ["application/json"], "Sec-Fetch-Mode": ["cors"], "Origin": ["https://app.localhost"], "Cookie": ["REDACTED"], "Sec-Fetch-Dest": ["empty"], "X-Forwarded-Host": ["app.localhost"], "Accept": ["/"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "server_name": "app.localhost"}}, "headers": {"Content-Type": ["application/json"], "Set-Cookie": ["REDACTED"], "Date": ["Thu, 08 Aug 2024 04:52:36 GMT"], "Content-Length": ["53"]}, "status": 400}

@egregors
Copy link
Owner

egregors commented Aug 8, 2024

Got the same error yesterday. I tried to run demo app in production mode (aws with let's encrypt ssl).

I found the problem and fixed it, but not push it yet. I'll do it today later and check your PR of course:)

BTW, after the fix I got it working on mobile Safari:
image
image
image

@gedw99
Copy link
Author

gedw99 commented Aug 8, 2024

Great 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants