Trigger a webhook on visit

I’m creating a simple CTF (capture-the-flag) exercise and I’d like to know when someone reaches given stage.

Is there a way to trigger a webhook when someone hits given handle { } block? I mean with Caddy only, without a dedicated HTTP app behind it.

It’s a pretty vague question, but the simplest thing to do would be to simply reverse_proxy that endpoint:

reverse_proxy /stage3 https://mywebhook.com

Won’t in that case, the webook response be proxied to the user? I want the user to get the static file content…

I tried this:

	handle /ctf_level_1 {
		root * /srv
		rewrite * /ctf_level_1.html
		file_server
		reverse_proxy /ctf_level_1 https://mywebhook.com
	}

And unfortunately, I’m not seeing anything on the mywebhook access log. I understand that the rewrite + file_server conflicts with the reverse_proxy

Also, I cannot add any path to the webhook - when I tried:

	handle /ctf_level_1 {
		root * /srv
		rewrite * /ctf_level_1.html
		file_server
		reverse_proxy /ctf_level_1 https://mywebhook.com/some_resource
	}

I’m getting:

Error: adapting config using caddyfile: parsing caddyfile tokens for 'handle': /etc/caddy/Caddyfile:27 - Error during parsing: parsing caddyfile tokens for 'reverse_proxy': /etc/caddy/Caddyfile:26 - Error during parsing: for now, URLs for proxy upstreams only support scheme, host, and port components

What do you want the webhook to do exactly? Just make an HTTP request?

Sounds like the most ideal solution would be a very simple custom Caddy module that makes a request and then carries the request through to the next handler.

file_server specifically. You can use rewrite with reverse proxy. But both file server and reverse proxy write the HTTP response, so only the first one will run.

You can’t proxy to a subpath, you have to use rewrite first.

What do you want the webhook to do exactly? Just make an HTTP request?

Yeah, pretty much. Just wanted to notify me that someone has completed some stage of CTF.

Sounds like the most ideal solution would be a very simple custom Caddy module that makes a request and then carries the request through to the next handler.

Huh, given my 0-knowledge of golang, I guess I’ll setup a syslog-ng to monitor the logs and trigger webhooks with it.

Thank you for clarification!

1 Like

reverse_proxy takes only one argument, contrary to what Matt suggested. Try to remove /ctf_level_1 ?

You’re not referencing the actual documentation of the reverse_proxy directive. What you’re referencing is only a getting started guide. The definitive guide of reverse_proxy shows how multiple arguments work.

1 Like

Another option is to use reverse_proxy’s handle_response and ignore the response and write a new one to the client.

handle /ctf_level_1 {
	reverse_proxy /ctf_level_1 https://mywebhook.com {
		handle_response {
			root * /srv
			rewrite * /ctf_level_1.html
			file_server
		}
	}
}
2 Likes

That might work, but I already went the other way. Will make sure to use that approach on the next one, thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.