Skip to content

🔒 Fix DoS vulnerability in JSON file loading#110

Open
adcondev wants to merge 2 commits intomasterfrom
fix-json-dos-vulnerability-42113601145997800
Open

🔒 Fix DoS vulnerability in JSON file loading#110
adcondev wants to merge 2 commits intomasterfrom
fix-json-dos-vulnerability-42113601145997800

Conversation

@adcondev
Copy link
Owner

This PR addresses a potential Denial of Service (DoS) vulnerability in the CLI's JSON loading mechanism.
Previously, os.ReadFile would load the entire file into memory without checking its size.
This fix implements a strict size limit of 10MB using io.LimitReader and os.Stat checks.

Changes:

  • Added MaxJSONSize (10MB) to pkg/constants.
  • Refactored loadJSON in cmd/poster/parsing.go to securely read files.
  • Added cmd/poster/parsing_test.go to verify the fix with large and boundary-case files.

PR created automatically by Jules for task 42113601145997800 started by @adcondev

- Add `MaxJSONSize` constant (10MB) to `pkg/constants`.
- Secure `loadJSON` in `cmd/poster/parsing.go` to use `os.Open` + `io.LimitReader`.
- Add test coverage for size limits in `cmd/poster/parsing_test.go`.

Fixes uncontrolled resource consumption vulnerability where large files could cause OOM.

Co-authored-by: adcondev <38170282+adcondev@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings February 12, 2026 16:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

👋 Thanks for opening this PR, @adcondev!

Here's what will happen next:

  • 🤖 Automated checks will run
  • 🏷️ Labels will be added automatically
  • 👀 A maintainer will review your changes

Please make sure:

  • ✅ All tests pass
  • 📝 The PR title follows conventional commits
  • 📋 The PR template is filled out completely

@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

⚡ Benchmark Results

📈 Performance Comparison

📊 Click to expand detailed results

Current Branch Results

BenchmarkNewDocument-4    	1000000000	         0.3127 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 3660445	       333.1 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  396436	      2992 ns/op	    1809 B/op	      25 allocs/op
BenchmarkToJSON-4         	  513376	      2151 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  492578	      2314 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	   94568	     12663 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  421446	      2787 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  277227	      4206 ns/op	     944 B/op	      21 allocs/op
BenchmarkTextCommandParsing-4       	  524451	      2149 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  240616	      4984 ns/op	    1000 B/op	      29 allocs/op
BenchmarkParseHexString-4           	 8289812	       143.4 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 6656040	       179.8 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	369813058	         3.274 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	35282823	        37.48 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	14334823	        83.02 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  498592	      2411 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  138847	      8534 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     573	   1955161 ns/op	 3469937 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     302	   3795892 ns/op	 5481085 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     135	   8769475 ns/op	 5235276 B/op	  230723 allocs/op

Base Branch Results

BenchmarkNewDocument-4    	1000000000	         0.3124 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 3641227	       336.4 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  404083	      2801 ns/op	    1809 B/op	      25 allocs/op
BenchmarkToJSON-4         	  540406	      2115 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  477943	      2414 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	   90234	     13552 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  406212	      2848 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  263967	      4372 ns/op	     944 B/op	      21 allocs/op
BenchmarkTextCommandParsing-4       	  506535	      2316 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  238208	      4946 ns/op	    1000 B/op	      29 allocs/op
BenchmarkParseHexString-4           	 8677948	       137.6 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 6614784	       180.3 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	367252376	         3.291 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	32234542	        38.82 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	14350474	        82.54 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  499629	      2418 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  138145	      8637 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     604	   1930240 ns/op	 3469946 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     319	   3729421 ns/op	 5481083 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     134	   8897972 ns/op	 5235275 B/op	  230723 allocs/op

💡 Note: Use benchstat for statistical comparison

🎯 Summary

  • Total Benchmarks: 32
  • Average Speed: 2716616 ns/op
  • Average Memory: 2396935 B/op
  • Average Allocations: 41093 allocs/op

- Add `MaxJSONSize` constant (10MB) to `pkg/constants`.
- Secure `loadJSON` in `cmd/poster/parsing.go` to use `os.Open` + `io.LimitReader`.
- Add test coverage for size limits in `cmd/poster/parsing_test.go`.

Fixes uncontrolled resource consumption vulnerability where large files could cause OOM.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant