Skip to content

Commit 4b56c05

Browse files
Gusted0ko
authored andcommitted
fix: validate input for default_{merge,update}_style (go-gitea#7395)
- Add `binding:"In(...)"` to the `default_merge_style` and `default_update_style` fields to only accept recognized merge and update styles. - Resolves https://codeberg.org/forgejo/forgejo/issues/7389 - Added integration test for the API (`binding` works in the exact same way for the API and web routes). Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7395 Reviewed-by: 0ko <[email protected]> Co-authored-by: Gusted <[email protected]> Co-committed-by: Gusted <[email protected]>
1 parent 114cd6d commit 4b56c05

File tree

5 files changed

+266
-234
lines changed

5 files changed

+266
-234
lines changed

modules/structs/repo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ type EditRepoOption struct {
224224
AllowRebaseUpdate *bool `json:"allow_rebase_update,omitempty"`
225225
// set to `true` to delete pr branch after merge by default
226226
DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
227-
// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", "squash", or "fast-forward-only".
228-
DefaultMergeStyle *string `json:"default_merge_style,omitempty"`
227+
// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", "squash", "fast-forward-only", "manually-merged", or "rebase-update-only".
228+
DefaultMergeStyle *string `json:"default_merge_style,omitempty" binding:"In(merge,rebase,rebase-merge,squash,fast-forward-only,manually-merged,rebase-update-only)"`
229229
// set to a update style to be used by this repository: "rebase" or "merge"
230-
DefaultUpdateStyle *string `json:"default_update_style,omitempty"`
230+
DefaultUpdateStyle *string `json:"default_update_style,omitempty" binding:"In(merge,rebase)"`
231231
// set to `true` to allow edits from maintainers by default
232232
DefaultAllowMaintainerEdit *bool `json:"default_allow_maintainer_edit,omitempty"`
233233
// set to `true` to archive this repository.

routers/web/repo/setting/setting.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func Units(ctx *context.Context) {
105105

106106
func UnitsPost(ctx *context.Context) {
107107
form := web.GetForm(ctx).(*forms.RepoUnitSettingForm)
108+
if ctx.HasError() {
109+
ctx.Redirect(ctx.Repo.Repository.Link() + "/settings/units")
110+
return
111+
}
108112

109113
repo := ctx.Repo.Repository
110114

services/forms/repo_form.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ type RepoUnitSettingForm struct {
188188
PullsAllowSquash bool
189189
PullsAllowFastForwardOnly bool
190190
PullsAllowManualMerge bool
191-
PullsDefaultMergeStyle string
192-
PullsDefaultUpdateStyle string
191+
PullsDefaultMergeStyle string `binding:"In(merge,rebase,rebase-merge,squash,fast-forward-only,manually-merged,rebase-update-only)"`
192+
PullsDefaultUpdateStyle string `binding:"In(merge,rebase)"`
193193
EnableAutodetectManualMerge bool
194194
PullsAllowRebaseUpdate bool
195195
DefaultDeleteBranchAfterMerge bool

templates/swagger/v1_json.tmpl

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)