Skip to content

Commit

Permalink
feat: added new feature gate for parameterized queries
Browse files Browse the repository at this point in the history
Signed-off-by: Neko Ayaka <[email protected]>
  • Loading branch information
nekomeowww committed Nov 27, 2023
1 parent de9a57f commit e19c45f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion pkg/storage/internalstorage/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ const (
// owner: @cleverhu
// alpha: v0.3.0
AllowRawSQLQuery featuregate.Feature = "AllowRawSQLQuery"

// AllowParameterizedSQLQuery is a feature gate for the apiserver to allow querying by the parameterized SQL
// for better defense against SQL injection.
//
// Use either single whereSQLStatement field, a pair of whereSQLStatement with whereSQLParam, or
// whereSQLStatement with whereSQLJSONParams to pass the SQL it self and parameters.
//
// owner: @nekomeowww
// alpha: v0.8.0
AllowParameterizedSQLQuery featuregate.Feature = "AllowParameterizedSQLQuery"
)

func init() {
Expand All @@ -21,5 +31,6 @@ func init() {
// defaultInternalStorageFeatureGates consists of all known custom internalstorage feature keys.
// To add a new feature, define a key for it above and add it here.
var defaultInternalStorageFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
AllowRawSQLQuery: {Default: false, PreRelease: featuregate.Alpha},
AllowRawSQLQuery: {Default: false, PreRelease: featuregate.Alpha},
AllowParameterizedSQLQuery: {Default: false, PreRelease: featuregate.Alpha},
}
2 changes: 1 addition & 1 deletion pkg/storage/internalstorage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func applyListOptionsToQuery(query *gorm.DB, opts *internal.ListOptions, applyFn
query,
opts.URLQuery,
utilfeature.DefaultMutableFeatureGate.Enabled(AllowRawSQLQuery),
false,
utilfeature.DefaultMutableFeatureGate.Enabled((AllowParameterizedSQLQuery)),
)
if err != nil {
return 0, nil, nil, err
Expand Down

0 comments on commit e19c45f

Please sign in to comment.