mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-14 12:12:12 +08:00
chore: add Debugging location is "" redirect to "/"
This commit is contained in:
parent
e0d08aba79
commit
c99d328d50
@ -1066,7 +1066,14 @@ func (c *Context) String(code int, format string, values ...any) {
|
||||
}
|
||||
|
||||
// Redirect returns an HTTP redirect to the specific location.
|
||||
// When the 'location' parameter is empty, it poses a potential security risk.
|
||||
// Avoid bringing potential security risks into the production environment.
|
||||
func (c *Context) Redirect(code int, location string) {
|
||||
if IsDebugging() && location == "" {
|
||||
debugPrint(`[WARNING] When the 'location' parameter is empty, it poses a potential security risk. Please input a secure redirection URL to ensure safe operation.`)
|
||||
location = "/"
|
||||
}
|
||||
|
||||
c.Render(-1, render.Redirect{
|
||||
Code: code,
|
||||
Location: location,
|
||||
|
@ -1442,6 +1442,8 @@ Gin allow by default use only one html.Template. Check [a multitemplate render](
|
||||
|
||||
Issuing a HTTP redirect is easy. Both internal and external locations are supported.
|
||||
|
||||
Note: When the location is empty, there is a security risk. Please do not bring it to production
|
||||
|
||||
```go
|
||||
r.GET("/test", func(c *gin.Context) {
|
||||
c.Redirect(http.StatusMovedPermanently, "http://www.google.com/")
|
||||
|
Loading…
x
Reference in New Issue
Block a user