Skip to content
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

Validation error for HttpHeadersScanAttemptAsJson when using API #554

Closed
CampinCarl opened this issue Feb 9, 2022 · 2 comments
Closed

Comments

@CampinCarl
Copy link

Describe the Bug
I'm getting a pydantic.error_wrappers.ValidationError error message when attempting to save scan results as JSON using the API.

Steps to Reproduce
Steps to reproduce the behavior:

  1. Install SSLyze using pip, i.e., pip install sslyze
  2. Adapt the api_sample.py script, e.g., Example of SSLyze based scan that results in a ValidationError (Gist)
  3. Run and observe error on the ServerScanResultAsJson.from_orm(...) method

Example Error

Traceback (most recent call last):
  File "C:\Testing\scan.py", line 314, in <module>
    main()
  File "C:\Testing\scan.py", line 159, in main
    list_json_format_scan_results.append(ServerScanResultAsJson.from_orm(server_scan_result))
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\site-packages\sslyze\json\json_output.py", line 195, in from_orm
    scan_result_as_json = AllScanCommandsAttemptsAsJson.from_orm(server_scan_result.scan_result)
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\site-packages\sslyze\json\json_output.py", line 91, in from_orm
    all_scan_commands_attempts_json[field_name] = scan_command_attempt_json_cls(
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\site-packages\pydantic\main.py", line 406, in __init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for HttpHeadersScanAttemptAsJson
result
  asdict() should be called on dataclass instances (type=type_error)

Expected behavior
Scan result parses to JSON successfully, to be written out to a JSON file later.

Python Environment

  • OS: Windows 10 21H1
  • Python version: 3.10.0

PIP Package List
From a virtual environment, pip install sslyze results in this package list.

Package Version
cffi 1.15.0
cryptography 36.0.1
nassl 4.0.2
pip 21.2.3
pycparser 2.21
pydantic 1.8.2
setuptools 57.4.0
sslyze 5.0.2
tls-parser 2.0.0
typing_extensions 4.0.1

Additional context
This seems to be a per site issue, i.e., some sites work and others don't. That said, I can't replicate the error for the same sites when using the command line version. Perhaps this is an issue with one of the scan modules? It's my understanding that the API uses all modules by default vs. the smaller set of modules for the command line version.

@CampinCarl
Copy link
Author

Yup, looks like this might be an issue with the HTTP headers module?

C:\>sslyze.exe --quiet --json_out foo.json --http_headers support.google.com docs.microsoft.com docs.ubuntu.com
Traceback (most recent call last):
  File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\Scripts\sslyze.exe\__main__.py", line 7, in <module>
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\site-packages\sslyze\__main__.py", line 76, in main
    server_scan_results=[ServerScanResultAsJson.from_orm(result) for result in all_server_scan_results],
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\site-packages\sslyze\__main__.py", line 76, in <listcomp>
    server_scan_results=[ServerScanResultAsJson.from_orm(result) for result in all_server_scan_results],
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\site-packages\sslyze\json\json_output.py", line 195, in from_orm
    scan_result_as_json = AllScanCommandsAttemptsAsJson.from_orm(server_scan_result.scan_result)
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\site-packages\sslyze\json\json_output.py", line 91, in from_orm
    all_scan_commands_attempts_json[field_name] = scan_command_attempt_json_cls(
  File "C:\Users\Foo\AppData\Roaming\Python\Python310\site-packages\pydantic\main.py", line 406, in __init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for HttpHeadersScanAttemptAsJson
result
  asdict() should be called on dataclass instances (type=type_error)

@nabla-c0d3
Copy link
Owner

Thanks for the report. This was fixed in v5.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants