fix enableOTP
handling to match docs: prioritize store, then extension config
This commit is contained in:
@@ -724,7 +724,7 @@ async function handleMessage(settings, message, sendResponse) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "copyOTP":
|
case "copyOTP":
|
||||||
if (settings.enableOTP) {
|
if (helpers.getSetting("enableOTP", message.login, settings, helpers.SettingScope.Store)) {
|
||||||
try {
|
try {
|
||||||
if (!message.login.fields.otp) {
|
if (!message.login.fields.otp) {
|
||||||
throw new Exception("No OTP seed available");
|
throw new Exception("No OTP seed available");
|
||||||
@@ -796,8 +796,8 @@ async function handleMessage(settings, message, sendResponse) {
|
|||||||
|
|
||||||
// copy OTP token after fill
|
// copy OTP token after fill
|
||||||
if (
|
if (
|
||||||
settings.enableOTP &&
|
|
||||||
typeof message.login !== "undefined" &&
|
typeof message.login !== "undefined" &&
|
||||||
|
helpers.getSetting("enableOTP", message.login, settings, helpers.SettingScope.Store) &&
|
||||||
message.login.fields.hasOwnProperty("otp")
|
message.login.fields.hasOwnProperty("otp")
|
||||||
) {
|
) {
|
||||||
copyToClipboard(helpers.makeTOTP(message.login.fields.otp.params));
|
copyToClipboard(helpers.makeTOTP(message.login.fields.otp.params));
|
||||||
@@ -963,7 +963,10 @@ async function parseFields(settings, login) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// preprocess otp
|
// preprocess otp
|
||||||
if (settings.enableOTP && login.fields.hasOwnProperty("otp")) {
|
if (
|
||||||
|
helpers.getSetting("enableOTP", login, settings, helpers.SettingScope.Store) &&
|
||||||
|
login.fields.hasOwnProperty("otp")
|
||||||
|
) {
|
||||||
if (login.fields.otp.match(/^otpauth:\/\/.+/i)) {
|
if (login.fields.otp.match(/^otpauth:\/\/.+/i)) {
|
||||||
// attempt to parse otp data as URI
|
// attempt to parse otp data as URI
|
||||||
try {
|
try {
|
||||||
|
@@ -8,12 +8,20 @@ const hash = require("hash.js");
|
|||||||
const Authenticator = require("otplib").authenticator.Authenticator;
|
const Authenticator = require("otplib").authenticator.Authenticator;
|
||||||
const BrowserpassURL = require("@browserpass/url");
|
const BrowserpassURL = require("@browserpass/url");
|
||||||
|
|
||||||
|
const SettingScope = {
|
||||||
|
// query a setting first from the login, then the store, then globally
|
||||||
|
Login: "login",
|
||||||
|
// query a setting first from the store, then globally
|
||||||
|
Store: "store",
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
prepareLogins,
|
prepareLogins,
|
||||||
filterSortLogins,
|
filterSortLogins,
|
||||||
getSetting,
|
getSetting,
|
||||||
ignoreFiles,
|
ignoreFiles,
|
||||||
makeTOTP,
|
makeTOTP,
|
||||||
|
SettingScope,
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------- Function definitions ----------------------------------//
|
//----------------------------------- Function definitions ----------------------------------//
|
||||||
@@ -24,10 +32,11 @@ module.exports = {
|
|||||||
* @param string key Setting key
|
* @param string key Setting key
|
||||||
* @param object login Login object
|
* @param object login Login object
|
||||||
* @param object settings Settings object
|
* @param object settings Settings object
|
||||||
|
* @param string scope SettingScope value to specify where to search for the setting (optional)
|
||||||
* @return object Setting value
|
* @return object Setting value
|
||||||
*/
|
*/
|
||||||
function getSetting(key, login, settings) {
|
function getSetting(key, login, settings, scope = SettingScope.Login) {
|
||||||
if (typeof login.settings[key] !== "undefined") {
|
if (scope === SettingScope.Login && typeof login.settings[key] !== "undefined") {
|
||||||
return login.settings[key];
|
return login.settings[key];
|
||||||
}
|
}
|
||||||
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {
|
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {
|
||||||
|
@@ -103,7 +103,7 @@ function view(ctl, params) {
|
|||||||
]),
|
]),
|
||||||
(() => {
|
(() => {
|
||||||
if (
|
if (
|
||||||
this.settings.enableOTP &&
|
helpers.getSetting("enableOTP", login, this.settings, helpers.SettingScope.Store) &&
|
||||||
login.fields.otp &&
|
login.fields.otp &&
|
||||||
login.fields.otp.params.type === "totp"
|
login.fields.otp.params.type === "totp"
|
||||||
) {
|
) {
|
||||||
|
Reference in New Issue
Block a user