Syslifters / reptor

Other
10 stars 3 forks source link

Error in Parsing Integer Values in TOML Configuration for Custom Plugin #173

Open c-leitner opened 2 months ago

c-leitner commented 2 months ago

Description:

I am encountering an issue with the TOML configuration when trying to pass integer values to a finding field with a custom written plugin. When the integer field (testfield) is included in the TOML file, the parsing fails, and an error is generated. However, string values are parsed and handled correctly.

Steps to Reproduce:

  1. Create in the design Template a finding field as an integer. In my case the following structure was created. ciscatfinding(list) -> object -> name(string), testfield(integer). Define in the TOML-File of the Plugin the following:

ciscatfinding = [{name="<!--{{data.passed}}-->", testfield=<!--{{data.fail}}-->}]

  1. Ensure that data.passed is a string and data.fail is an integer.
  2. Run the plugin

Expected Behavior:

The TOML file should be parsed without errors, and both fields should be correctly filled with values from the data placeholders.

Actual Behavior:

An error occurs when loading the TOML finding template: WARNING Error while loading toml finding template /home/user/.sysreptor/plugins/ciscatpro/findings/ciscat.toml.
If the integer field testfield is removed, the finding is created successfully with the name field correctly pre-filled.

Additional Information:

The issue seems related specifically to integer handling in the TOML configuration.

aronmolnar commented 2 months ago

Yes, this is currently not possible, unfortunately.

The reason is that reptor first loads the toml and therefore your template must have a valid format. testfield=<!--{{data.fail}}-->, however, is no valid toml because the value is a string and strings must be enclosed with quotes.

The quickest workaround would be to enclose the value with quotes (testfield="<!--{{data.fail}}-->") and to transform the field type to string.

I will, however, have a look if we can cast int values to numbers to make it compatible with number fields.