-
Notifications
You must be signed in to change notification settings - Fork 6
Fix Critical Security Vulnerabilities and Modernize Codebase #6
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
Open
prasincs
wants to merge
8
commits into
hf:main
Choose a base branch
from
prasincs:nsm-modernize-with-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I used claude to review the code and manually checked every change - Update Go 1.15 → 1.23, CBOR library v2.2.0 → v2.7.0 - Fix potential panic on empty slice access in IOCTL operations - Fix resource leaks: only clear fd on successful close - Fix infinite loop in Read() entropy generation - Fix inconsistent nil checking patterns throughout codebase - Fix duplicate JSON tags in response structs - Document blocking IOCTL behavior and performance implications - Add basic GitHub Actions CI workflow Co-Authored-By: Claude <[email protected]>
- Fix buffer overrun: validate response length before slicing - Fix type assertion panics: add safe checks for pool operations - Fix race condition: use defer for cleanup in Close() method - Add input validation: check request/response sizes and nil values - Add error context: wrap CBOR and encoding errors with details - Fix README examples: correct defer placement after error checks - Update README: use consistent Go idioms (err != nil) Addresses memory safety issues that could cause crashes or data corruption in production AWS Nitro Enclave environments. Co-Authored-By: Claude <[email protected]>
- Add tests validating empty buffer protection against panics
- Add tests for nil session handling and proper error returns
- Add tests for resource cleanup with defer in Close() method
- Add tests for type-safe pool operations without panics
- Add tests for input validation and closed session detection
- Fix nil pool access: check pools before use in Send/Read
- Modernize: use 'any' instead of 'interface{}' for Go 1.18+
- All tests pass, validating production safety of security fixes
Co-Authored-By: Claude <[email protected]>
- Add test coverage for ioc package: IOCTL command generation (100%) - Add test coverage for request package: all Encoded() methods (100%) - Add test coverage for response package: CBOR unmarshaling (100%) - Extend nsm package tests: sendMarshaled validation, successful paths - Improve main package coverage from 44.6% to 63.4% - Add tests for OpenDefaultSession, pool type safety, error handling - Tests validate all security fixes and core functionality - All tests are focused, human-reviewable, and production-ready Co-Authored-By: Claude <[email protected]>
- Add GitHub Actions workflow with lint, test, and coverage checks - Pin all dependencies: golangci-lint v1.61.0, actions@v4/v5/v6 - Use go.mod version (1.23) for consistent builds - Enforce 60% minimum test coverage with built-in tooling - Add Makefile for local development with same standards - Self-contained pipeline - no external services or tokens required - Add .gitignore with https://github.com/github/gitignore/blob/main/Go.gitignore Co-Authored-By: Claude <[email protected]>
- Fix unused parameters in test functions by replacing with underscore - Organize constants and variables at top of nsm.go file - Add tools.go for development dependencies with go run approach - Update Makefile to use go run for tools instead of install - Update CI workflow to use Makefile targets for consistency Co-Authored-By: Claude <[email protected]>
- Add make fmt command with gofmt and goimports - Make lint target depend on fmt to ensure proper formatting - Fix unused parameters in test functions by using underscore - Fix nil pointer dereference warning with else-if pattern - Fix allocation warnings by using original pool objects - Add tools.go for development dependencies with go:build tools tag - Update Makefile to use go run for tools instead of installation - Ensure consistent code formatting across all files Co-Authored-By: Claude <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses critical memory safety issues in this AWS Nitro Enclave library and modernizes it for production use with some modern Go idioms. I was tempted to upgrade it all the way to 1.25 but figured I'll keep it to 1.23.
AI Use
I did use Claude Code as a helper here to ensure I'm catching everything.
🚨 Critical Security Fixes
Memory Safety Issues
res[:msg.Response.Len]could exceed buffer ifmalicious NSM device returns invalid length (this is unlikely but better to be defensive than panic in production)
msg.Response.Len > uint64(len(res))&req[0]and&res[0]panic when slices are emptysess.reqpool.Get().(*bytes.Buffer)panics on wrong pooltypes
Resource Management Issues
Close()set fd=nil even on close failure, preventing retryfor i := 0; i < len(into); i += 0in Read() methodError Handling Issues
nil != erranderr != nilthroughout codebasedefer sess.Close()called before nil check in examples🔧 Modernization & Quality
Dependencies & Tooling
interface{}→anyfor Go 1.18+Testing & Documentation
🔍 Technical Details
Before (Vulnerable)
After (Secure)