RepreZen / KaiZen-OpenApi-Parser

High-performance Parser, Validator, and Java Object Model for OpenAPI 3.x
130 stars 31 forks source link

Create tighter URL field validations #221

Open andylowry opened 6 years ago

andylowry commented 6 years ago

Recent implementation work resolving #209 has resulted in a significant weakening of URL validations. The reasons are:

So that's one problem with URL validation - it's probably allowing relative URLs where they're not intended.

The second problem is that the current validation implementation is very weak, especially in the case of relative URLs.

The problems are that:

What I propose for this is to not rely at all on URL constructors. Instead, use two steps:

  1. Use regex or other means to verify that the string conforms to the general syntactic requirements of the applicable RFC. This should handle both absolute and relative URLs, and the check should also permit us to distinguish the two.
  2. If step 1 passes and the URL is absolute, use Apache commons-validation to perform further validation. This will include scheme-specific checks for several common schemes.
  3. If step 1 succeeds and step 2 fails due to unrecognized scheme, validation passes.
  4. If step 1 succeeds and the URL is relative validation passes or fails depending on whether relative URLs are permitted.
  5. In all other cases, validation fails.