tegola
tegola copied to clipboard
Feature: adds configurable query parameters to tile endpoints
This PR is a successor of https://github.com/go-spatial/tegola/pull/795.
The main differences/features are:
- Avoid SQL injection vulnerability (more on the approach bellow)
- Allow using several types of parameters, not only
int
- Support omitting a query entirely or replacing it with an arbitrary expression in case no parameter is passed
- Go is updated to
1.18.3
A user can define custom parameters on per-map basis like this:
[[maps.params]]
name = "param2"
token = "!PARAM2!"
# only very simply types are suppored: `int`, `string`, `float`, `bool`
type = "int"
# `?` will be replaced with the actual value
# if `sql` is not specified, it is considered to be `?`
sql = "AND ANSWER = ?"
# if the parameter value is missing from the HTTP query, this value will be used
# `default_value` is an optional parameter. If it is not defined, the parameter is considered as required and cliet will get 400 error
default_value = "42"
# instead of `default_value`, `default_sql` can be defined, e.g. to omit a param query entirely:
#default_sql = " "
# defining both `default_value` and `default_sql` is forbidden
When a request is received, a value of QueryParameterValue
is constructed to hold the resulting parameter query (still with ?
) and a value (parsed to the proper type).
Then (params map[string]QueryParameterValue) ReplaceParams(sql string, args *[]interface{}) string
function can be called which replaces parameters with positional arguments (e.g., $1
, $2
) and fills an array with their values. This should prevent SQL injections.