-
-
Notifications
You must be signed in to change notification settings - Fork 18
Fix safe handling of constructor null values #142
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6c406dc
Fix safe handling of constructor null values
mcollina 8dca2b5
Merge main branch and fix constructor null handling
mcollina a19da94
Fix linting issues and update CLAUDE.md
mcollina 63971c7
Remove CLAUDE.md from tracking and update .gitignore
mcollina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# CLAUDE.md | ||
|
||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
||
## Project Overview | ||
|
||
This is **secure-json-parse**, a drop-in replacement for `JSON.parse()` that protects against prototype poisoning attacks. The library detects and handles dangerous `__proto__` and `constructor` properties in JSON that could lead to prototype pollution vulnerabilities. | ||
|
||
## Architecture | ||
|
||
- **Single-file module**: `index.js` contains the core functionality | ||
- **Three main functions**: | ||
- `parse()`: Main JSON parsing with security checks (supports reviver and options) | ||
- `scan()` (exported as `filter`): Scans existing objects for dangerous properties | ||
- `safeParse()`: Returns undefined instead of throwing errors | ||
- **Security approach**: Uses regex pre-scanning for performance, then deep object traversal for thorough cleanup | ||
- **Enhanced security**: Now specifically targets `constructor.prototype` patterns rather than any `constructor` property | ||
- **Action modes**: `error` (default), `remove`, or `ignore` for both `protoAction` and `constructorAction` | ||
- **TypeScript support**: Includes TypeScript definitions in `types/` directory | ||
|
||
## Commands | ||
|
||
### Testing | ||
```bash | ||
npm test # Run linting, unit tests, and TypeScript tests | ||
npm run test:unit # Run unit tests only (tape) | ||
npm run test:typescript # Run TypeScript definition tests (tsd) | ||
npm run test:browser # Run tests in browsers using airtap | ||
``` | ||
|
||
### Linting | ||
```bash | ||
npm run lint # Run ESLint with neostandard config | ||
npm run lint:fix # Auto-fix linting issues where possible | ||
``` | ||
|
||
### Benchmarking | ||
```bash | ||
npm run benchmark # Run performance benchmarks against standard JSON.parse | ||
``` | ||
|
||
### Code Standards | ||
- Uses **neostandard** with **ESLint 9** for linting | ||
- **Tape** for testing framework | ||
- **nyc** for test coverage | ||
- **tsd** for TypeScript definition testing | ||
- Test files located in `test/` directory (not root) | ||
|
||
### Git Workflow | ||
- Use `git commit -s` to add Developer Certificate of Origin signoff | ||
- Create feature branches for changes | ||
- All commits should include proper signoff for contribution tracking | ||
|
||
## Testing Notes | ||
|
||
- Tests cover all action combinations (`error`/`remove`/`ignore`) | ||
- Unicode escape sequence handling is thoroughly tested | ||
- Buffer and BOM (Byte Order Mark) support included | ||
- Tests verify behavior with overwritten `hasOwnProperty` | ||
- Constructor null handling is tested to prevent TypeError | ||
- Enhanced security tests for `constructor.prototype` patterns specifically | ||
- TypeScript definitions are validated with test files in `types/` |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.