Skip to content

Commit

Permalink
Fixes stoplightio#49 by adding rules for JSON Schema unevaluatedPrope…
Browse files Browse the repository at this point in the history
…rties keyword
  • Loading branch information
DavidBiesack committed Aug 17, 2023
1 parent 343043b commit fc53df0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,27 @@ export default {
],
},

/**
* @author: David Biesack <https://github.com/davidbiesack>,
* derived from owasp:api6:2019-no-additionalProperties
* @see: https://github.com/italia/api-oas-checker/blob/master/security/objects.yml
*/
"owasp:api6:2019-no-unevaluatedProperties": {
message:
"If the unevaluatedProperties keyword is used it must be set to false.",
description:
"By default JSON Schema allows unevaluated properties, which can potentially lead to mass assignment issues, where unspecified fields are passed to the API without validation. Disable them with `unevaluatedProperties: false` or add `maxProperties`.",
severity: DiagnosticSeverity.Warning,
formats: [oas3],
given: '$..[?(@ && @.type=="object" && @.unevaluatedProperties)]',
then: [
{
field: "unevaluatedProperties",
function: falsy,
},
],
},

/**
* @author: Roberto Polli <https://github.com/ioggstream>
* @see: https://github.com/italia/api-oas-checker/blob/master/security/objects.yml
Expand All @@ -711,6 +732,27 @@ export default {
],
},

/**
* @author: David Biesack <https://github.com/davidbiesack>,
* derived from owasp:api6:2019-constrained-additionalProperties
* @see: https://github.com/italia/api-oas-checker/blob/master/security/objects.yml
*/
"owasp:api6:2019-constrained-unevaluatedProperties": {
message: "Objects should not allow unconstrained unevaluatedProperties.",
description:
"By default JSON Schema allows unevaluated properties, which can potentially lead to mass assignment issues, where unspecified fields are passed to the API without validation. Disable them with `unevaluatedProperties: false` or add `maxProperties`",
severity: DiagnosticSeverity.Warning,
formats: [oas3],
given:
'$..[?(@ && @.type=="object" && @.unevaluatedProperties && @.unevaluatedProperties!=true && @.unevaluatedProperties!=false )]',
then: [
{
field: "maxProperties",
function: defined,
},
],
},

/**
* API7:2019 — Security misconfiguration
*
Expand Down

0 comments on commit fc53df0

Please sign in to comment.