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

Validate the format of examples #766

Open
tatomyr opened this issue Jul 13, 2022 · 9 comments · May be fixed by #1820
Open

Validate the format of examples #766

tatomyr opened this issue Jul 13, 2022 · 9 comments · May be fixed by #1820
Labels
governance Issues relating to problems with or requests for API governance/linting/decorating p3 Type: Enhancement

Comments

@tatomyr
Copy link
Contributor

tatomyr commented Jul 13, 2022

Is your feature request related to a problem? Please describe.

Consider this definition sample:

openapi: 3.0.0

components:
  parameters:
    foo:
      in: query
      name: foo
      schema:
        type: string
        format: ipv4
      example: wrong

Although the example is wrong, linter doesn't recognise this.

Describe the solution you'd like
It would be great if no-invalid-parameter-examples rule could take format into account as well.

Describe alternatives you've considered
None

Additional context

See more details here.

@tatomyr tatomyr changed the title Linter does not validate examples against the schema Linter does not fully validate examples Jul 13, 2022
@lornajane lornajane added the governance Issues relating to problems with or requests for API governance/linting/decorating label Nov 17, 2023
@tatomyr
Copy link
Contributor Author

tatomyr commented Mar 5, 2024

See also: #1470

@LasneF
Copy link

LasneF commented Mar 6, 2024

notice that the partial support of format is a pain , because when using in conjonction with oneOf the current implementation make the validation failing in all case when adding a sample as it patches always both item of the oneOf

    maturity:
      description: Maturity date or tenor 
      type: string
      oneOf:
        - format: date
        - pattern: ^\d+[YyMmWwDd]|\d+[YyMmWwDd]\d+[YyMmWwDd]

@tatomyr
Copy link
Contributor Author

tatomyr commented Apr 25, 2024

A similar issue.

@adamaltman
Copy link
Member

Same issue exists with schema examples.

Maybe we should support format validation one-by-one? Starting with the most obvious formats like date, date-time, pattern?

@tatomyr
Copy link
Contributor Author

tatomyr commented Apr 25, 2024

Maybe we should support format validation one-by-one? Starting with the most obvious formats like date, date-time, pattern?

Redocly CLI relies on AJV for validating examples, and AJV is supposed to be used together with the ajv-formats plugin to validate formats. It should be comparatively easy to start adding some formats.

However, there is a potential security issue of ReDoS attack:

It is recommended NOT to use "format" keyword implementations with untrusted data, as they may use potentially unsafe regular expressions

So the main issue here, I believe, is to assess the potential security impact.

@LasneF
Copy link

LasneF commented Sep 18, 2024

redocli CLI looks not an appropriate target for a redos Attack, given redocly is used as a linter tooling (meaning validation a file that you are in control) . The worst case i can establish would be some one introducing a poisonned spec with nasty sample in a CICD that could lock the production chain . Usually this kind of attack is used in a runtime mode like an API gateway or a backend code and so not a redocly use case

One remediation can be to applies validation on sample only for the format part and not for the pattern part
This would be already a great step , especially considering the format date for instance , here as the pattern is controled internaly by redocly it should not be something really subject to attacks

then given the the attack vector being to intput a bad pattern , and then a bad sample that make infinite loop, an other remediation ( to check if it is possible) is to apply a time out for exemple validation that would significantly reduce the impact of the attack.

@tatomyr tatomyr changed the title Linter does not fully validate examples Validate the format of examples Sep 18, 2024
@tatomyr
Copy link
Contributor Author

tatomyr commented Sep 25, 2024

@LasneF I think you're right in your assumptions. It's mostly a matter of priorities 😅.

@lornajane
Copy link
Contributor

Since the formats are more like advice than strict types, let's add the ability to not check formats as a configuration setting on the rule.

@LasneF
Copy link

LasneF commented Sep 25, 2024

i would not qualify format or pattern as an advice , but munch more as a constrains , as same as minLength or pattern.
To me format act as a kind of "predefined" pattern to avoid setting the date time complex regular expression .
till the registry is open , it is fair to be open and fluid for unknown format , but for known format that would be nice to have strict validation

i am not 100% sure about what mean Format Assertion , but the feature that would be nice is the implementation of
https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7.2.2

meaning "When the Format-Assertion vocabulary is declared with a value of true, implementations MUST provide full validation support for all of the formats defined by this specificaion."

@tatomyr tatomyr linked a pull request Dec 10, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
governance Issues relating to problems with or requests for API governance/linting/decorating p3 Type: Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants