{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://docs.getcanyon.ai/contracts/schema/finding.schema.json",
  "title": "Canyon finding profile (seam 1) — a strict SARIF 2.1.0 profile",
  "description": "What makes a SARIF result a Canyon finding. Validate the log against the SARIF 2.1.0 schema first; this schema adds the profile: one location with a full region, a canyon/v1 fingerprint, and the required properties.canyon bag. The findings contract is canonical.",
  "type": "object",
  "required": [
    "version",
    "$schema",
    "runs"
  ],
  "properties": {
    "version": {
      "const": "2.1.0"
    },
    "$schema": {
      "const": "https://json.schemastore.org/sarif-2.1.0.json"
    },
    "runs": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "columnKind",
          "tool",
          "results"
        ],
        "properties": {
          "columnKind": {
            "const": "unicodeCodePoints"
          },
          "tool": {
            "type": "object",
            "required": [
              "driver"
            ],
            "properties": {
              "driver": {
                "type": "object",
                "required": [
                  "name",
                  "version",
                  "rules"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9/-]*$"
                  },
                  "version": {
                    "type": "string",
                    "minLength": 1
                  },
                  "rules": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "id",
                        "name"
                      ],
                      "properties": {
                        "id": {
                          "$ref": "#/definitions/ruleId"
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/definitions/result"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "ruleId": {
      "type": "string",
      "pattern": "^([a-z]+\\.[a-z][a-z-]*|(sarif|[a-z]+\\.[a-z][a-z-]*)\\.[a-z0-9]+(-[a-z0-9]+)*\\.[!-~]{1,128})$",
      "description": "A Canyon rule, or an imported tool's: sarif.<tool>.<the tool's own rule id, printable ASCII without whitespace>, or <policy>.<tool>.<the tool's own rule id> where the policy table maps it."
    },
    "region": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "startLine",
        "startColumn",
        "endLine",
        "endColumn",
        "snippet"
      ],
      "properties": {
        "startLine": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000000
        },
        "startColumn": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000000
        },
        "endLine": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000000
        },
        "endColumn": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000000
        },
        "snippet": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "text"
          ],
          "properties": {
            "text": {
              "type": "string",
              "maxLength": 400
            }
          }
        }
      }
    },
    "location": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "physicalLocation"
      ],
      "properties": {
        "physicalLocation": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "artifactLocation",
            "region"
          ],
          "properties": {
            "artifactLocation": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "uri"
              ],
              "properties": {
                "uri": {
                  "type": "string",
                  "minLength": 1
                },
                "uriBaseId": {
                  "const": "IMAGE",
                  "description": "a path inside the image an app runs, on a platform.known-vuln finding alone, which always carries it (finding.md, System libraries and build tools)"
                }
              }
            },
            "region": {
              "$ref": "#/definitions/region"
            }
          }
        }
      }
    },
    "result": {
      "type": "object",
      "required": [
        "ruleId",
        "level",
        "message",
        "locations",
        "partialFingerprints",
        "properties"
      ],
      "properties": {
        "ruleId": {
          "$ref": "#/definitions/ruleId"
        },
        "level": {
          "enum": [
            "error",
            "warning",
            "note"
          ]
        },
        "message": {
          "type": "object",
          "required": [
            "text"
          ],
          "properties": {
            "text": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "locations": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1,
          "items": {
            "$ref": "#/definitions/location"
          }
        },
        "relatedLocations": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/location"
          }
        },
        "partialFingerprints": {
          "type": "object",
          "required": [
            "canyon/v1"
          ],
          "properties": {
            "canyon/v1": {
              "type": "string",
              "pattern": "^f_[0-9a-f]{64}$"
            }
          }
        },
        "properties": {
          "type": "object",
          "required": [
            "canyon"
          ],
          "properties": {
            "canyon": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "severity",
                "blocks",
                "title",
                "problem",
                "fix",
                "policy_name"
              ],
              "properties": {
                "severity": {
                  "enum": [
                    "critical",
                    "high",
                    "medium",
                    "low"
                  ]
                },
                "blocks": {
                  "type": "boolean"
                },
                "title": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 120
                },
                "problem": {
                  "type": "string",
                  "minLength": 1
                },
                "fix": {
                  "type": "string",
                  "minLength": 1
                },
                "policy_name": {
                  "type": "string",
                  "minLength": 1
                },
                "secret_name": {
                  "type": "string",
                  "pattern": "^[A-Z][A-Z0-9_]*$"
                },
                "recorded": {
                  "const": true
                },
                "shown": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "startColumn",
                    "endColumn"
                  ],
                  "properties": {
                    "startColumn": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 1000000000
                    },
                    "endColumn": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 1000000000
                    }
                  }
                },
                "required_end_state": {
                  "type": "string",
                  "minLength": 1
                },
                "do_not": {
                  "type": "array",
                  "minItems": 1,
                  "items": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            }
          },
          "additionalProperties": false
        }
      },
      "if": {
        "properties": {
          "ruleId": {
            "const": "platform.known-vuln"
          }
        }
      },
      "then": {
        "properties": {
          "locations": {
            "items": {
              "properties": {
                "physicalLocation": {
                  "properties": {
                    "artifactLocation": {
                      "required": [
                        "uriBaseId"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "else": {
        "properties": {
          "locations": {
            "items": {
              "properties": {
                "physicalLocation": {
                  "properties": {
                    "artifactLocation": {
                      "not": {
                        "required": [
                          "uriBaseId"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
