mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: rollback simplewebauthn
This commit is contained in:
6 files changed
+21
-10
No files matched your search
@@ -280,12 +280,17 @@ class HomeSecurityHandler extends Handler {
|
||||
this.back();
|
||||
}
|
||||
|
||||
getAuthnHost() {
|
||||
return system.get('authn.host') && this.request.hostname.includes(system.get('authn.host'))
|
||||
? system.get('authn.host') : this.request.hostname;
|
||||
}
|
||||
|
||||
@requireSudo
|
||||
@param('type', Types.Range(['cross-platform', 'platform']))
|
||||
async postRegister(domainId: string, type: 'cross-platform' | 'platform') {
|
||||
const options = await generateRegistrationOptions({
|
||||
const options = generateRegistrationOptions({
|
||||
rpName: system.get('server.name'),
|
||||
rpID: this.request.hostname,
|
||||
rpID: this.getAuthnHost(),
|
||||
userID: this.user._id.toString(),
|
||||
userDisplayName: this.user.uname,
|
||||
userName: `${this.user.uname}(${this.user.mail})`,
|
||||
@@ -310,7 +315,7 @@ class HomeSecurityHandler extends Handler {
|
||||
response: this.args.result,
|
||||
expectedChallenge: this.session.webauthnVerify,
|
||||
expectedOrigin: this.request.headers.origin,
|
||||
expectedRPID: this.request.hostname,
|
||||
expectedRPID: this.getAuthnHost(),
|
||||
}).catch(() => { throw new ValidationError('verify'); });
|
||||
if (!verification.verified) throw new ValidationError('verify');
|
||||
const info = verification.registrationInfo;
|
||||
|
||||
@@ -165,16 +165,22 @@ class UserSudoHandler extends Handler {
|
||||
class UserWebauthnHandler extends Handler {
|
||||
noCheckPermView = true;
|
||||
|
||||
getAuthnHost() {
|
||||
return system.get('authn.host') && this.request.hostname.includes(system.get('authn.host'))
|
||||
? system.get('authn.host') : this.request.hostname;
|
||||
}
|
||||
|
||||
@param('uname', Types.Username, true)
|
||||
async get(domainId: string, uname: string) {
|
||||
const udoc = this.user._id ? this.user : ((await user.getByEmail(domainId, uname)) || await user.getByUname(domainId, uname));
|
||||
if (!udoc._id) throw new UserNotFoundError(uname || 'user');
|
||||
if (!udoc.authn) throw new AuthOperationError('authn', 'disabled');
|
||||
const options = await generateAuthenticationOptions({
|
||||
const options = generateAuthenticationOptions({
|
||||
allowCredentials: udoc._authenticators.map((authenticator) => ({
|
||||
id: authenticator.credentialID.buffer,
|
||||
type: 'public-key',
|
||||
})),
|
||||
rpID: this.getAuthnHost(),
|
||||
userVerification: 'preferred',
|
||||
});
|
||||
await token.add(token.TYPE_WEBAUTHN, 60, { uid: udoc._id }, options.challenge);
|
||||
@@ -195,7 +201,7 @@ class UserWebauthnHandler extends Handler {
|
||||
response: result,
|
||||
expectedChallenge: challenge,
|
||||
expectedOrigin: this.request.headers.origin,
|
||||
expectedRPID: this.request.hostname,
|
||||
expectedRPID: this.getAuthnHost(),
|
||||
authenticator: {
|
||||
...authenticator,
|
||||
credentialID: authenticator.credentialID.buffer,
|
||||
|
||||
Reference in new issue
Block a user