-
Notifications
You must be signed in to change notification settings - Fork 413
feat: support custom data dir and log directories #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,9 @@ const tagBytes = 16 | |||||||||||||||
|
|
||||||||||||||||
| // StorageDir returns the directory where encrypted files are stored. | ||||||||||||||||
| func StorageDir(service string) string { | ||||||||||||||||
| if dir := os.Getenv("LARKSUITE_CLI_DATA_DIR"); dir != "" { | ||||||||||||||||
| return dir | ||||||||||||||||
|
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Append service name to avoid data conflicts between services. When
The default behavior (line 38) correctly appends the service name: 🔧 Proposed fix to append service name func StorageDir(service string) string {
if dir := os.Getenv("LARKSUITE_CLI_DATA_DIR"); dir != "" {
- return dir
+ return filepath.Join(dir, service)
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate the environment variable path before use. The As per coding guidelines: Validate paths using 🛡️ Proposed fix to add path validation+import (
+ "github.com/larksuite/cli/internal/validate"
+)
+
func StorageDir(service string) string {
if dir := os.Getenv("LARKSUITE_CLI_DATA_DIR"); dir != "" {
+ if err := validate.SafeInputPath(dir); err != nil {
+ fmt.Fprintf(os.Stderr, "warning: invalid LARKSUITE_CLI_DATA_DIR: %v, using default\n", err)
+ // Fall through to default logic
+ } else {
- return dir
+ return dir
+ }
}🤖 Prompt for AI Agents🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check if macOS StorageDir implementation supports LARKSUITE_CLI_DATA_DIR
rg -n "LARKSUITE_CLI_DATA_DIR" internal/keychain/keychain_darwin.goRepository: larksuite/cli Length of output: 39 🏁 Script executed: # Check the macOS StorageDir implementation
cat -n internal/keychain/keychain_darwin.go | sed -n '40,60p'Repository: larksuite/cli Length of output: 967 🏁 Script executed: # List all platform-specific keychain implementations
fd -e go internal/keychain/ | sortRepository: larksuite/cli Length of output: 434 🏁 Script executed: # Check what keychain_other.go represents and its full context
head -n 40 internal/keychain/keychain_other.goRepository: larksuite/cli Length of output: 976 🏁 Script executed: # Find all keychain implementation files
fd . internal/keychain/ --type f -e go | sortRepository: larksuite/cli Length of output: 298 🏁 Script executed: # Search for any documentation or reasoning about platform-specific StorageDir
rg -n "StorageDir|LARKSUITE_CLI_DATA_DIR" internal/keychain/ -B2 -A2Repository: larksuite/cli Length of output: 5429 🏁 Script executed: # Check if there's documentation in config or other places about this env var
rg -n "LARKSUITE_CLI_DATA_DIR" --type go | head -20Repository: larksuite/cli Length of output: 155 🏁 Script executed: # Check Windows implementation for StorageDir
cat -n internal/keychain/keychain_windows.go | sed -n '1,80p'Repository: larksuite/cli Length of output: 3114 🏁 Script executed: # Check if LARKSUITE_CLI_DATA_DIR is documented anywhere
rg -n "LARKSUITE_CLI_DATA_DIR" -B3 -A3 --type-add='markdown:*.md'Repository: larksuite/cli Length of output: 549 🏁 Script executed: # Check tests for keychain_other to see if env var override is tested
cat internal/keychain/keychain_other.go | grep -n "func Test"Repository: larksuite/cli Length of output: 39 🏁 Script executed: # Check if there's a test file for keychain_other
fd . internal/keychain/ --name '*other*test*'Repository: larksuite/cli Length of output: 289 🏁 Script executed: # Look for any test that uses LARKSUITE_CLI_DATA_DIR
rg -n "LARKSUITE_CLI_DATA_DIR" --type goRepository: larksuite/cli Length of output: 155 🏁 Script executed: # Check if there are tests that might use t.Setenv for this
rg -n "Setenv.*LARKSUITE_CLI" --type goRepository: larksuite/cli Length of output: 3772 Add environment variable override to macOS StorageDir for consistency, or document as Linux-only. The Linux implementation in Consider either:
🤖 Prompt for AI Agents
Comment on lines
27
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When
Suggested change
|
||||||||||||||||
| home, err := vfs.UserHomeDir() | ||||||||||||||||
| if err != nil || home == "" { | ||||||||||||||||
| // If home is missing, fallback to relative path and print warning. | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate the environment variable path before use.
The
LARKSUITE_CLI_LOG_DIRenvironment variable is user-controlled input that is returned directly and later used in file I/O operations (line 48:vfs.MkdirAll, line 54:vfs.OpenFile). Without validation, malicious or malformed paths could cause path traversal vulnerabilities or unexpected filesystem behavior.As per coding guidelines: Validate paths using
validate.SafeInputPathbefore any file I/O operations.🛡️ Proposed fix to add path validation
🤖 Prompt for AI Agents