Skip to content

Add option to write output to file - #69

Open
0xBigfish wants to merge 5 commits into
santoru:masterfrom
0xBigfish:feature/write-to-file
Open

0xBigfish wants to merge 5 commits into
santoru:masterfrom
0xBigfish:feature/write-to-file

Conversation

@0xBigfish

Copy link
Copy Markdown

Add the -o and --output flags which can be used to specify a file where the program output is written to. The output is still logged to console even when an output file is specified.
If the --json flag is set the output will be in JSON format.

MarioVilas added a commit to MarioVilas/shcheck that referenced this pull request Jul 24, 2026
0xBigfish and others added 4 commits September 18, 2026 14:55
When no value for the ``default`` parameter is set, ``None``
is used, which is the right choice instead of the misleading ``False``.
Information disclosure lines never reached the file because output_file
was passed to str.format() instead of log(), due to badly placed
parenthesis.

The log() statements in parse_csp() were never adjusted, so CSP output
was never part of the output file.

Fix both bugs by adding the file handle to the global options variable,
instead of passing it as an extra parameter to each log() call.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Open the output file in parse_options() and keep the handle in
options.output_file, so everything log() prints, banner included, lands
in the file. With -j the file still holds only the JSON document.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Parse the file on its own instead of comparing it with stdout, so the
file stays valid JSON regardless of future changes to the stdout format.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@0xBigfish

Copy link
Copy Markdown
Author

I revisited this PR because I found a bug: neither the information disclosure lines nor the CSP where added to the output file.

The bugs are fixed and I refactored the writing logic. My previous approach of adding the output file as a parameter to each and every log() call was replaced by adding the output file to the global options variable.

The logic is now covered by tests. All tests pass

All commits that used AI where marked with the AI as co-author. Unmarked commits did not use AI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants