Fix: use safeDecode while decoding account & issuer

This commit is contained in:
Neeraj Gupta 2023-08-10 11:59:19 +05:30
parent 32e74929ce
commit 81fcbac0ec
3 changed files with 13 additions and 11 deletions

View file

@ -23,12 +23,12 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
void initState() {
_issuerController = TextEditingController(
text: widget.code != null
? Uri.decodeFull(widget.code!.issuer).trim()
? safeDecode(widget.code!.issuer).trim()
: null,
);
_accountController = TextEditingController(
text: widget.code != null
? Uri.decodeFull(widget.code!.account).trim()
? safeDecode(widget.code!.account).trim()
: null,
);
_secretController = TextEditingController(

View file

@ -306,15 +306,6 @@ class _CodeWidgetState extends State<CodeWidget> {
);
}
String safeDecode(String value) {
try {
return Uri.decodeComponent(value);
} catch (e) {
// note: don't log the value, it might contain sensitive information
logger.severe("Failed to decode", e);
return value;
}
}
String _getCurrentOTP() {
try {

View file

@ -1,4 +1,5 @@
import 'package:ente_auth/models/code.dart';
import 'package:flutter/foundation.dart';
import 'package:otp/otp.dart' as otp;
String getOTP(Code code) {
@ -50,3 +51,13 @@ otp.Algorithm _getAlgorithm(Code code) {
String getSanitizedSecret(String secret) {
return secret.toUpperCase().trim().replaceAll(' ', '');
}
String safeDecode(String value) {
try {
return Uri.decodeComponent(value);
} catch (e) {
// note: don't log the value, it might contain sensitive information
debugPrint("Failed to decode $e");
return value;
}
}