diff options
Diffstat (limited to 'app/validators')
4 files changed, 240 insertions, 1 deletions
diff --git a/app/validators/json_schema_validator.rb b/app/validators/json_schema_validator.rb index f8c1727035c..fee4a00cec5 100644 --- a/app/validators/json_schema_validator.rb +++ b/app/validators/json_schema_validator.rb @@ -12,6 +12,7 @@ class JsonSchemaValidator < ActiveModel::EachValidator FILENAME_ALLOWED = /\A[a-z0-9_-]*\Z/.freeze FilenameError = Class.new(StandardError) + JSON_VALIDATOR_MAX_DRAFT_VERSION = 4 def initialize(options) raise ArgumentError, "Expected 'filename' as an argument" unless options[:filename] @@ -29,10 +30,18 @@ class JsonSchemaValidator < ActiveModel::EachValidator private def valid_schema?(value) - JSON::Validator.validate(schema_path, value) + if draft_version > JSON_VALIDATOR_MAX_DRAFT_VERSION + JSONSchemer.schema(Pathname.new(schema_path)).valid?(value) + else + JSON::Validator.validate(schema_path, value) + end end def schema_path Rails.root.join('app', 'validators', 'json_schemas', "#{options[:filename]}.json").to_s end + + def draft_version + options[:draft] || JSON_VALIDATOR_MAX_DRAFT_VERSION + end end diff --git a/app/validators/json_schemas/codeclimate.json b/app/validators/json_schemas/codeclimate.json new file mode 100644 index 00000000000..56056c62c4e --- /dev/null +++ b/app/validators/json_schemas/codeclimate.json @@ -0,0 +1,34 @@ +{ + "description": "Codequality used by codeclimate parser", + "type": "object", + "required": ["description", "fingerprint", "severity", "location"], + "properties": { + "description": { "type": "string" }, + "fingerprint": { "type": "string" }, + "severity": { "type": "string" }, + "location": { + "type": "object", + "properties": { + "path": { "type": "string" }, + "lines": { + "type": "object", + "properties": { + "begin": { "type": "integer" } + } + }, + "positions": { + "type": "object", + "properties": { + "begin": { + "type": "object", + "properties": { + "line": { "type": "integer" } + } + } + } + } + } + } + }, + "additionalProperties": true +} diff --git a/app/validators/json_schemas/http_integration_payload_attribute_mapping.json b/app/validators/json_schemas/http_integration_payload_attribute_mapping.json new file mode 100644 index 00000000000..e457b8a292b --- /dev/null +++ b/app/validators/json_schemas/http_integration_payload_attribute_mapping.json @@ -0,0 +1,14 @@ +{ + "type": "object", + "patternProperties": { + ".*": { + "type": "object", + "required": ["path", "type"], + "properties": { + "path": { "type": "array" }, + "type": { "type": "string" } + }, + "additionalProperties": false + } + } +} diff --git a/app/validators/json_schemas/vulnerability_finding_details.json b/app/validators/json_schemas/vulnerability_finding_details.json new file mode 100644 index 00000000000..f2940866f4b --- /dev/null +++ b/app/validators/json_schemas/vulnerability_finding_details.json @@ -0,0 +1,182 @@ +{ + "type": "object", + "description": "The schema for vulnerability finding details", + "additionalProperties": false, + "patternProperties": { + "^.*$": { + "allOf": [ + { "$ref": "#/definitions/named_field" }, + { "$ref": "#/definitions/type_list" } + ] + } + }, + "definitions": { + "type_list": { + "oneOf": [ + { "$ref": "#/definitions/named_list" }, + { "$ref": "#/definitions/list" }, + { "$ref": "#/definitions/table" }, + + { "$ref": "#/definitions/text" }, + { "$ref": "#/definitions/url" }, + { "$ref": "#/definitions/code" }, + { "$ref": "#/definitions/int" }, + + { "$ref": "#/definitions/commit" }, + { "$ref": "#/definitions/file_location" }, + { "$ref": "#/definitions/module_location" } + ] + }, + "lang_text": { + "type": "object", + "required": [ "value", "lang" ], + "properties": { + "lang": { "type": "string" }, + "value": { "type": "string" } + } + }, + "lang_text_list": { + "type": "array", + "items": { "$ref": "#/definitions/lang_text" } + }, + "named_field": { + "type": "object", + "required": [ "name" ], + "properties": { + "name": { "$ref": "#/definitions/lang_text_list" }, + "description": { "$ref": "#/definitions/lang_text_list" } + } + }, + "named_list": { + "type": "object", + "description": "An object with named and typed fields", + "required": [ "type", "items" ], + "properties": { + "type": { "const": "named-list" }, + "items": { + "type": "object", + "patternProperties": { + "^.*$": { + "allOf": [ + { "$ref": "#/definitions/named_field" }, + { "$ref": "#/definitions/type_list" } + ] + } + } + } + } + }, + "list": { + "type": "object", + "description": "A list of typed fields", + "required": [ "type", "items" ], + "properties": { + "type": { "const": "list" }, + "items": { + "type": "array", + "items": { "$ref": "#/definitions/type_list" } + } + } + }, + "table": { + "type": "object", + "description": "A table of typed fields", + "required": [], + "properties": { + "type": { "const": "table" }, + "items": { + "type": "object", + "properties": { + "header": { + "type": "array", + "items": { + "$ref": "#/definitions/type_list" + } + }, + "rows": { + "type": "array", + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/type_list" + } + } + } + } + } + } + }, + "text": { + "type": "object", + "description": "Raw text", + "required": [ "type", "value" ], + "properties": { + "type": { "const": "text" }, + "value": { "$ref": "#/definitions/lang_text_list" } + } + }, + "url": { + "type": "object", + "description": "A single URL", + "required": [ "type", "href" ], + "properties": { + "type": { "const": "url" }, + "text": { "$ref": "#/definitions/lang_text_list" }, + "href": { "type": "string" } + } + }, + "code": { + "type": "object", + "description": "A codeblock", + "required": [ "type", "value" ], + "properties": { + "type": { "const": "code" }, + "value": { "type": "string" }, + "lang": { "type": "string" } + } + }, + "int": { + "type": "object", + "description": "An integer", + "required": [ "type", "value" ], + "properties": { + "type": { "const": "int" }, + "value": { "type": "integer" }, + "format": { + "type": "string", + "enum": [ "default", "hex" ] + } + } + }, + "commit": { + "type": "object", + "description": "A specific commit within the project", + "required": [ "type", "value" ], + "properties": { + "type": { "const": "commit" }, + "value": { "type": "string", "description": "The commit SHA" } + } + }, + "file_location": { + "type": "object", + "description": "A location within a file in the project", + "required": [ "type", "file_name", "line_start" ], + "properties": { + "type": { "const": "file-location" }, + "file_name": { "type": "string" }, + "line_start": { "type": "integer" }, + "line_end": { "type": "integer" } + } + }, + "module_location": { + "type": "object", + "description": "A location within a binary module of the form module+relative_offset", + "required": [ "type", "module_name", "offset" ], + "properties": { + "type": { "const": "module-location" }, + "module_name": { "type": "string" }, + "offset": { "type": "integer" } + } + } + } +} |