Repository navigation
feat: IdentityFile pull and arrow key hold-repeat - #66
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 41125516 | Triggered | OpenSSH Private Key | bb55c7f | test/fixtures/id_ed25519_unencrypted | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Reviewer's GuideAPIReview the SSH config import outcomes and the merge/pull interface that passes pending IdentityFile paths through to key attachment.
Review the parser’s IdentityFile contract and documentation alongside the import interface that consumes its parsed paths.
Uses of the APIReview how profile import invokes the SFTP pull, persists keys and profiles, and reports the resulting hints and attached keys.
ImplementationReview how IdentityFile paths are expanded for Windows and POSIX configurations before remote reads.
Review PEM validation, encrypted-key rejection, algorithm mapping, and safe failure messages used by key import.
DocumentationReview the user-facing feature and release notes for the new IdentityFile pull and arrow-key repeat behavior.
Review the project guidance and roadmap updates that record IdentityFile import behavior and its shipped status.
TestsReview generated in-memory test keys and coverage for IdentityFile path resolution, PEM import, key attachment, hints, and shared-key reuse.
Review tests that verify which shortcut actions support repeat and how arrow actions map to terminal keys.
Other changesFiles not grouped.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
| @@ -0,0 +1,7 @@ | |||
| -----BEGIN OPENSSH PRIVATE KEY----- | |||
There was a problem hiding this comment.
CRITICAL: Test fixture contains a real OpenSSH private key
The file test/fixtures/id_ed25519_unencrypted contains an actual OpenSSH private key (BEGIN OPENSSH PRIVATE KEY). GitGuardian has already flagged this as a secret. Even though the PR description states this is a "disposable" test key, committing any private key material to a repository is a security anti-pattern. This key should be replaced with a clearly fake/mock key that is obviously not real (e.g., using a placeholder like -----BEGIN OPENSSH PRIVATE KEY-----\nMOCK_KEY_DATA\n-----END OPENSSH PRIVATE KEY-----) or generated dynamically in the test setup.
| candidate, | ||
| maxBytes: kIdentityFileMaxBytes, | ||
| ); | ||
| pemText = utf8.decode(bytes, allowMalformed: false); |
There was a problem hiding this comment.
WARNING: Misleading error message on UTF-8 decode failure
utf8.decode(bytes, allowMalformed: false) throws a FormatException if the bytes are not valid UTF-8. The catch block treats all exceptions as "not found or unreadable", which is misleading for decoding errors (e.g., corrupted file, binary data, wrong encoding). Consider catching FileSystemException/StateError separately from FormatException to provide accurate error messages.
| ); | ||
| pemText = utf8.decode(bytes, allowMalformed: false); | ||
| } catch (_) { | ||
| lastError = 'not found or unreadable at $candidate'; |
There was a problem hiding this comment.
WARNING: Broad exception catching masks real errors
The catch (_) block catches all exceptions (including SocketException, PermissionException, TimeoutException, etc.) and converts them to a generic "not found or unreadable" message. This makes debugging difficult. Consider catching specific exception types or at least logging the original exception for debugging.
| if (SSHKeyPair.isEncryptedPem(pem)) { | ||
| return const PemKeyImportResult.failed(PemKeyImportFailure.encrypted); | ||
| } | ||
| } catch (_) { |
There was a problem hiding this comment.
WARNING: Silent catch on encryption probe may mask parse errors
SSHKeyPair.isEncryptedPem(pem) throwing an exception could indicate a malformed PEM, not just an encrypted one. Silently continuing to fromPem may cause a subsequent parse failure with a less clear error message. Consider logging the exception or handling specific failure modes.
| if (pulled.keys.isNotEmpty) { | ||
| final existingKeys = await ConfigService.getSSHKeys(); | ||
| for (final key in pulled.keys) { | ||
| await SecureStorageService.writePrivateKey(key.id, key.privateKey); |
There was a problem hiding this comment.
WARNING: No error handling for secure storage and config save
If SecureStorageService.writePrivateKey or ConfigService.saveSSHKeys throws, the imported keys are not persisted but the profile update continues. This leaves profiles referencing key IDs that don't exist in secure storage/config. Wrap these in try-catch and roll back or report the failure to the user.
| homes.add(homeFromConfig); | ||
| } | ||
| if (isWindowsConfig) { | ||
| final winHome = RemotePath.normalize('C:/Users/$username'); |
There was a problem hiding this comment.
SUGGESTION: Windows home directory fallback may be incorrect
The fallback C:/Users/$username assumes the Windows profile folder matches the SSH username and is on C:. This may fail for users with renamed profiles, different drive letters, or domain-joined machines (e.g., C:/Users/username.DOMAIN). The homeFromConfig derivation (line 21) is more reliable when available.
| final rawPath = entry.value; | ||
|
|
||
| final existingRef = profile.privateKey?.trim(); | ||
| if (existingRef != null && existingRef.isNotEmpty) { |
There was a problem hiding this comment.
SUGGESTION: Existing key check doesn't account for PEM strings in privateKey field
profile.privateKey?.trim() is checked for emptiness, but privateKey can contain a PEM string (as seen in profile_manager.dart:382 with looksLikePemPrivateKey check). A profile with a PEM string in privateKey would incorrectly be treated as having no key, potentially causing duplicate key imports. Consider using the same looksLikePemPrivateKey check or a dedicated hasKey helper.
Co-authored-by: Cursor <cursoragent@cursor.com>
| if (!_repeatActive) { | ||
| return; | ||
| } | ||
| fire(); |
There was a problem hiding this comment.
WARNING: Hold-to-repeat doesn't verify connection on each timer fire
The periodic timer callback calls fire() without re-checking isConnected. If the SSH session disconnects while the user holds an arrow key, keys continue to be sent to a disconnected session. Consider checking ssh.activeSession?.isConnected inside the timer callback or the fire() function.
| case 'ssh-ed25519': | ||
| return SSHKeyType.ed25519; | ||
| case 'ssh-rsa': | ||
| return SSHKeyType.rsa2048; |
There was a problem hiding this comment.
SUGGESTION: All ssh-rsa keys mapped to rsa2048 regardless of actual size
The SSH algorithm name ssh-rsa doesn't encode key size (could be 2048, 3072, 4096 bits). Consider detecting the key size from the parsed key pair or using a generic RSA type if the enum supports it.
Summary
IdentityFilePEMs over SFTP during SSH config import and attach them to profiles that do not already have a key (encrypted/missing/already-keyed stay as hints).Related issues
N/A
Type of change
Platform tested
Test plan
flutter pub getflutter analyze(no errors)flutter testSteps:
flutter test test/utils/identity_file_path_test.dart test/utils/pem_key_import_test.dart test/services/ssh_config_import_service_test.dart test/widgets/shortcut_key_repeat_test.dartIdentityFilein~/.ssh/config, import SSH config, confirm key attaches (or hint when passphrase-protected).Screenshots / recordings
N/A
Checklist
analysis_options.yamlNote:
test/fixtures/id_ed25519_unencryptedis a disposable OpenSSH test key generated for unit tests, not a real host credential.Summary by Sourcery
Add SSH config IdentityFile key import and hold-to-repeat arrow shortcuts.
New Features:
Enhancements:
Documentation:
Tests: