(report Report, out string)
| 79 | } |
| 80 | |
| 81 | func Sarif(report Report, out string) { |
| 82 | |
| 83 | s := sarifReport{ |
| 84 | Version: "2.1.0", |
| 85 | Schema: "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0.json", |
| 86 | } |
| 87 | |
| 88 | run := sarifRun{} |
| 89 | run.Tool.Driver.Name = "opensca-cli" |
| 90 | run.Tool.Driver.Version = strings.TrimLeft(report.TaskInfo.ToolVersion, "vV") |
| 91 | run.Tool.Driver.InformationUri = "https://opensca.xmirror.cn" |
| 92 | |
| 93 | vulnInfos := map[string]*detail.VulnInfo{} |
| 94 | |
| 95 | report.ForEach(func(n *detail.DepDetailGraph) bool { |
| 96 | for _, vuln := range n.Vulnerabilities { |
| 97 | |
| 98 | if vuln.Id == "" { |
| 99 | continue |
| 100 | } |
| 101 | |
| 102 | vulnInfos[vuln.Id] = &detail.VulnInfo{Vuln: vuln, Language: n.Language} |
| 103 | |
| 104 | result := sarifResult{ |
| 105 | RuleId: vuln.Id, |
| 106 | Level: vuln.SarifLevel(), |
| 107 | } |
| 108 | result.Message.Text = fmt.Sprintf("引入的组件 %s 中存在 %s", n.Dep.Key()[:strings.LastIndex(n.Dep.Key(), ":")], vuln.Name) |
| 109 | for i, path := range n.Paths { |
| 110 | if truncIndex := strings.Index(path, "["); truncIndex > 0 { |
| 111 | path = strings.Trim(path[:truncIndex], `\/`) |
| 112 | } |
| 113 | location := sarifLocation{} |
| 114 | location.PhysicalLocation.ArtifactLocation.Uri = path |
| 115 | location.PhysicalLocation.ArtifactLocation.Index = i |
| 116 | location.PhysicalLocation.Region.StartColumn = 1 |
| 117 | location.PhysicalLocation.Region.EndColumn = 1 |
| 118 | location.PhysicalLocation.Region.StartLine = 1 |
| 119 | location.PhysicalLocation.Region.EndLine = 1 |
| 120 | result.Locations = append(result.Locations, location) |
| 121 | } |
| 122 | |
| 123 | run.Results = append(run.Results, result) |
| 124 | } |
| 125 | return true |
| 126 | }) |
| 127 | |
| 128 | for _, vuln := range vulnInfos { |
| 129 | run.Tool.Driver.Rules = append(run.Tool.Driver.Rules, sarifRule{ |
| 130 | Id: vuln.Id, |
| 131 | Name: vuln.Name, |
| 132 | ShortDescription: sarifRuleShortDescription{Text: vuln.Name}, |
| 133 | FullDescription: sarifRuleFullDescription{Text: vuln.Description}, |
| 134 | Help: sarifRuleHelp{Markdown: formatDesc(vuln)}, |
| 135 | Properties: sarifRuleProperties{Tags: formatTags(vuln)}, |
| 136 | }) |
| 137 | } |
| 138 |
no test coverage detected