Skip to content

Add validation constraints for repository creation fields#36671

Merged
lunny merged 10 commits intogo-gitea:mainfrom
lunny:lunny/license_size
Feb 25, 2026
Merged

Add validation constraints for repository creation fields#36671
lunny merged 10 commits intogo-gitea:mainfrom
lunny:lunny/license_size

Conversation

@lunny
Copy link
Copy Markdown
Member

@lunny lunny commented Feb 18, 2026

Adds validation constraints to repository creation inputs, enforcing max-length limits for labels/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
Copy Markdown
Member

KN4CK3R commented Feb 18, 2026

Other fields like Gitignores are no problem?

@lunny
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@wxiaoguang wxiaoguang marked this pull request as draft February 20, 2026 06:48
@silverwind
Copy link
Copy Markdown
Member

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

@wxiaoguang
Copy link
Copy Markdown
Contributor

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

#36638 (comment)

@lunny lunny marked this pull request as ready for review February 25, 2026 01:25
@lunny
Copy link
Copy Markdown
Member Author

lunny commented Feb 25, 2026

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

The tests of binding have been added in binding repository. It seems we don't need to have.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 25, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 25, 2026
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 25, 2026
@lunny lunny enabled auto-merge (squash) February 25, 2026 16:03
@lunny lunny merged commit 569c49d into go-gitea:main Feb 25, 2026
26 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Feb 25, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 25, 2026
@wxiaoguang wxiaoguang deleted the lunny/license_size branch February 25, 2026 16:46
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Feb 25, 2026
…6671)

Adds validation constraints to repository creation inputs, enforcing
max-length limits for labels/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 backport/done All backports for this PR have been created label Feb 25, 2026
lunny added a commit that referenced this pull request Feb 25, 2026
…36757)

Backport #36671 by @lunny

Adds validation constraints to repository creation inputs, enforcing
max-length limits for labels/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.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 26, 2026
* giteaofficial/main:
  Fix release draft access check logic (go-gitea#36720)
  Change image transparency grid to CSS (go-gitea#36711)
  Avoid opening new tab when downloading actions logs (go-gitea#36740)
  Add validation constraints for repository creation fields (go-gitea#36671)
  Fix SVG height calculation in diff viewer (go-gitea#36748)
silverwind added a commit to silverwind/gitea that referenced this pull request Feb 26, 2026
* main: (24 commits)
  Instance-wide (global) info banner and maintenance mode (go-gitea#36571)
  Add created_by filter to SearchIssues (go-gitea#36670)
  Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714)
  Fix release draft access check logic (go-gitea#36720)
  Change image transparency grid to CSS (go-gitea#36711)
  Avoid opening new tab when downloading actions logs (go-gitea#36740)
  Add validation constraints for repository creation fields (go-gitea#36671)
  Fix SVG height calculation in diff viewer (go-gitea#36748)
  Fix path resolving (go-gitea#36734)
  [skip ci] Updated translations via Crowdin
  Fix track time list permission check (go-gitea#36662)
  Fix incorrect setting loading order (go-gitea#36735)
  Use case-insensitive matching for Git error "Not a valid object name" (go-gitea#36728)
  feat: Add workflow dependencies visualization (go-gitea#36248)
  Add keyboard shortcuts for repository file and code search (go-gitea#36416)
  Refactor text utility classes to Tailwind CSS (go-gitea#36703)
  Prevent redirect bypasses via backslash-encoded paths (go-gitea#36660)
  Fix force push time-line commit comments of pull request (go-gitea#36653)
  Fix get release draft permission check (go-gitea#36659)
  Move `X_FRAME_OPTIONS` setting from `cors` to `security` section (go-gitea#30256)
  ...

# Conflicts:
#	web_src/css/base.css
#	web_src/css/index.css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/v1.25 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. 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.

6 participants