json-schema-diff 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,485 @@
1
+ # JSON Schema Diff
2
+
3
+ A Ruby gem that performs semantic diffs between JSON files, using JSON Schema to guide and annotate the diff output with type information, field metadata, and structured change detection.
4
+
5
+ [![Ruby](https://img.shields.io/badge/ruby-%3E%3D%203.2-red.svg)](https://www.ruby-lang.org/)
6
+ [![Gem Version](https://badge.fury.io/rb/json-schema-diff.svg)](https://rubygems.org/gems/json-schema-diff)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ Perfect for comparing structured CLI output from security tools like zizmor and capslock across versions to highlight when security issues have been introduced or resolved.
10
+
11
+ ## Features
12
+
13
+ - **Schema-guided diffing** - Uses JSON Schema metadata to provide context for changes
14
+ - **Multiple output formats** - Pretty colorized output for humans, JSON for machines
15
+ - **Smart field filtering** - Automatically detects and can ignore noisy fields (timestamps, UUIDs)
16
+ - **Read-only field support** - Respects `readOnly` schema properties
17
+ - **Nested object and array support** - Handles complex JSON structures
18
+ - **Custom field ignoring** - Ignore specific fields by path
19
+ - **Type and format information** - Shows field types, formats, and enum values from schema
20
+ - **Change categorization** - Clearly identifies additions, removals, and modifications
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'json-schema-diff'
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ ```bash
33
+ bundle install
34
+ ```
35
+
36
+ Or install it yourself as:
37
+
38
+ ```bash
39
+ gem install json-schema-diff
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ### Basic Usage
45
+
46
+ ```bash
47
+ json-schema-diff schema.json old.json new.json
48
+ ```
49
+
50
+ ### Output Formats
51
+
52
+ ```bash
53
+ # Pretty colorized output (default)
54
+ json-schema-diff --format pretty schema.json old.json new.json
55
+
56
+ # Machine-readable JSON output
57
+ json-schema-diff --format json schema.json old.json new.json
58
+
59
+ # Disable colors
60
+ json-schema-diff --no-color schema.json old.json new.json
61
+ ```
62
+
63
+ ### Ignoring Fields
64
+
65
+ ```bash
66
+ # Ignore specific fields (comma-separated)
67
+ json-schema-diff --ignore-fields timestamp,scan_id,duration_ms schema.json old.json new.json
68
+ ```
69
+
70
+ ### CLI Options
71
+
72
+ ```bash
73
+ # Show help
74
+ json-schema-diff --help
75
+
76
+ # Show version
77
+ json-schema-diff --version
78
+
79
+ # All options
80
+ json-schema-diff [OPTIONS] SCHEMA OLD_JSON NEW_JSON
81
+
82
+ Options:
83
+ -f, --format FORMAT Output format (pretty, json)
84
+ -i, --ignore-fields FIELDS Comma-separated list of field paths to ignore
85
+ --[no-]color Enable/disable colored output (default: enabled)
86
+ -h, --help Show help message
87
+ -v, --version Show version
88
+ ```
89
+
90
+ ### Example Output
91
+
92
+ ```
93
+ JSON Schema Diff Results
94
+ ==================================================
95
+
96
+ ADDITIONS (1):
97
+
98
+ issues[3] (object)
99
+ + Added: {"id":"ZIZ004","severity":"critical","category":"crypto",...}
100
+
101
+ REMOVALS (1):
102
+
103
+ issues[2] (object)
104
+ Title: Security Issue
105
+ + Removed: {"id":"ZIZ003","severity":"medium","category":"misc",...}
106
+
107
+ MODIFICATIONS (2):
108
+
109
+ metadata.version (string)
110
+ Title: Tool Version
111
+ - Old: "1.2.0"
112
+ + New: "1.3.0"
113
+
114
+ summary.by_severity.critical (integer)
115
+ Title: Critical Issues
116
+ - Old: 1
117
+ + New: 2
118
+
119
+ SUMMARY:
120
+ Total changes: 4
121
+ Noisy fields: 2
122
+ ```
123
+
124
+ ### Ruby API
125
+
126
+ ```ruby
127
+ require 'json/schema/diff'
128
+
129
+ # Parse schema
130
+ schema = Json::Schema::Diff::SchemaParser.new('schema.json')
131
+
132
+ # Create comparer with optional ignore fields
133
+ comparer = Json::Schema::Diff::Comparer.new(schema, ['timestamp', 'scan_id'])
134
+
135
+ # Load and compare JSON files
136
+ old_json = JSON.parse(File.read('old.json'))
137
+ new_json = JSON.parse(File.read('new.json'))
138
+
139
+ changes = comparer.compare(old_json, new_json)
140
+
141
+ # Format results
142
+ formatter = Json::Schema::Diff::Formatter.new('pretty', true)
143
+ puts formatter.format(changes)
144
+ ```
145
+
146
+ ## Schema Features
147
+
148
+ ### Supported JSON Schema Properties
149
+
150
+ - **type** - Field data type (string, integer, object, array, etc.)
151
+ - **title** - Human-readable field name
152
+ - **description** - Field description
153
+ - **format** - Field format (date-time, uuid, email, etc.)
154
+ - **enum** - Allowed values for the field
155
+ - **readOnly** - Fields marked as read-only are ignored in diffs
156
+
157
+ ### Noisy Field Detection
158
+
159
+ The gem automatically detects potentially noisy fields based on:
160
+
161
+ - **Format hints**: `date-time`, `date`, `time`, `uuid` formats
162
+ - **Value patterns**: UUID strings, ISO timestamp strings
163
+ - **Schema annotations**: Fields marked as `readOnly`
164
+
165
+ ### Example Schema
166
+
167
+ ```json
168
+ {
169
+ "$schema": "http://json-schema.org/draft-07/schema#",
170
+ "title": "Security Report Schema",
171
+ "type": "object",
172
+ "properties": {
173
+ "metadata": {
174
+ "type": "object",
175
+ "properties": {
176
+ "tool": {
177
+ "type": "string",
178
+ "title": "Tool Name",
179
+ "enum": ["zizmor", "capslock", "semgrep"]
180
+ },
181
+ "timestamp": {
182
+ "type": "string",
183
+ "format": "date-time",
184
+ "readOnly": true
185
+ }
186
+ }
187
+ },
188
+ "issues": {
189
+ "type": "array",
190
+ "items": {
191
+ "type": "object",
192
+ "properties": {
193
+ "severity": {
194
+ "type": "string",
195
+ "enum": ["critical", "high", "medium", "low"]
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ ```
203
+
204
+ ## Use Cases
205
+
206
+ ### Security Tool Comparison
207
+
208
+ Compare security scan results across tool versions:
209
+
210
+ ```bash
211
+ # Compare zizmor audit results (official schema)
212
+ # See: https://github.com/zizmorcore/zizmor
213
+ json-schema-diff examples/zizmor/zizmor.schema.json zizmor-v0.1.0.json zizmor-v0.2.0.json
214
+ ```
215
+
216
+ **Example Output:**
217
+ ```
218
+ JSON Schema Diff Results
219
+ ==================================================
220
+
221
+ ADDITIONS (1):
222
+
223
+ [2]
224
+ + Added: {"ident":"hardcoded-credentials","desc":"Hardcoded credentials detected",...}
225
+
226
+ MODIFICATIONS (2):
227
+
228
+ [1].determinations.confidence
229
+ - Old: "Medium"
230
+ + New: "High"
231
+
232
+ [1].determinations.severity
233
+ - Old: "Medium"
234
+ + New: "High"
235
+
236
+ SUMMARY:
237
+ Total changes: 3
238
+ ```
239
+
240
+ ```bash
241
+ # Compare capslock capability analysis
242
+ # See: https://github.com/google/capslock
243
+ json-schema-diff examples/capslock/capslock.schema.json capslock-v0.5.0.json capslock-v0.6.0.json
244
+ ```
245
+
246
+ **Example Output:**
247
+ ```
248
+ JSON Schema Diff Results
249
+ ==================================================
250
+
251
+ ADDITIONS (3):
252
+
253
+ capability_info[2]
254
+ + Added: {"package_name":"github.com/example/myapp/crypto","capability":"CAPABILITY_ARBITRARY_EXECUTION",...}
255
+
256
+ module_info[2]
257
+ + Added: {"path":"github.com/suspicious/lib","version":"v1.2.3"}
258
+
259
+ package_info[2]
260
+ + Added: {"path":"github.com/example/myapp/crypto","ignored_files":[]}
261
+
262
+ MODIFICATIONS (2):
263
+
264
+ module_info[0].version
265
+ - Old: "v1.0.0"
266
+ + New: "v1.1.0"
267
+
268
+ module_info[1].version
269
+ - Old: "v1.8.0"
270
+ + New: "v1.8.1"
271
+
272
+ SUMMARY:
273
+ Total changes: 5
274
+ ```
275
+
276
+ ### CI/CD Integration
277
+
278
+ Integrate into your CI pipeline to track security improvements:
279
+
280
+ ```bash
281
+ #!/bin/bash
282
+ # Run zizmor security scan
283
+ zizmor --format json > zizmor-current.json
284
+
285
+ # Compare with previous scan using official schema
286
+ if [ -f zizmor-previous.json ]; then
287
+ json-schema-diff examples/zizmor/zizmor.schema.json zizmor-previous.json zizmor-current.json --format json > security-diff.json
288
+ fi
289
+
290
+ # Archive current scan for next comparison
291
+ cp zizmor-current.json zizmor-previous.json
292
+
293
+ # Run capslock capability analysis
294
+ capslock -output json > capslock-current.json
295
+ if [ -f capslock-previous.json ]; then
296
+ json-schema-diff examples/capslock/capslock.schema.json capslock-previous.json capslock-current.json --format json > capability-diff.json
297
+ fi
298
+ cp capslock-current.json capslock-previous.json
299
+ ```
300
+
301
+ **Example JSON Output for Automation:**
302
+ ```json
303
+ [
304
+ {
305
+ "path": "[1].determinations.severity",
306
+ "change_type": "modification",
307
+ "old_value": "Medium",
308
+ "new_value": "High",
309
+ "field_info": {},
310
+ "is_noisy": false
311
+ },
312
+ {
313
+ "path": "[2]",
314
+ "change_type": "addition",
315
+ "old_value": null,
316
+ "new_value": {
317
+ "ident": "hardcoded-credentials",
318
+ "desc": "Hardcoded credentials detected",
319
+ "determinations": {
320
+ "confidence": "High",
321
+ "severity": "High"
322
+ }
323
+ },
324
+ "field_info": {},
325
+ "is_noisy": false
326
+ }
327
+ ]
328
+ ```
329
+
330
+ ### Configuration Monitoring
331
+
332
+ Track changes in complex configuration files using SchemaStore schemas:
333
+
334
+ ```bash
335
+ # Monitor package.json changes
336
+ curl -s https://json.schemastore.org/package.json > package.schema.json
337
+ json-schema-diff --ignore-fields version package.schema.json old-package.json new-package.json
338
+ ```
339
+
340
+ **Example Output:**
341
+ ```
342
+ JSON Schema Diff Results
343
+ ==================================================
344
+
345
+ ADDITIONS (1):
346
+
347
+ dependencies.lodash (string)
348
+ Title: Dependency
349
+ + Added: "^4.17.21"
350
+
351
+ MODIFICATIONS (1):
352
+
353
+ scripts.test (string)
354
+ Title: Script Command
355
+ - Old: "jest"
356
+ + New: "jest --coverage"
357
+
358
+ SUMMARY:
359
+ Total changes: 2
360
+ ```
361
+
362
+ ```bash
363
+ # Track GitHub Actions workflow changes
364
+ curl -s https://json.schemastore.org/github-workflow.json > workflow.schema.json
365
+ json-schema-diff workflow.schema.json old-workflow.json new-workflow.json
366
+
367
+ # Monitor Docker Compose changes
368
+ curl -s https://json.schemastore.org/docker-compose.yml > compose.schema.json
369
+ json-schema-diff compose.schema.json old-compose.json new-compose.json
370
+ ```
371
+
372
+ ### Development Workflow Analysis
373
+
374
+ Compare development tool outputs with proper schema context:
375
+
376
+ ```bash
377
+ # ESLint configuration changes
378
+ curl -s https://json.schemastore.org/eslintrc.json > eslint.schema.json
379
+ json-schema-diff eslint.schema.json old-eslintrc.json new-eslintrc.json
380
+
381
+ # TypeScript configuration tracking
382
+ curl -s https://json.schemastore.org/tsconfig.json > tsconfig.schema.json
383
+ json-schema-diff tsconfig.schema.json old-tsconfig.json new-tsconfig.json
384
+ ```
385
+
386
+ ## Development
387
+
388
+ After checking out the repo, run `bin/setup` to install dependencies. Then:
389
+
390
+ ```bash
391
+ # Run tests
392
+ rake test
393
+
394
+ # Run with example files
395
+ bundle exec exe/json-schema-diff examples/security-report.schema.json examples/old-report.json examples/new-report.json
396
+
397
+ # Install locally
398
+ bundle exec rake install
399
+ ```
400
+
401
+ ## Examples
402
+
403
+ The `examples/` directory contains organized examples for different security tools:
404
+
405
+ ### Tool-Specific Examples
406
+
407
+ - **`examples/zizmor/`** - [Zizmor](https://github.com/zizmorcore/zizmor) GitHub Actions security auditor
408
+ - `zizmor.schema.json` - Official zizmor JSON output schema (v1)
409
+ - `zizmor-v0.1.0.json` / `zizmor-v0.2.0.json` - Sample audit reports across versions
410
+
411
+ - **`examples/capslock/`** - [Capslock](https://github.com/google/capslock) Go capability analysis
412
+ - `capslock.schema.json` - Google's Capslock capability analysis schema
413
+ - `capslock-v0.5.0.json` / `capslock-v0.6.0.json` - Sample capability reports across versions
414
+
415
+ - **`examples/generic/`** - Generic security tool template
416
+ - `security-report.schema.json` - Generic security analysis reports schema
417
+ - `report-v1.2.0.json` / `report-v1.3.0.json` - Sample security reports
418
+
419
+ ### Try the Examples
420
+
421
+ ```bash
422
+ # Zizmor security audit comparison (official schema)
423
+ json-schema-diff examples/zizmor/zizmor.schema.json examples/zizmor/zizmor-v0.1.0.json examples/zizmor/zizmor-v0.2.0.json
424
+
425
+ # Capslock capability analysis
426
+ json-schema-diff examples/capslock/capslock.schema.json examples/capslock/capslock-v0.5.0.json examples/capslock/capslock-v0.6.0.json
427
+
428
+ # Generic security tool comparison
429
+ json-schema-diff examples/generic/security-report.schema.json examples/generic/report-v1.2.0.json examples/generic/report-v1.3.0.json
430
+ ```
431
+
432
+ ### Using Existing Schemas
433
+
434
+ The gem works with any valid JSON Schema. You can use schemas from:
435
+
436
+ - **[SchemaStore.org](https://www.schemastore.org/)** - Hundreds of schemas for popular tools and configurations
437
+ - **Tool documentation** - Many CLI tools provide JSON schemas for their output
438
+ - **Custom schemas** - Create your own schemas for proprietary formats
439
+
440
+ For example, with SchemaStore schemas:
441
+
442
+ ```bash
443
+ # Compare GitHub Actions workflows
444
+ curl -o github-workflow.schema.json https://json.schemastore.org/github-workflow.json
445
+ json-schema-diff github-workflow.schema.json old-workflow.yml new-workflow.yml
446
+
447
+ # Compare package.json files
448
+ curl -o package.schema.json https://json.schemastore.org/package.json
449
+ json-schema-diff package.schema.json old-package.json new-package.json
450
+
451
+ # Compare Docker Compose files
452
+ curl -o compose.schema.json https://json.schemastore.org/docker-compose.yml
453
+ json-schema-diff compose.schema.json old-compose.yml new-compose.yml
454
+ ```
455
+
456
+ ## Contributing
457
+
458
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/andrew/json-schema-diff>.
459
+
460
+ 1. Fork it
461
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
462
+ 3. Make your changes
463
+ 4. Add tests for your changes
464
+ 5. Ensure all tests pass (`rake test`)
465
+ 6. Commit your changes (`git commit -am 'Add some feature'`)
466
+ 7. Push to the branch (`git push origin my-new-feature`)
467
+ 8. Create new Pull Request
468
+
469
+ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
470
+
471
+ ## Security
472
+
473
+ For security issues, please see our [Security Policy](SECURITY.md).
474
+
475
+ ## License
476
+
477
+ This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
478
+
479
+ ## Changelog
480
+
481
+ See [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes and releases.
482
+
483
+ ## Code of Conduct
484
+
485
+ Everyone interacting in the json-schema-diff project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
data/SECURITY.md ADDED
@@ -0,0 +1,143 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ We actively support and provide security updates for the following versions:
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 1.x.x | :white_check_mark: |
10
+ | < 1.0 | :x: |
11
+
12
+ ## Reporting a Vulnerability
13
+
14
+ The json-schema-diff team takes security seriously. If you discover a security vulnerability, please follow these steps:
15
+
16
+ ### 1. Do NOT Create a Public Issue
17
+
18
+ Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.
19
+
20
+ ### 2. Report Privately
21
+
22
+ Send a detailed report to **andrew@ecosyste.ms** with:
23
+
24
+ - **Subject**: `[SECURITY] json-schema-diff - [Brief Description]`
25
+ - **Description** of the vulnerability
26
+ - **Steps to reproduce** the issue
27
+ - **Potential impact** assessment
28
+ - **Suggested fix** (if you have one)
29
+ - **Your contact information** for follow-up
30
+
31
+ ### 3. What to Include
32
+
33
+ Please provide as much information as possible:
34
+
35
+ ```
36
+ - Affected versions
37
+ - Attack vectors
38
+ - Proof of concept (if safe to share)
39
+ - Environmental details (Ruby version, OS, etc.)
40
+ - Any relevant configuration details
41
+ ```
42
+
43
+ ## Response Process
44
+
45
+ ### Initial Response
46
+
47
+ - **24-48 hours**: We will acknowledge receipt of your report
48
+ - **Initial assessment**: Within 1 week of acknowledgment
49
+ - **Status updates**: Weekly until resolution
50
+
51
+ ### Investigation
52
+
53
+ We will:
54
+ 1. **Confirm** the vulnerability exists
55
+ 2. **Assess** the severity and impact
56
+ 3. **Develop** a fix and mitigation strategy
57
+ 4. **Test** the fix thoroughly
58
+ 5. **Coordinate** disclosure timeline
59
+
60
+ ### Resolution
61
+
62
+ - **High/Critical**: Immediate fix and release
63
+ - **Medium**: Fix within 30 days
64
+ - **Low**: Fix in next regular release cycle
65
+
66
+ ## Security Considerations
67
+
68
+ ### Input Validation
69
+
70
+ The json-schema-diff library processes JSON files and JSON Schema documents:
71
+
72
+ - **JSON parsing**: Validates JSON syntax and structure
73
+ - **Schema validation**: Ensures schema conforms to JSON Schema specification
74
+ - **Path traversal**: Validates file paths to prevent directory traversal attacks
75
+ - **Memory usage**: Guards against extremely large JSON files that could cause DoS
76
+
77
+ ### Potential Risk Areas
78
+
79
+ Areas that warrant security attention:
80
+
81
+ 1. **JSON parsing**: Malformed JSON could cause parsing errors or crashes
82
+ 2. **Schema complexity**: Deeply nested schemas could cause stack overflow
83
+ 3. **File operations**: Reading files requires proper path validation
84
+ 4. **Regular expressions**: Pattern matching should be safe from ReDoS attacks
85
+
86
+ ### Safe Usage Practices
87
+
88
+ When using json-schema-diff in applications:
89
+
90
+ - **Validate input**: Don't trust user-provided file paths or JSON content
91
+ - **Handle errors**: Properly catch and handle parsing exceptions
92
+ - **Limit resources**: Implement timeouts and memory limits for large files
93
+ - **Sanitize output**: Be careful when displaying diff results in web applications
94
+
95
+ ## Disclosure Policy
96
+
97
+ ### Coordinated Disclosure
98
+
99
+ We follow coordinated disclosure principles:
100
+
101
+ 1. **Private reporting** allows us to fix issues before public disclosure
102
+ 2. **Reasonable timeline** for fixes (typically 90 days maximum)
103
+ 3. **Credit and recognition** for responsible reporters
104
+ 4. **Public disclosure** after fixes are available
105
+
106
+ ### Public Disclosure
107
+
108
+ After a fix is released:
109
+
110
+ 1. **Security advisory** published on GitHub
111
+ 2. **CVE requested** if applicable
112
+ 3. **Release notes** include security information
113
+ 4. **Community notification** through appropriate channels
114
+
115
+ ## Security Updates
116
+
117
+ ### Notification Channels
118
+
119
+ Security updates are announced through:
120
+
121
+ - **GitHub Security Advisories**
122
+ - **RubyGems security alerts**
123
+ - **Release notes and CHANGELOG**
124
+ - **Project README updates**
125
+
126
+ ### Update Recommendations
127
+
128
+ To stay secure:
129
+
130
+ - **Monitor** our security advisories
131
+ - **Update regularly** to the latest version
132
+ - **Review** release notes for security fixes
133
+ - **Subscribe** to GitHub notifications for this repository
134
+
135
+ ## Contact Information
136
+
137
+ **Security Contact**: andrew@ecosyste.ms
138
+
139
+ **Response Time**: We aim to acknowledge security reports within 24-48 hours
140
+
141
+ ---
142
+
143
+ Thank you for helping keep json-schema-diff and its users safe!
@@ -0,0 +1,27 @@
1
+ # Capslock Examples
2
+
3
+ This directory contains examples for [Capslock](https://github.com/google/capslock), Google's Go capability analysis tool.
4
+
5
+ ## Files
6
+
7
+ - `capslock.schema.json` - Official Capslock JSON output schema
8
+ - `capslock-v0.5.0.json` - Sample capability report from capslock v0.5.0
9
+ - `capslock-v0.6.0.json` - Sample capability report from capslock v0.6.0
10
+
11
+ ## Example Usage
12
+
13
+ ```bash
14
+ # Compare capability analysis between versions
15
+ json-schema-diff capslock.schema.json capslock-v0.5.0.json capslock-v0.6.0.json
16
+
17
+ # Real-world usage with actual capslock output
18
+ capslock -output json > current-capabilities.json
19
+ json-schema-diff capslock.schema.json previous-capabilities.json current-capabilities.json
20
+ ```
21
+
22
+ ## Key Changes Demonstrated
23
+
24
+ - **New dangerous capability**: v0.6.0 introduces `CAPABILITY_ARBITRARY_EXECUTION` via transitive dependency
25
+ - **Dependency tracking**: New suspicious library `github.com/suspicious/lib@v1.2.3` added
26
+ - **Call path analysis**: Detailed function call chains showing how capabilities are reached
27
+ - **Module version updates**: Tracking dependency version changes across releases