MCPcopy Create free account
hub / github.com/gogs/gogs / HTTP

Function HTTP

internal/route/repo/http.go:415–467  ·  view source on GitHub ↗
(c *HTTPContext)

Source from the content-addressed store, hash-verified

413}
414
415func HTTP(c *HTTPContext) {
416 for _, route := range routes {
417 reqPath := strings.ToLower(c.Req.URL.Path)
418 m := route.re.FindStringSubmatch(reqPath)
419 if m == nil {
420 continue
421 }
422
423 // We perform check here because route matched in cmd/web.go is wider than needed,
424 // but we only want to output this message only if user is really trying to access
425 // Git HTTP endpoints.
426 if conf.Repository.DisableHTTPGit {
427 c.Error(http.StatusForbidden, "Interacting with repositories by HTTP protocol is disabled")
428 return
429 }
430
431 if route.method != c.Req.Method {
432 c.Error(http.StatusNotFound)
433 return
434 }
435
436 // 🚨 SECURITY: Prevent path traversal.
437 cleaned := pathutil.Clean(m[1])
438 if m[1] != "/"+cleaned {
439 c.Error(http.StatusBadRequest, "Request path contains suspicious characters")
440 return
441 }
442
443 file := strings.TrimPrefix(reqPath, cleaned)
444 dir, err := getGitRepoPath(cleaned)
445 if err != nil {
446 log.Warn("HTTP.getGitRepoPath: %v", err)
447 c.Error(http.StatusNotFound)
448 return
449 }
450
451 route.handler(serviceHandler{
452 w: c.Resp,
453 r: c.Req.Request,
454 dir: dir,
455 file: file,
456
457 authUser: c.AuthUser,
458 ownerName: c.OwnerName,
459 ownerSalt: c.OwnerSalt,
460 repoID: c.RepoID,
461 repoName: c.RepoName,
462 })
463 return
464 }
465
466 c.Error(http.StatusNotFound)
467}

Callers

nothing calls this directly

Calls 4

CleanFunction · 0.92
getGitRepoPathFunction · 0.85
FindStringSubmatchMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected