Skip to content

Commit 6dc6926

Browse files
authored
Merge pull request #306 from Bwko/Security
Fixes xss, clickjacking & password autocompletion
2 parents 6519718 + 1e9730a commit 6dc6926

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

modules/context/context.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package context
66

77
import (
88
"fmt"
9+
"html"
910
"html/template"
1011
"io"
1112
"net/http"
@@ -186,8 +187,10 @@ func Contexter() macaron.Handler {
186187
}
187188
}
188189

189-
ctx.Data["CsrfToken"] = x.GetToken()
190-
ctx.Data["CsrfTokenHtml"] = template.HTML(`<input type="hidden" name="_csrf" value="` + x.GetToken() + `">`)
190+
ctx.Resp.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)
191+
192+
ctx.Data["CsrfToken"] = html.EscapeString(x.GetToken())
193+
ctx.Data["CsrfTokenHtml"] = template.HTML(`<input type="hidden" name="_csrf" value="` + ctx.Data["CsrfToken"].(string) + `">`)
191194
log.Debug("Session ID: %s", sess.ID())
192195
log.Debug("CSRF Token: %v", ctx.Data["CsrfToken"])
193196

templates/user/auth/reset_passwd.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{{if .IsResetForm}}
1414
<div class="required inline field {{if .Err_Password}}error{{end}}">
1515
<label for="password">{{.i18n.Tr "password"}}</label>
16-
<input id="password" name="password" type="password" value="{{.password}}" autofocus required>
16+
<input id="password" name="password" type="password" value="{{.password}}" autocomplete="off" autofocus required>
1717
</div>
1818
<div class="ui divider"></div>
1919
<div class="inline field">

templates/user/auth/signin.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616
<div class="required inline field {{if .Err_Password}}error{{end}}">
1717
<label for="password">{{.i18n.Tr "password"}}</label>
18-
<input id="password" name="password" type="password" value="{{.password}}" required>
18+
<input id="password" name="password" type="password" value="{{.password}}" autocomplete="off" required>
1919
</div>
2020
<div class="inline field">
2121
<label></label>

templates/user/auth/signup.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
</div>
2323
<div class="required inline field {{if .Err_Password}}error{{end}}">
2424
<label for="password">{{.i18n.Tr "password"}}</label>
25-
<input id="password" name="password" type="password" value="{{.password}}" required>
25+
<input id="password" name="password" type="password" value="{{.password}}" autocomplete="off" required>
2626
</div>
2727
<div class="required inline field {{if .Err_Password}}error{{end}}">
2828
<label for="retype">{{.i18n.Tr "re_type"}}</label>
29-
<input id="retype" name="retype" type="password" value="{{.retype}}" required>
29+
<input id="retype" name="retype" type="password" value="{{.retype}}" autocomplete="off" required>
3030
</div>
3131
{{if .EnableCaptcha}}
3232
<div class="inline field">

templates/user/settings/password.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
{{.CsrfTokenHtml}}
1515
<div class="required field {{if .Err_OldPassword}}error{{end}}">
1616
<label for="old_password">{{.i18n.Tr "settings.old_password"}}</label>
17-
<input id="old_password" name="old_password" type="password" autofocus required>
17+
<input id="old_password" name="old_password" type="password" autocomplete="off" autofocus required>
1818
</div>
1919
<div class="required field {{if .Err_Password}}error{{end}}">
2020
<label for="password">{{.i18n.Tr "settings.new_password"}}</label>
21-
<input id="password" name="password" type="password" required>
21+
<input id="password" name="password" type="password" autocomplete="off" required>
2222
</div>
2323
<div class="required field {{if .Err_Password}}error{{end}}">
2424
<label for="retype">{{.i18n.Tr "settings.retype_new_password"}}</label>
25-
<input id="retype" name="retype" type="password" required>
25+
<input id="retype" name="retype" type="password" autocomplete="off" required>
2626
</div>
2727

2828
<div class="field">
@@ -33,7 +33,7 @@
3333
<div class="ui info message">
3434
<p class="text left">{{$.i18n.Tr "settings.password_change_disabled"}}</p>
3535
</div>
36-
{{end}}
36+
{{end}}
3737
</div>
3838
</div>
3939
</div>

0 commit comments

Comments
 (0)