Skip to content

Comments

Add validation constraints for repository creation fields#36671

Draft
lunny wants to merge 7 commits intogo-gitea:mainfrom
lunny:lunny/license_size
Draft

Add validation constraints for repository creation fields#36671
lunny wants to merge 7 commits intogo-gitea:mainfrom
lunny:lunny/license_size

Conversation

@lunny
Copy link
Member

@lunny lunny commented Feb 18, 2026

Adds validation constraints to repository creation inputs, enforcing max-length limits for labels/gitignores/license/readme and enum validation for trust model and object format. Updates both the API option struct and the web form struct to keep validation consistent.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 18, 2026
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Feb 18, 2026
@KN4CK3R
Copy link
Member

KN4CK3R commented Feb 18, 2026

Other fields like Gitignores are no problem?

@lunny
Copy link
Member Author

lunny commented Feb 18, 2026

Other fields like Gitignores are no problem?

Only the License field among the repository creation parameters is used as a database query/insert parameter.

@lunny
Copy link
Member Author

lunny commented Feb 18, 2026

Other fields like Gitignores are no problem?

These restrictions have been added to enforce stricter validation and prevent potential issues or unnecessary problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds input validation constraints to repository creation form fields and API options, limiting the size of various string fields to prevent potential issues with excessively long input values.

Changes:

  • Added MaxSize validation to License (100), Gitignores (255), IssueLabels (255), Readme (255), and ForkSingleBranch (255) fields
  • Added enum validation with In() to ObjectFormatName (sha1, sha256) and TrustModel (default, collaborator, committer, collaboratorcommitter) fields
  • Applied validation consistently to both web form structs (CreateRepoForm) and API structs (CreateRepoOption)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
services/forms/repo_form.go Added MaxSize and In() validation tags to CreateRepoForm fields for web form validation
modules/structs/repo.go Added MaxSize and In() validation tags to CreateRepoOption fields for API validation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@silverwind
Copy link
Member

Update PR title please to reflect that it's not only license.

@lunny lunny changed the title Limit license name's size Add validation constraints for repository creation fields Feb 19, 2026
@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Feb 19, 2026
ForkSingleBranch string
ObjectFormatName string
ForkSingleBranch string `binding:"MaxSize(255)"`
ObjectFormatName string `binding:"In(sha1,sha256)"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's right

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// enum: default,collaborator,committer,collaboratorcommitter
TrustModel string `json:"trust_model"`
// ObjectFormatName of the underlying git repository
TrustModel string `json:"trust_model" binding:"In(default,collaborator,committer,collaboratorcommitter)"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not right

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wxiaoguang wxiaoguang marked this pull request as draft February 20, 2026 06:48
@silverwind
Copy link
Member

Maybe add some tests to validate the new limits? Tests could be AI-generated.

@wxiaoguang
Copy link
Contributor

Unnecessary tests only slow down the tests. Incorrect tests slow down more.

#36638 (comment)

Template bool `json:"template"`
// Gitignores to use
Gitignores string `json:"gitignores"`
Gitignores string `json:"gitignores" binding:"MaxSize(255)"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure Gitignores should have MaxSize(255)? What wrong will happen if it exceeds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v1.25 lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants