1. The problem I’m having:
I’d like to allow only a predefined set of query strings, but strip any other key/values that might be appended to the request.
For example, the upstream application expects to receive one, or a combination of predefined strings:
?format=car
or
?format=car&dag-scope=all
The allowed queries are defined in this expression:
@allowedQueries `
!query({'format': ['car', 'raw', 'ipns-record']})
&& !query({'format': ['car', 'raw', 'ipns-record'], 'dag-scope': ['block', 'entity', 'all']})
`
rewrite @allowedQueries {path}?
This is working fine (only those parameters are sent to the upstream), however using the Caddyfile below, additional queries can be appended to the request which are then sent to the upstream application:
Example: ?format=car&dag-scope=all&this=doesntbelong
In this case, I’d like to only forward the whitelisted strings and remove anything else such as &this=doesntbelong
.
2. Error messages and/or full log output:
N/A
3. Caddy version:
v2.7.6-0.20240401181240-45132c5b24b4 h1:RkqsTV1P0EjpiOyNG6hO4kouGTzawDhi1/L43SnKyoM=
4. How I installed and ran Caddy:
xcaddy build master
a. System environment:
Fedora 37
b. Command:
caddy run
c. Service/unit/compose file:
N/A
d. My complete Caddy config:
{
admin off
auto_https off
local_certs
log {
level INFO
format json
}
}
:8443 {
bind 0.0.0.0
tls internal {
on_demand
}
@allowedQueries `
!query({'format': ['car', 'raw', 'ipns-record']})
&& !query({'format': ['car', 'raw', 'ipns-record'], 'dag-scope': ['block', 'entity', 'all']})
`
rewrite @allowedQueries {path}?
reverse_proxy http://localhost:8080
}