Skip to content

Commit 9deef2d

Browse files
committed
fix: enforce ISO 8601 validation for date query parameters
- Add validation for 'since' and 'until' parameters to ensure they follow ISO 8601 (RFC3339) format, returning an error if invalid Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 8f82a1f commit 9deef2d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

routers/api/v1/repo/commits.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math"
99
"net/http"
1010
"strconv"
11+
"time"
1112

1213
issues_model "code.gitea.io/gitea/models/issues"
1314
user_model "code.gitea.io/gitea/models/user"
@@ -161,6 +162,20 @@ func GetAllCommits(ctx *context.APIContext) {
161162
since := ctx.FormString("since")
162163
until := ctx.FormString("until")
163164

165+
// Validate since/until as ISO 8601 (RFC3339)
166+
if since != "" {
167+
if _, err := time.Parse(time.RFC3339, since); err != nil {
168+
ctx.APIError(http.StatusUnprocessableEntity, "invalid 'since' format, expected ISO 8601 (RFC3339)")
169+
return
170+
}
171+
}
172+
if until != "" {
173+
if _, err := time.Parse(time.RFC3339, until); err != nil {
174+
ctx.APIError(http.StatusUnprocessableEntity, "invalid 'until' format, expected ISO 8601 (RFC3339)")
175+
return
176+
}
177+
}
178+
164179
if ctx.Repo.Repository.IsEmpty {
165180
ctx.JSON(http.StatusConflict, api.APIError{
166181
Message: "Git Repository is empty.",

0 commit comments

Comments
 (0)