Skip to content

Commit 2e317d3

Browse files
zeripathlunny
andauthored
Prevent security failure due to bad APP_ID (#18678) (#18682)
Backport #18678 WebAuthn may cause a security exception if the provided APP_ID is not allowed for the current origin. Therefore we should reattempt authentication without the appid extension. Also we should allow [u2f] as-well as [U2F] sections. Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent ce69882 commit 2e317d3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

modules/setting/setting.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,13 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
10221022
UI.CustomEmojisMap[emoji] = ":" + emoji + ":"
10231023
}
10241024

1025-
sec = Cfg.Section("U2F")
1026-
U2F.AppID = sec.Key("APP_ID").MustString(strings.TrimSuffix(AppURL, "/"))
1025+
// FIXME: DEPRECATED to be removed in v1.18.0
1026+
U2F.AppID = strings.TrimSuffix(AppURL, "/")
1027+
if Cfg.Section("U2F").HasKey("APP_ID") {
1028+
U2F.AppID = Cfg.Section("U2F").Key("APP_ID").MustString(strings.TrimSuffix(AppURL, "/"))
1029+
} else if Cfg.Section("u2f").HasKey("APP_ID") {
1030+
U2F.AppID = Cfg.Section("u2f").Key("APP_ID").MustString(strings.TrimSuffix(AppURL, "/"))
1031+
}
10271032
}
10281033

10291034
func parseAuthorizedPrincipalsAllow(values []string) ([]string, bool) {
@@ -1162,7 +1167,6 @@ func MakeManifestData(appName, appURL, absoluteAssetURL string) []byte {
11621167
},
11631168
},
11641169
})
1165-
11661170
if err != nil {
11671171
log.Error("unable to marshal manifest JSON. Error: %v", err)
11681172
return make([]byte, 0)

web_src/js/features/user-auth-webauthn.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ export function initUserAuthWebAuthn() {
2424
.then((credential) => {
2525
verifyAssertion(credential);
2626
}).catch((err) => {
27+
// Try again... without the appid
28+
if (makeAssertionOptions.publicKey.extensions && makeAssertionOptions.publicKey.extensions.appid) {
29+
delete makeAssertionOptions.publicKey.extensions['appid'];
30+
navigator.credentials.get({
31+
publicKey: makeAssertionOptions.publicKey
32+
})
33+
.then((credential) => {
34+
verifyAssertion(credential);
35+
}).catch((err) => {
36+
webAuthnError('general', err.message);
37+
});
38+
return;
39+
}
2740
webAuthnError('general', err.message);
2841
});
2942
}).fail(() => {

0 commit comments

Comments
 (0)