Skip to content

Commit ef980b0

Browse files
itxiaohu001huyongfeng
and
huyongfeng
authored
improve analytical ability for python & custom warehouse pull detection (#33)
* Update config.json * update readme.md * update config.json * Fix formatting issues * Support for specifying Maven private repositories * improve analytical ability for python * change version comparison algorithm Co-authored-by: huyongfeng <[email protected]>
1 parent 827c020 commit ef980b0

File tree

15 files changed

+819
-366
lines changed

15 files changed

+819
-366
lines changed

.github/README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ OpenSCA is intended for scanning the third-party component dependencies and vuln
2121

2222
OpenSCA is now capable of parsing configuration files in the listed programming languages and correspondent package managers. The project team is now dedicated to introducing more languages and enriching the parsing of relevant configuration files gradually.
2323

24-
| LANGUAGE | PACKAGE MANAGER | FILE |
25-
| ------------ | --------------- | ---------------------------------------------- |
26-
| `Java` | `Maven` | `pom.xml` |
27-
| `Java` | `Gradle` | `.gradle` `.gradle.kts` |
28-
| `JavaScript` | `Npm` | `package-lock.json` `package.json` `yarn.lock` |
29-
| `PHP` | `Composer` | `composer.json` `composer.lock` |
30-
| `Ruby` | `gem` | `gemfile.lock` |
31-
| `Golang` | `gomod` | `go.mod` `go.sum` |
32-
| `Rust` | `cargo` | `Cargo.lock` |
33-
| `Erlang` | `Rebar` | `rebar.lock` |
34-
| `Python` | `Pip` | `Pipfile` `Pipfile.lock` `setup.py` |
24+
| LANGUAGE | PACKAGE MANAGER | FILE |
25+
| ------------ | --------------- | ------------------------------------------------------------ |
26+
| `Java` | `Maven` | `pom.xml` |
27+
| `Java` | `Gradle` | `.gradle` `.gradle.kts` |
28+
| `JavaScript` | `Npm` | `package-lock.json` `package.json` `yarn.lock` |
29+
| `PHP` | `Composer` | `composer.json` `composer.lock` |
30+
| `Ruby` | `gem` | `gemfile.lock` |
31+
| `Golang` | `gomod` | `go.mod` `go.sum` |
32+
| `Rust` | `cargo` | `Cargo.lock` |
33+
| `Erlang` | `Rebar` | `rebar.lock` |
34+
| `Python` | `Pip` | `Pipfile` `Pipfile.lock` `setup.py``requirements.txt``requirements.in`(For the latter two, you need to install pipenv in advance) |
3535

3636
## Download and Deployment
3737

README.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717

1818
`OpenSCA`现已支持以下编程语言相关的配置文件解析及对应的包管理器,后续会逐步支持更多的编程语言,丰富相关配置文件的解析。
1919

20-
| 支持语言 | 包管理器 | 解析文件 |
21-
| ------------ | ---------- | ---------------------------------------------- |
22-
| `Java` | `Maven` | `pom.xml` |
23-
| `Java` | `Gradle` | `.gradle` `.gradle.kts` |
24-
| `JavaScript` | `Npm` | `package-lock.json` `package.json` `yarn.lock` |
25-
| `PHP` | `Composer` | `composer.json` `composer.lock` |
26-
| `Ruby` | `gem` | `gemfile.lock` |
27-
| `Golang` | `gomod` | `go.mod` `go.sum` |
28-
| `Rust` | `cargo` | `Cargo.lock` |
29-
| `Erlang` | `Rebar` | `rebar.lock` |
30-
| `Python` | `Pip` | `Pipfile` `Pipfile.lock` `setup.py` |
20+
| 支持语言 | 包管理器 | 解析文件 |
21+
| ------------ | ---------- | ------------------------------------------------------------ |
22+
| `Java` | `Maven` | `pom.xml` |
23+
| `Java` | `Gradle` | `.gradle` `.gradle.kts` |
24+
| `JavaScript` | `Npm` | `package-lock.json` `package.json` `yarn.lock` |
25+
| `PHP` | `Composer` | `composer.json` `composer.lock` |
26+
| `Ruby` | `gem` | `gemfile.lock` |
27+
| `Golang` | `gomod` | `go.mod` `go.sum` |
28+
| `Rust` | `cargo` | `Cargo.lock` |
29+
| `Erlang` | `Rebar` | `rebar.lock` |
30+
| `Python` | `Pip` | `Pipfile` `Pipfile.lock` `setup.py``requirements.txt``requirements.in`(后两者需要pipenv环境,需要联网) |
3131

3232
## 下载安装
3333

@@ -75,18 +75,18 @@ opensca-cli -db db.json -path ${project_path}
7575

7676
**可在配置文件中配置参数,也可在命令行输入参数,两者冲突时优先使用输入参数**
7777

78-
| 参数 | 类型 | 描述 | 使用样例 |
79-
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
80-
| `config` | `string` | 指定配置文件路径,程序启动时将配置文件中的参数作为启动参数,配置参数与命令行输入参数冲突时优先使用输入参数 | `-config config.json` |
81-
| `path` | `string` | 指定要检测的文件或目录路径 | `-path ./foo` |
82-
| `url` | `string` | 从云漏洞库查询漏洞,指定要连接云服务的地址,与 `token` 参数一起使用 | `-url https://opensca.xmirror.cn` |
83-
| `token` | `string` | 云服务验证 `token`,需要在云服务平台申请,与 `url` 参数一起使用 | `-token xxxxxxx` |
84-
| `cache` | `bool` | 建议开启,缓存下载的文件(例如 `.pom` 文件),重复检测相同组件时会节省时间,下载的文件会保存到工具所在目录的.cache 目录下 | `-cache` |
85-
| `vuln` | `bool` | 结果仅保留有漏洞信息的组件,使用该参数将不会保留组件层级结构 | `-vuln` |
86-
| `out` | `string` | 将检测结果保存到指定文件,根据后缀生成不同格式的文件,默认为 `json` 格式;支持以`spdx`格式展示`sbom`清单只需更换相应输出文件后缀即可 | `-out output.json` |
78+
| 参数 | 类型 | 描述 | 使用样例 |
79+
| ---------- | -------- | ------------------------------------------------------------ | --------------------------------- |
80+
| `config` | `string` | 指定配置文件路径,程序启动时将配置文件中的参数作为启动参数,配置参数与命令行输入参数冲突时优先使用输入参数 | `-config config.json` |
81+
| `path` | `string` | 指定要检测的文件或目录路径 | `-path ./foo` |
82+
| `url` | `string` | 从云漏洞库查询漏洞,指定要连接云服务的地址,与 `token` 参数一起使用 | `-url https://opensca.xmirror.cn` |
83+
| `token` | `string` | 云服务验证 `token`,需要在云服务平台申请,与 `url` 参数一起使用 | `-token xxxxxxx` |
84+
| `cache` | `bool` | 建议开启,缓存下载的文件(例如 `.pom` 文件),重复检测相同组件时会节省时间,下载的文件会保存到工具所在目录的.cache 目录下 | `-cache` |
85+
| `vuln` | `bool` | 结果仅保留有漏洞信息的组件,使用该参数将不会保留组件层级结构 | `-vuln` |
86+
| `out` | `string` | 将检测结果保存到指定文件,根据后缀生成不同格式的文件,默认为 `json` 格式;支持以`spdx`格式展示`sbom`清单只需更换相应输出文件后缀即可 | `-out output.json` |
8787
| `db` | `string` | 指定本地漏洞库文件,希望使用自己漏洞库时可用,漏洞库文件为 `json` 格式,具体格式会在之后给出;若同时使用云端漏洞库与本地漏洞库,漏洞查询结果取并集 | `-db db.json` |
88-
| `progress` | `bool` | 显示进度条 | `-progress` |
89-
| `dedup` | `bool` | 相同组件去重 | `-dedup` |
88+
| `progress` | `bool` | 显示进度条 | `-progress` |
89+
| `dedup` | `bool` | 相同组件去重 | `-dedup` |
9090

9191
---
9292

analyzer/engine/engine.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ func (e Engine) ParseFile(filepath string) (depRoot *model.DepTree, taskInfo rep
5656
// 目录树
5757
dirRoot := model.NewDirTree()
5858
depRoot = model.NewDepTree(nil)
59+
filepath = strings.ReplaceAll(filepath, `\`, `/`)
5960
taskInfo = report.TaskInfo{
60-
AppName: filepath,
61+
AppName: strings.TrimSuffix(path.Base(filepath), path.Ext(path.Base(filepath))),
6162
StartTime: time.Now().Format("2006-01-02 15:04:05"),
6263
}
6364
s := time.Now()

0 commit comments

Comments
 (0)