Skip to content

Commit ff66e8f

Browse files
committed
Merge pull request ethereum#1562 from ethersphere/blankpasswd
jsre: leave out lines from history possibly containing passwords
2 parents 17b481e + 6628eeb commit ff66e8f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

cmd/geth/js.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"os/signal"
2525
"path/filepath"
26+
"regexp"
2627
"strings"
2728

2829
"sort"
@@ -44,6 +45,10 @@ import (
4445
"github.com/robertkrimen/otto"
4546
)
4647

48+
var passwordRegexp = regexp.MustCompile("personal.[nu]")
49+
50+
const passwordRepl = ""
51+
4752
type prompter interface {
4853
AppendHistory(string)
4954
Prompt(p string) (string, error)
@@ -413,15 +418,25 @@ func (self *jsre) interactive() {
413418
str += input + "\n"
414419
self.setIndent()
415420
if indentCount <= 0 {
416-
hist := str[:len(str)-1]
417-
self.AppendHistory(hist)
421+
hist := hidepassword(str[:len(str)-1])
422+
if len(hist) > 0 {
423+
self.AppendHistory(hist)
424+
}
418425
self.parseInput(str)
419426
str = ""
420427
}
421428
}
422429
}
423430
}
424431

432+
func hidepassword(input string) string {
433+
if passwordRegexp.MatchString(input) {
434+
return passwordRepl
435+
} else {
436+
return input
437+
}
438+
}
439+
425440
func (self *jsre) withHistory(op func(*os.File)) {
426441
datadir := common.DefaultDataDir()
427442
if self.ethereum != nil {

0 commit comments

Comments
 (0)