Skip to content

feat(KSM-641): Add secret storage capability with < operator#147

Draft
maksimu wants to merge 3 commits intomasterfrom
KSM-641-add-secret-storage-with-arrow-operator
Draft

feat(KSM-641): Add secret storage capability with < operator#147
maksimu wants to merge 3 commits intomasterfrom
KSM-641-add-secret-storage-with-arrow-operator

Conversation

@maksimu
Copy link
Collaborator

@maksimu maksimu commented Sep 3, 2025

This major enhancement adds comprehensive secret storage functionality to the
KSM Action, allowing users to write/update values in Keeper records using the
new < operator syntax alongside the existing > operator for reading.

🎯 New Features

Secret Storage with < Operator

  • Store values to record fields: record/field/password < 'newpassword'
  • Store from environment variables: record/field/notes < env:MY_VAR
  • Store from files: record/field/notes < file:./notes.txt
  • Upload files to records: record/file/document.pdf < file:./local-file.pdf
  • Support for mixed read/write operations in single action

Comprehensive Safety System

  • Field type validation and sanitization
  • Protection against modification of system fields (fileRef, passkey, etc.)
  • Record integrity checks with automatic backup/restore
  • Smart field creation for standard fields (notes, text, etc.)
  • Input validation with security safeguards

Enhanced Error Handling

  • Detailed field-not-found errors with record type and available fields
  • Helpful suggestions for correct field paths
  • Reduced error message repetition
  • Context-aware error messages with record information

Automatic Retry Mechanism

  • Out-of-sync record detection and retry with exponential backoff
  • Configurable retry limits and timing
  • Graceful handling of concurrent record modifications

Performance Monitoring

  • File upload timing and progress tracking
  • Performance warnings for slow operations
  • Detailed logging for troubleshooting

🧪 Testing & Quality

  • 54+ comprehensive tests covering all functionality
  • Integration tests for real KSM operations
  • GitHub Actions workflow testing
  • Field restriction and safeguards testing
  • Retry mechanism testing
  • Docker-based build pipeline
  • Full TypeScript type safety

⚙️ Configuration

  • Configurable test record UID for GitHub Actions
  • Environment-based configuration examples
  • Comprehensive documentation and testing guides

🔄 Backward Compatibility

  • All existing > operator functionality preserved
  • No breaking changes to existing workflows
  • Enhanced but compatible action.yml interface

📊 Impact

  • 4,238 lines added, 218 deleted across 19 files
  • Major version-worthy enhancement with full backward compatibility
  • Production-ready with comprehensive safety measures

This implementation provides a robust, secure, and user-friendly way to manage
Keeper secrets bidirectionally while maintaining the highest standards for
data protection and operational reliability.

@socket-security
Copy link

socket-security bot commented Sep 3, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addeddotenv@​17.2.19910010094100

View full report

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds secret storage capability to the KSM GitHub Action using the < operator syntax. The implementation includes comprehensive safeguards to prevent record corruption, permission-aware error handling, and file upload support while maintaining full backward compatibility.

Key Changes:

  • Add bidirectional secret management with < operator for storing values to Keeper
  • Implement comprehensive safeguards including protected field validation and record integrity checks
  • Add file upload functionality and enhanced error handling with clear messages

Reviewed Changes

Copilot reviewed 12 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/main.ts Core implementation of store operations with safeguards and error handling
src/safeguards.ts New safeguards module with field validation and record integrity checks
test-integration.js Integration test runner for local testing with real KSM configuration
tests/safeguards.test.ts Comprehensive unit tests for safeguards functionality
tests/main.test.ts Enhanced unit tests including store operation parsing and error handling
tests/integration.test.ts Real KSM integration tests for end-to-end validation
tests/integration-field-restrictions.test.ts Integration tests for field restriction enforcement
action.yml Updated action definition with new inputs for store functionality
package.json Version bump to 1.2.0 and new test scripts
README.md Comprehensive documentation with examples and migration guide
CHANGELOG.md Detailed changelog documenting new features and changes
.env.local.example Template for local testing configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -0,0 +1,191 @@
#!/usr/bin/env node
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shebang should use /usr/bin/env node for better portability across different Node.js installations.

Copilot uses AI. Check for mistakes.
Comment on lines +380 to +393
function isValidUrl(url: string): boolean {
try {
new URL(url)
return true
} catch {
// Check if it's a relative URL or protocol-less
return /^(\/|www\.|[a-zA-Z0-9-]+\.)/.test(url)
}
}
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The URL validation regex pattern ^(\/|www\.|[a-zA-Z0-9-]+\.) may be too permissive and could match unintended strings. Consider using a more specific pattern or documenting the intended behavior for edge cases.

Copilot uses AI. Check for mistakes.
const fileUpload: KeeperFileUpload = {
name: fileName,
title: fileName,
type: 'application/octet-stream', // Could be enhanced with mime-type detection
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment indicates missing functionality. Consider implementing MIME type detection or creating a TODO/issue to track this enhancement.

Copilot uses AI. Check for mistakes.

describe('Protected Field Restrictions', () => {
it('should reject modification of fileRef field', async () => {
const mockLogger = createMockLogger(['A7Pu-DNINF8d14VD5NGETA/field/fileRef < test-value'])
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded record UIDs like 'A7Pu-DNINF8d14VD5NGETA' should be extracted to constants at the top of the file or use environment variables for better maintainability.

Copilot uses AI. Check for mistakes.
This major enhancement adds comprehensive secret storage functionality to the
KSM Action, allowing users to write/update values in Keeper records using the
new < operator syntax alongside the existing > operator for reading.

## New Features

### Secret Storage with < Operator
- Store values to record fields: record/field/password < 'newpassword'
- Store from environment variables: record/field/notes < env:MY_VAR
- Store from files: record/field/notes < file:./notes.txt
- Upload files to records: record/file/document.pdf < file:./local-file.pdf
- Support for mixed read/write operations in single action

### Comprehensive Safety System
- Field type validation and sanitization
- Protection against modification of system fields (fileRef, passkey, etc.)
- Record integrity checks with automatic backup/restore
- Smart field creation for standard fields (notes, text, etc.)
- Input validation with security safeguards

### Enhanced Error Handling
- Detailed field-not-found errors with record type and available fields
- Helpful suggestions for correct field paths
- Reduced error message repetition
- Context-aware error messages with record information

### Automatic Retry Mechanism
- Out-of-sync record detection and retry with exponential backoff
- Configurable retry limits and timing
- Graceful handling of concurrent record modifications

### Performance Monitoring
- File upload timing and progress tracking
- Performance warnings for slow operations
- Detailed logging for troubleshooting

## Testing & Quality
- Comprehensive test suite with 54+ tests
- Integration tests for real KSM operations
- GitHub Actions workflow testing
- Field restriction and safeguards testing
- Retry mechanism testing
- Docker-based build pipeline
- Full TypeScript type safety

## Configuration
- Configurable test record UID for GitHub Actions
- Environment-based configuration examples
- Comprehensive documentation and testing guides

## Backward Compatibility
- All existing > operator functionality preserved
- No breaking changes to existing workflows
- Enhanced but compatible action.yml interface

This implementation provides a robust, secure, and user-friendly way to manage
Keeper secrets bidirectionally while maintaining the highest standards for
data protection and operational reliability.
@maksimu maksimu force-pushed the KSM-641-add-secret-storage-with-arrow-operator branch from e214f16 to 71cdb79 Compare September 4, 2025 07:18
Replace potentially dangerous regex pattern that could cause catastrophic
backtracking with a safer, more specific pattern that follows RFC 5322
guidelines while avoiding polynomial time complexity.

- Old pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/ (vulnerable to ReDoS)
- New pattern: Uses character classes with quantified ranges to prevent backtracking
- Maintains email validation functionality while eliminating security risk
- All existing tests continue to pass

This addresses the high-severity security alert from GitHub CodeQL.
Properly quote GitHub Actions output variable to prevent syntax errors
when the output contains special characters that could break bash
conditional expressions.

- Use intermediate variable assignment to safely handle output values
- Prevents 'syntax error in conditional expression' issues
- Maintains validation functionality while improving robustness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants