-
Notifications
You must be signed in to change notification settings - Fork 2
Add Env Module RGB Support + Security Fixes #57
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
Merged
Merged
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
## Features - Add RGB properties (red, green, blue, rgb) to Env module - Implement version-based RGB support check (v2.x+) - Add comprehensive test suite (15 new tests) - Create multi-module examples with version handling ## Changes ### Core Implementation - modi_plus/module/input_module/env.py: Add RGB properties with v2.x+ check - modi_plus/module/module.py: Increase mock buffer to support RGB offsets - RGB property offsets: RED=8, GREEN=10, BLUE=12 ### Testing - tests/module/input_module/test_env.py: Add 15 RGB tests - Test coverage: v1.x (not supported), v2.x (supported), v3.x (supported) - Total tests: 67 โ 82 (all passing) ### Examples - env_rgb_example.py: Multi-module RGB monitoring - env_rgb_mixed_versions.py: Handle mixed v1.x/v2.x modules - env_rgb_color_detection.py: RGB-based color detection ### Makefile & Testing Infrastructure - Improve Makefile with better test commands - Add pytest.ini to resolve setup_module naming conflict - Fix packaging dependency (21.3 โ >=21.3) - Add test-input, test-output, test-task commands ### Documentation - ENV_RGB_FEATURE.md: Complete API documentation - ENV_RGB_SUMMARY.md: Implementation summary - ENV_RGB_EXAMPLES.md: Multi-module examples guide - MAKEFILE_GUIDE.md: Makefile usage guide - TESTS_README.md: Testing system explanation ## Test Results - 82 tests passing in 1.24s - No dependency conflicts - Full backward compatibility ๐ค Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Added test-examples-syntax command to validate example file syntax - Added test-all command combining unit tests, lint, and example syntax checks - Created comprehensive testing strategy documentation (TESTING_STRATEGY.md) - Added PyPI deployment guides (PYPI_DEPLOYMENT_GUIDE.md, QUICK_DEPLOY.md) - Created automated deployment script (scripts/deploy_to_pypi.sh) - Clarified that examples require manual hardware testing - Fixed Makefile syntax issues and duplicate target names Testing: - make test-examples-syntax validates 17 example files - make test-all runs all automated tests (unit + lint + syntax) - All syntax checks passing ๐ค Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
## Security Fixes ### Critical Issues Resolved: 1. **Removed exec() in tutorial_util.py (Line 273)** - Risk: Arbitrary code execution via user input - Fix: Direct function call with input validation - Impact: Tutorial functionality unchanged 2. **Replaced eval() with getattr() in inspection_util.py (Line 26)** - Risk: Code injection through dynamic property access - Fix: Safe attribute access with validation - Impact: Hardware inspection works identically 3. **Replaced os.system() with subprocess.run() in ble_task_rpi.py** - Risk: Command injection via shell interpretation - Fix: Direct process execution with argument lists - Added: Path validation, timeout, error handling - Impact: Bluetooth communication unchanged ### Additional Changes: 4. **Added SECURITY.md** - Vulnerability reporting process - Security best practices - Response timeline ## Testing Results ### Unit Tests: - โ 82/82 tests passing (1.19s) - All existing functionality verified ### Hardware Tests (with connected MODI+ modules): - โ 15/15 core examples working correctly - โ 3/3 new RGB examples tested - โ All hardware communication validated -โ ๏ธ 2 game examples require optional 'playscii' library ### Security Impact: - No changes to hardware communication logic - All property access methods unchanged - Bluetooth configuration still works - Tutorial mode functions identically ## Modified Files: - SECURITY.md (new): Security policy and reporting - modi_plus/util/tutorial_util.py: exec() โ direct call - modi_plus/util/inspection_util.py: eval() โ getattr() - modi_plus/task/ble_task/ble_task_rpi.py: os.system() โ subprocess.run() ๐ค Generated with [Claude Code](https://claude.com/claude-code) 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.
Pull Request: Env Module RGB Support + Security Fixes
๐ Summary
This PR adds RGB color sensor support for Env module v2.x+ and fixes critical security vulnerabilities in the codebase.
๐ฏ Features
1. RGB Support for Env Module (v2.x+)
New Properties:
red- Red color intensity (0-65535)green- Green color intensity (0-65535)blue- Blue color intensity (0-65535)rgb- Tuple of (red, green, blue) valuesVersion Detection:
_is_rgb_supported()AttributeErrorwith helpful messageImplementation Details:
2. Security Vulnerability Fixes
Critical Issues Fixed:
a) Removed
exec()in tutorial_util.pyb) Replaced
eval()withgetattr()in inspection_util.pyc) Replaced
os.system()withsubprocess.run()in ble_task_rpi.pyd) Added SECURITY.md
๐ Files Changed
Core Implementation
modi_plus/module/input_module/env.py- RGB properties and version checkingmodi_plus/module/module.py- Buffer size fix (12 โ 14 bytes)Security Fixes
modi_plus/util/tutorial_util.py- Removedexec()modi_plus/util/inspection_util.py- Replacedeval()withgetattr()modi_plus/task/ble_task/ble_task_rpi.py- Replacedos.system()withsubprocess.run()SECURITY.md- Security policy (new)Tests
tests/module/input_module/test_env.py- 15 new RGB tests addedDocumentation
ENV_RGB_FEATURE.md- Complete RGB API documentationENV_RGB_SUMMARY.md- Quick reference guideENV_RGB_EXAMPLES.md- Example usage guideMAKEFILE_GUIDE.md- Makefile usage documentationTESTING_STRATEGY.md- Testing strategy and guidelinesPYPI_DEPLOYMENT_GUIDE.md- PyPI deployment processQUICK_DEPLOY.md- Quick deployment referenceSECURITY.md- Security policy and reportingExamples
env_rgb_example.py- Multi-module RGB monitoringenv_rgb_mixed_versions.py- Mixed v1.x/v2.x version handlingenv_rgb_color_detection.py- RGB-based color detectionBuild & Testing
Makefile- Enhanced with new test commandspytest.ini- Test configuration (new)requirements.txt- Fixed packaging version conflictscripts/deploy_to_pypi.sh- Automated deployment script (new)๐งช Testing
Unit Tests
make testNew RGB Test Coverage:
Hardware Tests
# With MODI+ modules connected python3 examples/basic_usage_examples/env_rgb_example.pyplaysciilibrarySyntax Validation
Full Test Suite
๐ Test Results Summary
๐ Security Assessment
Before This PR:
After This PR:
No Breaking Changes:
๐ Documentation
API Documentation
Developer Documentation
User Documentation
๐ Deployment
Version Recommendation
This PR includes:
Recommended version bump:
0.3.1โ0.4.0Deployment Checklist
modi_plus/about.py๐ฏ Breaking Changes
None. This PR is fully backward compatible.
๐ Checklist
๐ Related Issues
This PR addresses:
๐ธ Testing Evidence
RGB Support
Security Fixes
๐ Review Notes
This PR brings significant improvements:
Ready for review and merge! ๐
Questions or concerns? Feel free to comment or request changes.