Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make avatar lookup occur at image request #10540

Merged
merged 17 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Protect against evil email address ".."
  • Loading branch information
zeripath committed Feb 29, 2020
commit bdcf2871b27bbfea05d383d4b4fa27c2f7d540df
2 changes: 1 addition & 1 deletion modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func SizedAvatarLink(email string, size int) string {
// which includes app sub-url as prefix. However, it is possible
// to return full URL if user enables Gravatar-like service.
func AvatarLink(email string) string {
return setting.AppSubURL + "/avatar/" + url.PathEscape(email)
return setting.AppSubURL + "/avatar/email-" + url.PathEscape(email)
}

// FileSize calculates the file size and generate user-friendly string.
Expand Down
2 changes: 1 addition & 1 deletion routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func RegisterRoutes(m *macaron.Macaron) {
})
// ***** END: User *****

m.Get("/avatar/:email", user.AvatarByEmail)
m.Get("/avatar/email-:email", user.AvatarByEmail)

adminReq := context.Toggle(&context.ToggleOptions{SignInRequired: true, AdminRequired: true})

Expand Down
6 changes: 5 additions & 1 deletion routers/user/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package user

import (
"errors"
"strconv"
"strings"

Expand Down Expand Up @@ -46,7 +47,10 @@ func Avatar(ctx *context.Context) {
// AvatarByEmail redirects the browser to the appropriate Avatar link
func AvatarByEmail(ctx *context.Context) {
zeripath marked this conversation as resolved.
Show resolved Hide resolved
email := ctx.Params(":email")

if email == "" {
ctx.ServerError("invalid email address", errors.New("email cannot be empty"))
return
}
size := ctx.QueryInt("size")
if size == 0 {
size = base.DefaultAvatarSize
Expand Down