Skip to content

fix: ensure AddRequestMutator uses appropriate ParameterContents for parameters - #317

Merged
grebnetiew merged 11 commits into
TNO-S3:mainfrom
DC925928496:fix/add-request-mutator-types
Jun 23, 2026
Merged

grebnetiew merged 11 commits into
TNO-S3:mainfrom
DC925928496:fix/add-request-mutator-types

Conversation

@DC925928496

Copy link
Copy Markdown
Contributor

Problem

The AddRequestMutator was inserting raw bytes (ParameterContents::Bytes) for all parameters, regardless of their actual type. This is incorrect for non-bytes parameters (e.g., strings, numbers) because the fuzzer expects parameters to match their specified type (e.g., a string parameter should be a LeafValue(String)). This could lead to type mismatches when the fuzzer attempts to use the parameter values in requests.

Fix

Changed the mutator to generate appropriate default values for parameters:

  • For non-bytes parameters (query, path, header, cookie), we now generate a random string and store it as ParameterContents::LeafValue(SimpleValue::String(s)).
  • For request body parameters that are bytes (e.g., bytes_b64), we keep the existing behavior of using ParameterContents::Bytes.

This ensures that the fuzzer inserts data of the correct type for each parameter, aligning with the ParameterContents enum variants.

Related Issues

Fixes #19

…parameters

The AddRequestMutator was inserting raw bytes for all parameters, which is incorrect for non-bytes parameters (e.g., strings, numbers). This change ensures that parameters are given a default string value (from random bytes) when their type is not explicitly bytes, aligning with the ParameterContents enum variants.

This addresses issue #19: \"AddRequestMutator inserts bytes instead of correct type of data\".
@ThomasTNO
ThomasTNO requested a review from grebnetiew May 26, 2026 06:44
Comment thread src/openapi_mutator/add_request.rs Resolved
@ThomasTNO

Copy link
Copy Markdown
Member

Thanks @DC925928496, I cleaned your commit. Furthermore:

The fix is partially correct but incomplete.

What it fixes:
The parameters section previously used ParameterContents::Bytes(new_rand_input(rand)). The change now converts those random bytes to a UTF-8 lossy string and wraps them in ParameterContents::LeafValue(SimpleValue::String(s)), which is a valid ParameterContents variant for path/query parameters.

What it doesn't fix:

  1. Parameter type awareness is missing. Random bytes run through from_utf8_lossy produce strings riddled with \u{...} replacement characters. A truly correct fix would inspect the parameter's schema type (e.g., integer, boolean, number) and generate a correctly typed value, not always a string.
  2. Body fields still use raw Bytes. The .map(|name| (name.clone(), ParameterContents::Bytes(new_rand_input(rand)))) in body_contents is unchanged. If the same issue applies to body field contents, that part remains broken.

@ThomasTNO
ThomasTNO requested a review from Jelle-Nauta May 27, 2026 14:53
@ThomasTNO

Copy link
Copy Markdown
Member

Suggested an alternative fix

@grebnetiew grebnetiew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me! Thanks for spotting this.

@grebnetiew
grebnetiew enabled auto-merge (squash) June 23, 2026 10:45
@grebnetiew
grebnetiew merged commit ef934aa into TNO-S3:main Jun 23, 2026
10 checks passed
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.

AddRequestMutator inserts bytes instead of correct type of data

3 participants