| Hasnain Lakhani | aa18332 | 2025-08-25 13:54:33 -0700 | [diff] [blame] | 1 | # Node.js Fuzzing README |
| 2 | |
| 3 | The Node.js Thrift implementation uses Jazzer.js for fuzzing. Jazzer.js is a coverage-guided, in-process fuzzer for JavaScript that integrates with libFuzzer. |
| 4 | |
| 5 | ## Setup |
| 6 | |
| 7 | 1. Install Jazzer.js: |
| 8 | ```bash |
| 9 | npm install --save-dev @jazzer.js/core |
| 10 | ``` |
| 11 | |
| 12 | ## Available Fuzzers |
| 13 | |
| 14 | The Node.js Thrift implementation currently supports the following fuzz targets: |
| 15 | |
| 16 | * `fuzz_parse_TJSONProtocol.js` - fuzzes the deserialization of the JSON protocol |
| 17 | * `fuzz_roundtrip_TJSONProtocol.js` - fuzzes the roundtrip of the JSON protocol (serialize -> deserialize -> compare) |
| 18 | * `fuzz_parse_TBinaryProtocol.js` - fuzzes the deserialization of the Binary protocol |
| 19 | * `fuzz_roundtrip_TBinaryProtocol.js` - fuzzes the roundtrip of the Binary protocol |
| 20 | * `fuzz_parse_TCompactProtocol.js` - fuzzes the deserialization of the Compact protocol |
| 21 | * `fuzz_roundtrip_TCompactProtocol.js` - fuzzes the roundtrip of the Compact protocol |
| 22 | |
| 23 | ## Running Fuzzers |
| 24 | |
| 25 | To run a fuzzer, use the Jazzer.js CLI: |
| 26 | |
| 27 | ```bash |
| 28 | npx jazzer ./fuzz_parse_TJSONProtocol.js --corpus=./corpus |
| 29 | ``` |
| 30 | |
| 31 | Where: |
| 32 | - `--corpus` points to a directory containing seed inputs (optional) |
| 33 | |
| 34 | ## Corpus Generation |
| 35 | |
| 36 | You can use the corpus generator from the Rust implementation to generate initial corpus files that can be used with these Node.js fuzzers. For JSON protocol fuzzers, ensure the corpus contains valid JSON data. |
| 37 | |
| 38 | ## Adding New Fuzzers |
| 39 | |
| 40 | To add a new fuzzer: |
| 41 | |
| 42 | 1. Create a new file in the `fuzz` directory |
| 43 | 2. Import the appropriate helper functions from `fuzz_common.js` |
| 44 | 3. Export a `fuzz` function that takes a Buffer parameter |
| 45 | 4. Use either `createParserFuzzer` or `createRoundtripFuzzer` with the appropriate protocol factory |
| 46 | |
| 47 | Example: |
| 48 | ```javascript |
| 49 | const { createParserFuzzer } = require('./fuzz_common'); |
| 50 | |
| 51 | module.exports.fuzz = createParserFuzzer((transport) => { |
| 52 | return new thrift.TJSONProtocol(transport); |
| 53 | }); |
| 54 | ``` |
| 55 | |
| 56 | For more information about Jazzer.js and its options, see the [Jazzer.js documentation](https://github.com/CodeIntelligenceTesting/jazzer.js). |