Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit 4ca5c7c

Browse files
eraydmax-baz
authored andcommitted
Support per-site configuration for autoSubmit in pass entries (#252) (fixes #251)
1 parent 9233a66 commit 4ca5c7c

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

browserpass.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import (
1919

2020
// Login represents a single pass login.
2121
type Login struct {
22-
Username string `json:"u"`
23-
Password string `json:"p"`
24-
OTP string `json:"digits"`
25-
OTPLabel string `json:"label"`
26-
URL string `json:"url"`
22+
Username string `json:"u"`
23+
Password string `json:"p"`
24+
OTP string `json:"digits"`
25+
OTPLabel string `json:"label"`
26+
URL string `json:"url"`
27+
AutoSubmit *bool `json:"autoSubmit,omitempty"`
2728
}
2829

2930
var endianness = binary.LittleEndian
@@ -37,7 +38,7 @@ var endianness = binary.LittleEndian
3738
// Config defines the root config structure sent from the browser extension
3839
type Config struct {
3940
// Manual searches use FuzzySearch if true, GlobSearch otherwise
40-
UseFuzzy bool `json:"use_fuzzy_search"`
41+
UseFuzzy bool `json:"use_fuzzy_search"`
4142
CustomStores []pass.StoreDefinition `json:"customStores"`
4243
}
4344

@@ -231,19 +232,31 @@ func parseLogin(r io.Reader) (*Login, error) {
231232
// Keep reading file for string in "login:", "username:" or "user:" format (case insensitive).
232233
userPattern := regexp.MustCompile("(?i)^(login|username|user):")
233234
urlPattern := regexp.MustCompile("(?i)^(url|link|website|web|site):")
235+
autoSubmitPattern := regexp.MustCompile("(?i)^autosubmit:")
234236
for scanner.Scan() {
235237
line := scanner.Text()
236-
parseTotp(line, login)
237-
replaced := userPattern.ReplaceAllString(line, "")
238-
if len(replaced) != len(line) {
239-
login.Username = strings.TrimSpace(replaced)
238+
if login.OTP == "" {
239+
parseTotp(line, login)
240+
}
241+
if login.Username == "" {
242+
replaced := userPattern.ReplaceAllString(line, "")
243+
if len(replaced) != len(line) {
244+
login.Username = strings.TrimSpace(replaced)
245+
}
240246
}
241247
if login.URL == "" {
242-
replaced = urlPattern.ReplaceAllString(line, "")
248+
replaced := urlPattern.ReplaceAllString(line, "")
243249
if len(replaced) != len(line) {
244250
login.URL = strings.TrimSpace(replaced)
245251
}
246252
}
253+
if login.AutoSubmit == nil {
254+
replaced := autoSubmitPattern.ReplaceAllString(line, "")
255+
if len(replaced) != len(line) {
256+
value := strings.ToLower(strings.TrimSpace(replaced)) == "true"
257+
login.AutoSubmit = &value
258+
}
259+
}
247260
}
248261

249262
// if an unlabelled OTP is present, label it with the username

chrome/background.browserify.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ chrome.tabs.onUpdated.addListener(onTabUpdated);
1212
chrome.runtime.onInstalled.addListener(onExtensionInstalled);
1313

1414
// fill login form & submit
15-
function fillLoginForm(login, tab) {
15+
function fillLoginForm(login, tab, autoSubmit) {
1616
const loginParam = JSON.stringify(login);
1717
chrome.tabs.executeScript(
1818
tab.id,
@@ -23,7 +23,7 @@ function fillLoginForm(login, tab) {
2323
function() {
2424
chrome.tabs.executeScript({
2525
allFrames: true,
26-
code: `browserpassFillForm(${loginParam}, ${getSettings().autoSubmit});`
26+
code: `browserpassFillForm(${loginParam}, ${autoSubmit});`
2727
});
2828
}
2929
);
@@ -76,7 +76,8 @@ function onMessage(request, sender, sendResponse) {
7676
) {
7777
// do not send login data to page if URL changed during search.
7878
if (tabs[0].url == request.urlDuringSearch) {
79-
fillLoginForm(response, tabs[0]);
79+
var autoSubmit = response.hasOwnProperty('autoSubmit') ? response.autoSubmit : getSettings().autoSubmit;
80+
fillLoginForm(response, tabs[0], autoSubmit);
8081
}
8182
});
8283

0 commit comments

Comments
 (0)