Skip to content

Commit 036fb78

Browse files
zeripathdelvhsilverwind
authored
Clean up WebAuthn javascript code and remove JQuery code (#22697)
There were several issues with the WebAuthn registration and testing code and the style was very old javascript with jquery callbacks. This PR uses async and fetch to replace the JQuery code. Ref #22651 Signed-off-by: Andrew Thornton <art27@cantab.net> --------- Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: silverwind <me@silverwind.io>
1 parent c09f747 commit 036fb78

File tree

9 files changed

+191
-164
lines changed

9 files changed

+191
-164
lines changed

routers/web/user/setting/security/webauthn.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package security
66
import (
77
"errors"
88
"net/http"
9+
"strconv"
10+
"time"
911

1012
"code.gitea.io/gitea/models/auth"
1113
wa "code.gitea.io/gitea/modules/auth/webauthn"
@@ -23,8 +25,8 @@ import (
2325
func WebAuthnRegister(ctx *context.Context) {
2426
form := web.GetForm(ctx).(*forms.WebauthnRegistrationForm)
2527
if form.Name == "" {
26-
ctx.Error(http.StatusConflict)
27-
return
28+
// Set name to the hexadecimal of the current time
29+
form.Name = strconv.FormatInt(time.Now().UnixNano(), 16)
2830
}
2931

3032
cred, err := auth.GetWebAuthnCredentialByName(ctx.Doer.ID, form.Name)

templates/user/auth/webauthn.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<h3 class="ui top attached header">
66
{{.locale.Tr "twofa"}}
77
</h3>
8+
{{template "user/auth/webauthn_error" .}}
89
<div class="ui attached segment">
910
{{svg "octicon-key" 56}}
1011
<h3>{{.locale.Tr "webauthn_insert_key"}}</h3>
@@ -18,5 +19,4 @@
1819
</div>
1920
</div>
2021
</div>
21-
{{template "user/auth/webauthn_error" .}}
2222
{{template "base/footer" .}}
+11-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
<div class="ui small modal" id="webauthn-error">
2-
<div class="header">{{.locale.Tr "webauthn_error"}}</div>
3-
<div class="content">
4-
<div class="ui negative message">
5-
<div class="header">
6-
{{.locale.Tr "webauthn_error"}}
7-
</div>
8-
<div class="gt-hidden" data-webauthn-error-msg="browser"><p>{{.locale.Tr "webauthn_unsupported_browser"}}</div>
9-
<div class="gt-hidden" data-webauthn-error-msg="unknown"><p>{{.locale.Tr "webauthn_error_unknown"}}</div>
10-
<div class="gt-hidden" data-webauthn-error-msg="insecure"><p>{{.locale.Tr "webauthn_error_insecure"}}</div>
11-
<div class="gt-hidden" data-webauthn-error-msg="unable-to-process"><p>{{.locale.Tr "webauthn_error_unable_to_process"}}</div>
12-
<div class="gt-hidden" data-webauthn-error-msg="duplicated"><p>{{.locale.Tr "webauthn_error_duplicated"}}</div>
13-
<div class="gt-hidden" data-webauthn-error-msg="empty"><p>{{.locale.Tr "webauthn_error_empty"}}</div>
14-
<div class="gt-hidden" data-webauthn-error-msg="timeout"><p>{{.locale.Tr "webauthn_error_timeout"}}</div>
15-
<div class="gt-hidden" data-webauthn-error-msg="general"></div>
16-
</div>
17-
</div>
18-
<div class="actions">
19-
<button onclick="window.location.reload()" class="success ui button gt-hidden webauthn_error_timeout">{{.locale.Tr "webauthn_reload"}}</button>
20-
<button class="ui cancel button">{{.locale.Tr "cancel"}}</button>
1+
<div id="webauthn-error" class="ui small gt-hidden">
2+
<div class="content ui negative message gt-df gt-fc gt-gap-3">
3+
<div class="header">{{.locale.Tr "webauthn_error"}}</div>
4+
<div id="webauthn-error-msg"></div>
5+
<div class="gt-hidden" data-webauthn-error-msg="browser">{{.locale.Tr "webauthn_unsupported_browser"}}</div>
6+
<div class="gt-hidden" data-webauthn-error-msg="unknown">{{.locale.Tr "webauthn_error_unknown"}}</div>
7+
<div class="gt-hidden" data-webauthn-error-msg="insecure">{{.locale.Tr "webauthn_error_insecure"}}</div>
8+
<div class="gt-hidden" data-webauthn-error-msg="unable-to-process">{{.locale.Tr "webauthn_error_unable_to_process"}}</div>
9+
<div class="gt-hidden" data-webauthn-error-msg="duplicated">{{.locale.Tr "webauthn_error_duplicated"}}</div>
10+
<div class="gt-hidden" data-webauthn-error-msg="empty">{{.locale.Tr "webauthn_error_empty"}}</div>
11+
<div class="gt-hidden" data-webauthn-error-msg="timeout">{{.locale.Tr "webauthn_error_timeout"}}</div>
2112
</div>
2213
</div>

templates/user/settings/security/webauthn.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
</h4>
44
<div class="ui attached segment">
55
<p>{{.locale.Tr "settings.webauthn_desc" | Str2html}}</p>
6+
{{template "user/auth/webauthn_error" .}}
67
<div class="ui key list">
78
{{range .WebAuthnCredentials}}
89
<div class="item">
@@ -28,7 +29,6 @@
2829
</div>
2930
</div>
3031

31-
{{template "user/auth/webauthn_error" .}}
3232

3333
<div class="ui g-modal-confirm delete modal" id="delete-registration">
3434
<div class="header">

web_src/css/base.css

+22
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,11 @@ a.label,
699699
border: 1px solid var(--color-secondary);
700700
}
701701

702+
.ui.info.message .header,
703+
.ui.blue.message .header {
704+
color: var(--color-blue);
705+
}
706+
702707
.ui.info.message,
703708
.ui.attached.info.message,
704709
.ui.blue.message,
@@ -708,6 +713,12 @@ a.label,
708713
border-color: var(--color-info-border);
709714
}
710715

716+
.ui.success.message .header,
717+
.ui.positive.message .header,
718+
.ui.green.message .header {
719+
color: var(--color-green);
720+
}
721+
711722
.ui.success.message,
712723
.ui.attached.success.message,
713724
.ui.positive.message,
@@ -717,6 +728,12 @@ a.label,
717728
border-color: var(--color-success-border);
718729
}
719730

731+
.ui.error.message .header,
732+
.ui.negative.message .header,
733+
.ui.red.message .header {
734+
color: var(--color-red);
735+
}
736+
720737
.ui.error.message,
721738
.ui.attached.error.message,
722739
.ui.red.message,
@@ -728,6 +745,11 @@ a.label,
728745
border-color: var(--color-error-border);
729746
}
730747

748+
.ui.warning.message .header,
749+
.ui.yellow.message .header {
750+
color: var(--color-yellow);
751+
}
752+
731753
.ui.warning.message,
732754
.ui.attached.warning.message,
733755
.ui.yellow.message,

web_src/css/repo.css

-5
Original file line numberDiff line numberDiff line change
@@ -2405,11 +2405,6 @@
24052405
padding-bottom: 0 !important;
24062406
}
24072407

2408-
.settings .content > .header,
2409-
.settings .content .segment {
2410-
box-shadow: 0 1px 2px 0 var(--color-box-header);
2411-
}
2412-
24132408
.settings.webhooks .list > .item:not(:first-child),
24142409
.settings.githooks .list > .item:not(:first-child),
24152410
.settings.actions .list > .item:not(:first-child) {

0 commit comments

Comments
 (0)