blacs30 / bitwarden-alfred-workflow

Simple Bitwarden Workflow for Alfred
MIT License
449 stars 31 forks source link

A 'runtime error: slice bounds out of range [:-18]' is copied to the clipboard instead of the password. #163

Closed katsusuke closed 1 year ago

katsusuke commented 1 year ago

Copying the password fails and the text 'A 'runtime error: slice bounds out of range [:-18]' is copied to the clipboard instead of the password. I have tried enabling DEBUG=true, and MakeDecryptKeyFromSession() seems to fail but is not falling back to bitwarden-cli.

I'm using following versions.

bitwarden-alfred-workflow version: 2.4.7 bw: 2023.5.0 node: 'v20.2.0'

The debug logs are as follows. I have replaced the confidential information with xxx.

[15:08:41.845] Bitwarden v2[Script Filter] Processing complete
[15:08:41.847] Bitwarden v2[Script Filter] Passing output 'login.password' to Conditional
[15:08:41.849] Bitwarden v2[Conditional] Processing complete
[15:08:41.851] Bitwarden v2[Conditional] Passing output 'login.password' to Run Script
[15:08:41.976] ERROR: Bitwarden v2[Run Script] Rotated log
15:08:41 utils.go:172: [DEBUG] bwDataPath is: /Users/katsusuke/Library/Application Support/Bitwarden CLI/data.json
15:08:41 utils.go:172: [DEBUG] BwData config is: {path:/Users/katsusuke/Library/Application Support/Bitwarden CLI/data.json InstalledVersion:2023.5.0 UserEmail:myemail@example.com UserId:xxx ActiveUserId:xxx ProtectedKey:xxx Kdf:0 KdfIterations:5000 Global:{InstalledVersion:2023.5.0} Profile:{EverBeenUnlocked:false LastSync:2023-07-09T05:13:56.432Z KdfIterations:5000 KdfType:0 Email:myemail@example.com UserId:xxx} Keys:{ApiKeyClientSecret:xxx CryptoSymmetricKey:{Encrypted:xxx} PrivateKey:{Encrypted:xxx}} Tokens:{AccessToken:xxx} Unused:map[]}
🍺
15:08:41 workflow.go:328: -------- Bitwarden v2/2.4.7 (AwGo/0.27.1) --------
15:08:41 main.go:162: &main.options{Search:false, Config:false, SetConfigs:false, Auth:false, OnOffConfigs:false, AuthConfig:false, Lock:false, Icons:false, Folder:false, Unlock:false, Login:false, Logout:false, Sync:false, Open:false, GetItem:true, Force:false, Totp:false, Last:false, Background:false, Id:"b9e90184-1673-408f-87d2-a9c900793485", Query:"login.password", Attachment:"", Output:""}
15:08:41 main.go:164: args=[]string{"-getitem", "-id", "b9e90184-1673-408f-87d2-a9c900793485", "login.password"} => []string{"login.password"}
15:08:41 main.go:165: (main.config) {
 AutoFetchIconCacheAge: (int) 1440,
 AutoFetchIconMaxCacheAge: (time.Duration) 24h0m0s,
 BwconfKeyword: (string) (len=9) ".bwconfig",
 BwauthKeyword: (string) (len=7) ".bwauth",
 BwKeyword: (string) (len=3) ".bw",
 BwfKeyword: (string) (len=4) ".bwf",
 BwExec: (string) (len=2) "bw",
 BwDataPath: (string) "",
 Debug: (bool) true,
 Email: (string) (len=29) "myemail@example.com",
 EmailMaxWait: (int) 15,
 EmptyDetailResults: (bool) false,
 IconCacheAge: (int) 43200,
 IconCacheEnabled: (bool) true,
 IconMaxCacheAge: (time.Duration) 720h0m0s,
 MaxResults: (int) 1000,
 Mod1: (string) (len=3) "alt",
 Mod1Action: (string) (len=13) "username,code",
 Mod2: (string) (len=5) "shift",
 Mod2Action: (string) (len=3) "url",
 Mod3: (string) (len=4) "ctrl",
 Mod3Action: (string) (len=4) "totp",
 Mod4: (string) (len=7) "cmd,opt",
 Mod4Action: (string) (len=4) "more",
 Mod5: (string) (len=9) "cmd,shift",
 Mod5Action: (string) (len=5) "webui",
 NoModAction: (string) (len=13) "password,card",
 OpenLoginUrl: (bool) true,
 OutputFolder: (string) (len=27) "/Users/katsusuke/Downloads/",
 Path: (string) (len=101) "/opt/homebrew/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/local/share/npm/bin:/usr/bin:/usr/sbin",
 ReorderingDisabled: (bool) true,
 Server: (string) "",
 Sfa: (bool) true,
 SfaMode: (int) 0,
 SkipTypes: (string) "",
 TitleWithUser: (bool) true,
 TitleWithUrls: (bool) false,
 UseApikey: (bool) true,
 WebUiURL: (string) (len=27) "https://vault.bitwarden.com"
}
15:08:41 bitwarden.go:239: Getting item for id b9e90184-1673-408f-87d2-a9c900793485
15:08:41 utils.go:172: [DEBUG] base64 decode protected key
15:08:41 utils.go:172: [DEBUG] protected Key length is: 97
15:08:41 utils.go:172: [DEBUG] protected Key encryption type is: 2
15:08:41 utils.go:172: [DEBUG] base64 decode session key
15:08:41 utils.go:172: [DEBUG] Session key length is: 64
15:08:41 utils.go:172: [DEBUG] comparing session mac with protected key
15:08:41 utils.go:172: [DEBUG] making the source key
15:08:41 utils.go:172: [DEBUG] making intermediate keys
15:08:41 utils.go:172: [DEBUG] decrypting final encryption keys
15:08:41 utils.go:172: [DEBUG] cs.encryptionType 0
15:08:41 workflow.go:343: ------------------ FATAL ERROR -------------------
15:08:41 workflow.go:344: runtime error: slice bounds out of range [:-18] : goroutine 1 [running]:
runtime/debug.Stack()
    /Users/runner/hostedtoolcache/go/1.18.7/x64/src/runtime/debug/stack.go:24 +0x68
github.com/deanishe/awgo.(*Workflow).Run.func2()
    /Users/runner/go/pkg/mod/github.com/deanishe/awgo@v0.29.1/workflow.go:344 +0xc0
panic({0x100f8d940, 0x140004c66c0})
    /Users/runner/hostedtoolcache/go/1.18.7/x64/src/runtime/panic.go:838 +0x204
main.unpad(...)
    /Users/runner/work/bitwarden-alfred-workflow/bitwarden-alfred-workflow/src/crypt_util.go:170
main.(*CipherString).Decrypt(0x14000072900, {{0x140005b0160, 0x20, 0x20}, {0x140005b0180, 0x20, 0x20}, 0x2})
    /Users/runner/work/bitwarden-alfred-workflow/bitwarden-alfred-workflow/src/crypt_util.go:164 +0x378
main.(*CipherString).DecryptKey(0x14000771560?, {{0x140005b0160, 0x20, 0x20}, {0x140005b0180, 0x20, 0x20}, 0x2}, 0x1400011d518?)
    /Users/runner/work/bitwarden-alfred-workflow/bitwarden-alfred-workflow/src/crypt_util.go:61 +0x74
main.MakeDecryptKeyFromSession({0x140007714d0?, 0x84?}, {0x140000a623b, 0x58})
    /Users/runner/work/bitwarden-alfred-workflow/bitwarden-alfred-workflow/src/crypt.go:220 +0xb68
main.runGetItem()
    /Users/runner/work/bitwarden-alfred-workflow/bitwarden-alfred-workflow/src/bitwarden.go:240 +0x17c
main.run()
    /Users/runner/work/bitwarden-alfred-workflow/bitwarden-alfred-workflow/src/main.go:283 +0x760
github.com/deanishe/awgo.(*Workflow).Run(0x1400021b440, 0x100fb5030)
    /Users/runner/go/pkg/mod/github.com/deanishe/awgo@v0.29.1/workflow.go:358 +0x294
main.main()
    /Users/runner/work/bitwarden-alfred-workflow/bitwarden-alfred-workflow/src/main.go:290 +0x34
15:08:41 workflow.go:345: ---------------- END STACK TRACE -----------------
15:08:41 workflow.go:376: [ERROR] runtime error: slice bounds out of range [:-18]
15:08:41 workflow.go:379: Get help at https://github.com/blacs30/bitwarden-alfred-workflow/issues
15:08:41 workflow.go:402: ------------------ 54.105792ms -------------------
[15:08:41.995] Bitwarden v2[Run Script] Processing complete
[15:08:41.997] Bitwarden v2[Run Script] Passing output 'runtime error: slice bounds out of range [:-18]' to Copy to Clipboard
[15:08:41.999] Bitwarden v2[Run Script] Passing output 'runtime error: slice bounds out of range [:-18]' to Arg and Vars
[15:08:42.001] Bitwarden v2[Arg and Vars] Processing complete
[15:08:42.003] Bitwarden v2[Arg and Vars] Passing output 'Copy Password for user:
admin' to Post Notification
blacs30 commented 1 year ago

Thanks for reporting this issue. I think you are right that it is not falling back. A workaround in the meantime could be to rotate the encryption key. https://bitwarden.com/help/account-encryption-key/#rotate-your-encryption-key Just make sure to read the warnings and follow the instructions.

Alternatively, if you have the time, you could try to fix it. Unfortunately I don't have the time available at the moment.