├── vuldata.sqlite3 ├── requirements.txt ├── f8a_version_comparator ├── __pycache__ │ ├── base.cpython-37.pyc │ ├── __init__.cpython-37.pyc │ ├── item_object.cpython-37.pyc │ └── comparable_version.cpython-37.pyc ├── base.py ├── __init__.py ├── item_object.py └── comparable_version.py ├── website.py ├── .gitignore ├── README.md ├── static ├── mosec-x-plugin-backend.drawio └── mosec-x-plugin-backend.svg ├── vuldb.py ├── test └── vuldb_test.py └── LICENSE /vuldata.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/momosecurity/mosec-x-plugin-backend/HEAD/vuldata.sqlite3 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | click==7.1.2 2 | Flask==1.1.2 3 | itsdangerous==1.1.0 4 | Jinja2==2.11.2 5 | MarkupSafe==1.1.1 6 | Werkzeug==1.0.1 7 | -------------------------------------------------------------------------------- /f8a_version_comparator/__pycache__/base.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/momosecurity/mosec-x-plugin-backend/HEAD/f8a_version_comparator/__pycache__/base.cpython-37.pyc -------------------------------------------------------------------------------- /f8a_version_comparator/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/momosecurity/mosec-x-plugin-backend/HEAD/f8a_version_comparator/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /f8a_version_comparator/__pycache__/item_object.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/momosecurity/mosec-x-plugin-backend/HEAD/f8a_version_comparator/__pycache__/item_object.cpython-37.pyc -------------------------------------------------------------------------------- /f8a_version_comparator/__pycache__/comparable_version.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/momosecurity/mosec-x-plugin-backend/HEAD/f8a_version_comparator/__pycache__/comparable_version.cpython-37.pyc -------------------------------------------------------------------------------- /f8a_version_comparator/base.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Red Hat Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Author: Geetika Batra 16 | # 17 | 18 | """Item class acting as base class for various item types.""" 19 | 20 | from abc import ABCMeta, abstractmethod 21 | 22 | 23 | class Item(metaclass=ABCMeta): 24 | """Base class for maven version comparator tasks.""" 25 | 26 | @abstractmethod 27 | def compare_to(self, _item): 28 | """Compare two maven versions.""" 29 | -------------------------------------------------------------------------------- /f8a_version_comparator/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Red Hat Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Author: Geetika Batra 16 | # 17 | # github: https://github.com/fabric8-analytics/fabric8-analytics-version-comparator 18 | # commit: 702dc284a121a790a487c1035dc77f3f597e72fc 19 | 20 | """Initialize Module.""" 21 | 22 | __all__ = [ 23 | "base", 24 | "comparable_version", 25 | "item_object", 26 | ] 27 | 28 | from . import base 29 | from . import comparable_version 30 | from . import item_object 31 | -------------------------------------------------------------------------------- /website.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright 2020 momosecurity. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | """ 16 | import sqlite3 17 | from flask import Flask, jsonify, request, g 18 | from vuldb import DB, Checker, ALLOW_SEVERITY 19 | 20 | app = Flask(__name__) 21 | 22 | 23 | @app.before_request 24 | def before_request(): 25 | g.db = sqlite3.connect(DB) 26 | 27 | 28 | @app.teardown_request 29 | def teardown_request(exception): 30 | if hasattr(g, 'db'): 31 | g.db.close() 32 | 33 | 34 | @app.route('/api/plugin', methods=['POST']) 35 | def api_mosec(): 36 | try: 37 | data = request.json 38 | lib_type = data['type'] 39 | dependencies = data['dependencies'] 40 | language = data['language'] 41 | severity = data['severityLevel'].capitalize() 42 | if severity not in ALLOW_SEVERITY: 43 | severity = 'High' 44 | except Exception as e: 45 | return jsonify({'msg': 'Post Data Error'}), 400 46 | 47 | try: 48 | res = Checker(g.db, lib_type, dependencies, language, severity).check_vuln() 49 | except Exception as e: 50 | return jsonify({'msg': 'Server Error'}), 500 51 | 52 | return jsonify(res) 53 | 54 | 55 | if __name__ == '__main__': 56 | app.run(debug=True, host='127.0.0.1', port=9000) 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/pycharm+all 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=pycharm+all 4 | 5 | ### PyCharm+all ### 6 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 7 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 8 | 9 | # User-specific stuff 10 | .idea/**/workspace.xml 11 | .idea/**/tasks.xml 12 | .idea/**/usage.statistics.xml 13 | .idea/**/dictionaries 14 | .idea/**/shelf 15 | 16 | # Generated files 17 | .idea/**/contentModel.xml 18 | 19 | # Sensitive or high-churn files 20 | .idea/**/dataSources/ 21 | .idea/**/dataSources.ids 22 | .idea/**/dataSources.local.xml 23 | .idea/**/sqlDataSources.xml 24 | .idea/**/dynamic.xml 25 | .idea/**/uiDesigner.xml 26 | .idea/**/dbnavigator.xml 27 | 28 | # Gradle 29 | .idea/**/gradle.xml 30 | .idea/**/libraries 31 | 32 | # Gradle and Maven with auto-import 33 | # When using Gradle or Maven with auto-import, you should exclude module files, 34 | # since they will be recreated, and may cause churn. Uncomment if using 35 | # auto-import. 36 | # .idea/artifacts 37 | # .idea/compiler.xml 38 | # .idea/jarRepositories.xml 39 | # .idea/modules.xml 40 | # .idea/*.iml 41 | # .idea/modules 42 | # *.iml 43 | # *.ipr 44 | 45 | # CMake 46 | cmake-build-*/ 47 | 48 | # Mongo Explorer plugin 49 | .idea/**/mongoSettings.xml 50 | 51 | # File-based project format 52 | *.iws 53 | 54 | # IntelliJ 55 | out/ 56 | 57 | # mpeltonen/sbt-idea plugin 58 | .idea_modules/ 59 | 60 | # JIRA plugin 61 | atlassian-ide-plugin.xml 62 | 63 | # Cursive Clojure plugin 64 | .idea/replstate.xml 65 | 66 | # Crashlytics plugin (for Android Studio and IntelliJ) 67 | com_crashlytics_export_strings.xml 68 | crashlytics.properties 69 | crashlytics-build.properties 70 | fabric.properties 71 | 72 | # Editor-based Rest Client 73 | .idea/httpRequests 74 | 75 | # Android studio 3.1+ serialized cache file 76 | .idea/caches/build_file_checksums.ser 77 | 78 | ### PyCharm+all Patch ### 79 | # Ignores the whole .idea folder and all .iml files 80 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 81 | 82 | .idea/ 83 | 84 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 85 | 86 | *.iml 87 | modules.xml 88 | .idea/misc.xml 89 | *.ipr 90 | 91 | # Sonarlint plugin 92 | .idea/sonarlint 93 | 94 | # End of https://www.toptal.com/developers/gitignore/api/pycharm+all 95 | venv/ 96 | __pycache__/ 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MOSEC-X-PLUGIN Backend 2 | 3 | MOSEC-X-PLUGIN 后端检测API 4 | 5 | 6 | 7 | ## 关于我们 8 | 9 | Website:https://security.immomo.com 10 | 11 | WeChat: 12 | 13 |
14 | 15 | 16 | 17 | ## 版本要求 18 | 19 | Python 3.7.x 20 | 21 | 22 | 23 | ## 安装 24 | 25 | ```shell script 26 | > pip install -r requirements.txt 27 | ``` 28 | 29 | 30 | 31 | ## 运行 32 | 33 | ```shell script 34 | > python website.py 35 | # will run on http://127.0.0.1:9000/ 36 | ``` 37 | 38 | 39 | 40 | ## 开发 41 | 42 | #### 漏洞规则数据表 43 | 44 | ```sqlite 45 | CREATE TABLE IF NOT EXISTS "vulrules" ( 46 | "title" TEXT(255), -- 漏洞标题 47 | "name" TEXT(255), -- 漏洞组件名称 ( vendor / groupId:artifactId ) 48 | "severity" TEXT(10), -- 漏洞危害等级 ( High / Medium / Low ) 49 | "type" TEXT(10), -- 构建工具类型 ( Maven / pip / npm / Composer ) 50 | "cve" TEXT(20), -- 漏洞对应CVE编号 51 | "cvss3" TEXT(10), -- 漏洞对应CVSS3分数 52 | "vul_version_fr" TEXT(255), -- 漏洞组件最低版本 ( vul_version_fr <= 使用的组件版本 ) 53 | "vul_version_to" TEXT(255), -- 漏洞组件最高版本 ( 使用的组件版本 <= vul_version_to ) 54 | "target_version" TEXT(255) -- 漏洞组件安全版本 ( 数据类型是json.dumps(list) ) 55 | ); 56 | ``` 57 | 58 | #### 检测流程 59 | 60 | ![flow](./static/mosec-x-plugin-backend.svg) 61 | 62 | ### API 63 | 64 | #### POST /api/plugin 65 | 66 | ```json 67 | { 68 | "type": "Maven", 69 | "language": "java", 70 | "severityLevel": "High", 71 | "name": "name1", 72 | "version": "version1", 73 | "from": [ 74 | "name1@version1" 75 | ], 76 | "dependencies": { 77 | "name2": { 78 | "name": "name2", 79 | "version": "version2", 80 | "from": [ 81 | "name1@version1", 82 | "name2@version2" 83 | ], 84 | "dependencies": { 85 | "name4": { 86 | "name": "name4", 87 | "version": "version4", 88 | "from": [ 89 | "name1@version1", 90 | "name2@version2", 91 | "name4@version4" 92 | ], 93 | "dependencies": {} 94 | } 95 | } 96 | }, 97 | "name3": { 98 | "name": "name3", 99 | "version": "version3", 100 | "from": [ 101 | "name1@version1", 102 | "name3@version3" 103 | ], 104 | "dependencies": {} 105 | } 106 | } 107 | } 108 | ``` 109 | 110 | #### Response 111 | 112 | ```json 113 | { 114 | "ok": false, 115 | "dependencyCount": 2, 116 | "vulnerabilities": [ 117 | { 118 | "title": "title", 119 | "severity": "High", 120 | "packageName": "name2", 121 | "version": "version2", 122 | "from": [ 123 | "name1@version1", 124 | "name2@version2" 125 | ], 126 | "cve": "cve", 127 | "target_version": [ 128 | "version2.1", 129 | "version3.0" 130 | ] 131 | } 132 | ] 133 | } 134 | ``` 135 | -------------------------------------------------------------------------------- /static/mosec-x-plugin-backend.drawio: -------------------------------------------------------------------------------- 1 | 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 -------------------------------------------------------------------------------- /vuldb.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright 2020 momosecurity. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | """ 16 | import json 17 | import os 18 | from collections import defaultdict 19 | from pkg_resources import parse_version 20 | from f8a_version_comparator.comparable_version import ComparableVersion 21 | 22 | DB = os.path.join(os.path.dirname(__file__), 'vuldata.sqlite3') 23 | ALLOW_SEVERITY = ['High', 'Medium', 'Low'] 24 | 25 | 26 | class Checker(object): 27 | 28 | def __init__(self, db: object, lib_type: str, dependencies: dict, language: str, severity: str): 29 | self.db = db 30 | self.lib_type = lib_type 31 | self.dependencies = list(self._get_dependencies_list(dependencies)) 32 | self.language = language 33 | self.severity = severity 34 | self.vulrules = self._get_vulrules(lib_type, severity) 35 | self.ver = get_version_tool(self.language) 36 | 37 | @classmethod 38 | def _get_dependencies_list(cls, dependencies: dict, root=''): 39 | for name, deps in dependencies.items(): 40 | yield { 41 | 'name': name, 42 | 'version': deps.get('version'), 43 | 'from': deps.get('from', []), 44 | 'root': root 45 | } 46 | if isinstance(deps.get('dependencies'), dict): 47 | for v in cls._get_dependencies_list(deps['dependencies'], name.lower()): 48 | yield v 49 | 50 | def _get_vulrules(self, lib_type: str, severity: str) -> dict: 51 | """ 52 | :param lib_type: 构建工具类型(Maven, Composer, pip, npm等) 53 | :param severity: 威胁级别(High, Medium, Low) 54 | :return: { 55 | lower('name'): [{ 56 | 'title': '漏洞描述', 57 | 'name': '组件名称', 58 | 'severity': '漏洞威胁级别', 59 | 'cve': 'cve/cwe编号', 60 | 'vul_version_fr': x, 61 | 'vul_version_to': y, 62 | 'target_version': ['v1', 'v2'] 63 | }, { 64 | ... 65 | }], 66 | lower('name2'): [{ 67 | ... 68 | }] 69 | } 70 | """ 71 | query_args = [] 72 | if severity == 'High': 73 | query_severity = "?" 74 | query_args.append('High') 75 | elif severity == 'Medium': 76 | query_severity = "?, ?" 77 | query_args.extend(['High', 'Medium']) 78 | else: 79 | query_severity = "?, ?, ?" 80 | query_args.extend(['High', 'Medium', 'Low']) 81 | 82 | query_args.append(lib_type) 83 | rules = query_db(self.db, 84 | "SELECT title, name, severity, cve, vul_version_fr, vul_version_to, target_version" 85 | " FROM vulrules" 86 | " WHERE severity in (" +query_severity +")" 87 | " AND type = ?", 88 | query_args) 89 | result = defaultdict(list) 90 | for rule in rules: 91 | rule['target_version'] = json.loads(rule['target_version']) 92 | result[rule['name'].lower()].append(rule) 93 | return result 94 | 95 | def _version_in(self, version: str, vul_version_fr: str, vul_version_to: str) -> bool: 96 | return self.ver(vul_version_fr) <= self.ver(version) <= self.ver(vul_version_to) 97 | 98 | def _target_version_compare(self, src: dict, dst: dict) -> bool: 99 | src_max_v = max(src['target_version'], key=lambda x: self.ver(x)) 100 | dst_max_v = max(dst['target_version'], key=lambda x: self.ver(x)) 101 | return self.ver(src_max_v) > self.ver(dst_max_v) 102 | 103 | def get_vuln(self, name: str, version: str) -> dict: 104 | rules = self.vulrules.get(name.lower(), {}) 105 | if not rules: 106 | return {} 107 | 108 | max_target_version_vuln = {} 109 | for rule in rules: 110 | if not self._version_in(version, rule['vul_version_fr'], rule['vul_version_to']): 111 | continue 112 | if not max_target_version_vuln: 113 | max_target_version_vuln = rule 114 | continue 115 | elif self._target_version_compare(rule, max_target_version_vuln): 116 | max_target_version_vuln = rule 117 | return max_target_version_vuln 118 | 119 | def check_vuln(self) -> dict: 120 | result = { 121 | 'ok': True, 122 | 'dependencyCount': 0, 123 | 'vulnerabilities': [] 124 | } 125 | 126 | roots = set() 127 | for dep in self.dependencies: 128 | if dep['root'] in roots: 129 | roots.add(dep['name']) 130 | continue 131 | result['dependencyCount'] += 1 132 | 133 | vuln = self.get_vuln(dep['name'], dep['version']) 134 | if vuln: 135 | roots.add(dep['name']) 136 | result['vulnerabilities'].append({ 137 | 'packageName': dep['name'], 138 | 'version': dep['version'], 139 | 'from': dep['from'], 140 | 'severity': vuln['severity'], 141 | 'target_version': vuln['target_version'], 142 | 'cve': vuln['cve'], 143 | 'title': vuln['title'], 144 | }) 145 | result['ok'] = not bool(result['vulnerabilities']) 146 | return result 147 | 148 | 149 | def get_version_tool(language: str): 150 | if language == 'java': 151 | return ComparableVersion 152 | else: 153 | return parse_version 154 | 155 | 156 | def query_db(db: object, query: str, args=(), one=False): 157 | cur = db.execute(query, args) 158 | rv = [dict((cur.description[idx][0], value) 159 | for idx, value in enumerate(row)) for row in cur.fetchall()] 160 | return (rv[0] if rv else None) if one else rv 161 | -------------------------------------------------------------------------------- /f8a_version_comparator/item_object.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Red Hat Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Author: Geetika Batra 16 | # 17 | 18 | """Module to implement methods item types.""" 19 | 20 | from .base import Item 21 | # TODO: setup logging 22 | 23 | 24 | class IntegerItem(Item): 25 | """Integer Item class for maven version comparator tasks.""" 26 | 27 | def __init__(self, str_version): 28 | """Initialize integer from string value of version. 29 | 30 | :str_version: part of version supplied as string 31 | """ 32 | self.value = int(str_version) 33 | 34 | def int_cmp(self, cmp_value): 35 | """Compare two integers.""" 36 | if self.value.__lt__(cmp_value): 37 | return -1 38 | if self.value.__gt__(cmp_value): 39 | return 1 40 | return 0 41 | 42 | def compare_to(self, item): 43 | """Compare two maven versions.""" 44 | if item is None: 45 | return 0 if self.value == 0 else 1 46 | 47 | if isinstance(item, IntegerItem): 48 | return self.int_cmp(item.value) # check if this value thing works 49 | if isinstance(item, StringItem): 50 | return 1 51 | if isinstance(item, ListItem): 52 | return 1 53 | else: 54 | raise ValueError("invalid item" + str(type(item))) 55 | 56 | def to_string(self): 57 | """Return string value of version.""" 58 | return str(self.value) 59 | 60 | def __str__(self): 61 | """Return string value of version - Pythonish variant.""" 62 | return str(self.value) 63 | 64 | 65 | class StringItem(Item): 66 | """String Item class for maven version comparator tasks.""" 67 | 68 | def __init__(self, str_version, followed_by_digit): 69 | """Initialize string value of version. 70 | 71 | :str_value: part of version supplied as string 72 | :followed_by_digit: True if str_version is followed by digit 73 | """ 74 | self.qualifiers = ["alpha", "beta", "milestone", "rc", "snapshot", "", "sp"] 75 | 76 | self.aliases = { 77 | "ga": "", 78 | "final": "", 79 | "cr": "rc" 80 | } 81 | 82 | self.release_version_index = str(self.qualifiers.index("")) 83 | self._decode_char_versions(str_version, followed_by_digit) 84 | 85 | def _decode_char_versions(self, value, followed_by_digit): 86 | """Decode short forms of versions.""" 87 | if followed_by_digit and len(value) == 1: 88 | if value.startswith("a"): 89 | value = "alpha" 90 | elif value.startswith("b"): 91 | value = "beta" 92 | elif value.startswith("m"): 93 | value = "milestone" 94 | 95 | self.value = self.aliases.get(value, value) 96 | 97 | def comparable_qualifier(self, qualifier): 98 | """Get qualifier that is comparable.""" 99 | q_index = None 100 | if qualifier in self.qualifiers: 101 | q_index = self.qualifiers.index(qualifier) 102 | q_index_not_found = str(len(self.qualifiers)) + "-" + qualifier 103 | 104 | return str(q_index) if q_index is not None else q_index_not_found 105 | 106 | def str_cmp(self, val1, val2): 107 | """Compare two strings.""" 108 | if val1.__lt__(val2): 109 | return -1 110 | if val1.__gt__(val2): 111 | return 1 112 | return 0 113 | 114 | def compare_to(self, item): 115 | """Compare two maven versions.""" 116 | if item is None: 117 | temp = self.str_cmp(self.comparable_qualifier(self.value), self.release_version_index) 118 | return temp 119 | if isinstance(item, IntegerItem): 120 | return -1 121 | if isinstance(item, StringItem): 122 | return self.str_cmp( 123 | self.comparable_qualifier( 124 | self.value), self.comparable_qualifier( 125 | item.value)) 126 | if isinstance(item, ListItem): 127 | return -1 128 | else: 129 | raise ValueError("invalid item" + str(type(item))) 130 | 131 | def to_string(self): 132 | """Return value in string form.""" 133 | return str(self.value) 134 | 135 | def __str__(self): 136 | """Return string value of version - Pythonish variant.""" 137 | return str(self.value) 138 | 139 | 140 | class ListItem(Item): 141 | """List Item class for maven version comparator tasks.""" 142 | 143 | def __init__(self): 144 | """Initialize string value of version.""" 145 | self.array_list = list() 146 | 147 | def add_item(self, item): 148 | """Add item to array list.""" 149 | self.array_list.append(item) 150 | 151 | def get_list(self): 152 | """Get object list items.""" 153 | return self.array_list 154 | 155 | def normalize(self): 156 | """Remove trailing items: 0, "", empty list.""" 157 | red_list = [0, None, ""] 158 | i = len(self.array_list) - 1 159 | while i >= 0: 160 | last_item = self.array_list[i] 161 | 162 | if not isinstance(last_item, ListItem): 163 | 164 | if last_item.value in red_list: 165 | self.array_list.pop(i) 166 | else: 167 | break 168 | 169 | i = i - 1 170 | 171 | def compare_to(self, item): 172 | """Compare two maven versions.""" 173 | # TODO: reduce cyclomatic complexity 174 | if item is None: 175 | if len(self.array_list) == 0: 176 | return 0 177 | first = self.array_list[0] 178 | return first.compare_to(None) 179 | 180 | if isinstance(item, IntegerItem): 181 | return -1 182 | if isinstance(item, StringItem): 183 | return 1 184 | if isinstance(item, ListItem): 185 | left_iter = iter(self.array_list) 186 | right_iter = iter(item.get_list()) 187 | 188 | while True: 189 | l_obj = next(left_iter, None) 190 | r_obj = next(right_iter, None) 191 | if l_obj is None and r_obj is None: 192 | break 193 | result = 0 194 | if l_obj is None: 195 | if r_obj is not None: 196 | result = -1 * r_obj.compare_to(l_obj) 197 | else: 198 | result = l_obj.compare_to(r_obj) 199 | if result != 0: 200 | return result 201 | 202 | return 0 203 | else: 204 | raise ValueError("invalid item" + str(type(item))) 205 | -------------------------------------------------------------------------------- /f8a_version_comparator/comparable_version.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Red Hat Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Author: Geetika Batra 16 | # 17 | 18 | """Module to implement Comparable Version class.""" 19 | 20 | import typing 21 | 22 | from .item_object import IntegerItem 23 | from .item_object import StringItem 24 | from .item_object import ListItem 25 | 26 | 27 | class ComparableVersion: 28 | """Class for Comparable Version.""" 29 | 30 | def __init__(self, version: str): 31 | """Initialize comparable version class. 32 | 33 | :version: Version supplied as a string 34 | """ 35 | if not isinstance(version, str): 36 | raise TypeError( 37 | "Invalid type {got!r} of argument `version`, expected {expected!r}".format( 38 | got=type(version), 39 | expected=str 40 | )) 41 | 42 | self.version = version 43 | self.items = self.parse_version() 44 | 45 | def __repr__(self): 46 | """Return representation of ComparableVersion object.""" 47 | return "{cls!s}(version={version!r})".format( 48 | cls=self.__class__.__name__, 49 | version=self.version 50 | ) 51 | 52 | def __str__(self): 53 | """Return version string held by ComparableVersion object.""" 54 | return "{version!s}".format( 55 | version=self.version 56 | ) 57 | 58 | def __eq__(self, other): 59 | """Compare ComparableVersion objects for equality. 60 | 61 | This rich comparison implies whether self == other 62 | """ 63 | # don't call compare_to(None) 64 | if other is None: 65 | return False 66 | 67 | return self.compare_to(other) == 0 68 | 69 | def __ne__(self, other): 70 | """Compare ComparableVersion objects for equality. 71 | 72 | This rich comparison implies whether self != other 73 | """ 74 | # don't call compare_to(None) 75 | if other is None: 76 | return True 77 | 78 | return self.compare_to(other) != 0 79 | 80 | def __lt__(self, other): 81 | """Compare ComparableVersion objects. 82 | 83 | This rich comparison implies whether self < other 84 | """ 85 | # don't call compare_to(None) 86 | if other is None: 87 | return False 88 | 89 | return self.compare_to(other) == -1 90 | 91 | def __le__(self, other): 92 | """Compare ComparableVersion objects. 93 | 94 | This rich comparison implies whether self <= other 95 | """ 96 | # don't call compare_to(None) 97 | if other is None: 98 | return False 99 | 100 | return self.compare_to(other) <= 0 101 | 102 | def __gt__(self, other): 103 | """Compare ComparableVersion objects. 104 | 105 | This rich comparison implies whether self > other 106 | """ 107 | # don't call compare_to(None) 108 | if other is None: 109 | return True 110 | 111 | return self.compare_to(other) == 1 112 | 113 | def __ge__(self, other): 114 | """Compare ComparableVersion objects. 115 | 116 | This rich comparison implies whether self >= other 117 | """ 118 | # don't call compare_to(None) 119 | if other is None: 120 | return True 121 | 122 | return self.compare_to(other) >= 0 123 | 124 | def parse_version(self): 125 | """Parse version.""" 126 | # TODO: reduce cyclomatic complexity 127 | ref_list = ListItem() 128 | items = ref_list 129 | parse_stack = list() 130 | version = self.version.lower() 131 | parse_stack.append(ref_list) 132 | _is_digit = False 133 | 134 | _start_index = 0 135 | 136 | for _ch in range(0, len(version)): 137 | 138 | ver_char = version[_ch] 139 | 140 | if ver_char == ".": 141 | 142 | if _ch == _start_index: 143 | ref_list.add_item(IntegerItem(0)) 144 | else: 145 | ref_list.add_item(self.parse_item(_is_digit, version[_start_index: _ch])) 146 | 147 | _start_index = _ch + 1 148 | 149 | elif ver_char == "-": 150 | if _ch == _start_index: 151 | ref_list.add_item(IntegerItem(0)) 152 | else: 153 | ref_list.add_item(self.parse_item(_is_digit, version[_start_index: _ch])) 154 | _start_index = _ch + 1 155 | 156 | temp = ListItem() 157 | ref_list.add_item(temp) 158 | ref_list = temp 159 | parse_stack.append(ref_list) 160 | elif ver_char.isdigit(): 161 | if not _is_digit and _ch > _start_index: 162 | ref_list.add_item(StringItem(version[_start_index: _ch], True)) 163 | _start_index = _ch 164 | 165 | temp = ListItem() 166 | ref_list.add_item(temp) 167 | ref_list = temp 168 | parse_stack.append(ref_list) 169 | _is_digit = True 170 | else: 171 | if _is_digit and _ch > _start_index: 172 | ref_list.add_item(self.parse_item(True, version[_start_index:_ch])) 173 | _start_index = _ch 174 | temp = ListItem() 175 | ref_list.add_item(temp) 176 | ref_list = temp 177 | parse_stack.append(ref_list) 178 | _is_digit = False 179 | 180 | if len(version) > _start_index: 181 | ref_list.add_item(self.parse_item(_is_digit, version[_start_index:])) 182 | 183 | while parse_stack: 184 | ref_list = parse_stack.pop() 185 | ref_list.normalize() 186 | 187 | return items 188 | 189 | @staticmethod 190 | def parse_item(_is_digit, buf): 191 | """Wrap items in version in respective object class.""" 192 | # TODO: make this function static (it does not need 'self') 193 | if _is_digit: 194 | return IntegerItem(buf) 195 | 196 | return StringItem(buf, False) 197 | 198 | def compare_to(self, obj: typing.Union["ComparableVersion", str]): 199 | """Compare two ComparableVersion objects.""" 200 | if isinstance(obj, ComparableVersion): 201 | # compare two objects of the same type 202 | cmp_result = self.items.compare_to(obj.items) 203 | elif isinstance(obj, str): 204 | # compare against string 205 | cmp_result = self.items.compare_to(ComparableVersion(obj).items) 206 | else: 207 | raise TypeError( 208 | "Invalid type {got!r} of argument `obj`, expected <{expected}>".format( 209 | got=type(obj), 210 | expected=typing.Union["ComparableVersion", str] 211 | )) 212 | 213 | return cmp_result 214 | -------------------------------------------------------------------------------- /test/vuldb_test.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright 2020 momosecurity. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | """ 16 | import unittest 17 | import sqlite3 18 | from vuldb import Checker, DB, ALLOW_SEVERITY 19 | 20 | 21 | class vuldbTest(unittest.TestCase): 22 | 23 | def setUp(self) -> None: 24 | self.db = sqlite3.connect(DB) 25 | 26 | def tearDown(self) -> None: 27 | if hasattr(self, 'db'): 28 | self.db.close() 29 | 30 | def test_get_dependencies_list(self): 31 | deps = { 32 | 'Name1': { 33 | 'name': 'Name1', 34 | 'version': 'version1', 35 | 'from': ['Name1@version1'], 36 | 'dependencies': { 37 | 'Name2': { 38 | 'name': 'Name2', 39 | 'version': 'version2', 40 | 'from': ['Name1@version1', 'Name2@version2'], 41 | 'dependencies': { 42 | 'Name3': { 43 | 'name': 'Name3', 44 | 'version': 'version3', 45 | 'from': ['Name1@version1', 'Name2@version2', 'Name3@version3'], 46 | 'dependencies': {} 47 | } 48 | } 49 | } 50 | } 51 | } 52 | } 53 | 54 | expect = [{ 55 | 'name': 'Name1', 56 | 'version': 'version1', 57 | 'from': ['Name1@version1'], 58 | 'root': '' 59 | }, { 60 | 'name': 'Name2', 61 | 'version': 'version2', 62 | 'from': ['Name1@version1', 'Name2@version2'], 63 | 'root': 'name1' 64 | }, { 65 | 'name': 'Name3', 66 | 'version': 'version3', 67 | 'from': ['Name1@version1', 'Name2@version2', 'Name3@version3'], 68 | 'root': 'name2' 69 | }] 70 | result = list(Checker._get_dependencies_list(deps)) 71 | self.assertEqual(expect, result) 72 | 73 | def test_get_vulrules(self): 74 | checker = Checker(self.db, 'Maven', {}, 'java', 'High') 75 | ruleset = checker.vulrules 76 | 77 | for name, rules in ruleset.items(): 78 | for rule in rules: 79 | self.assertEqual(rule['severity'], 'High') 80 | self.assertIsInstance(rule['vul_version_fr'], str) 81 | self.assertIsInstance(rule['vul_version_fr'], str) 82 | self.assertIsInstance(rule['target_version'], list) 83 | 84 | checker = Checker(self.db, 'Maven', {}, 'java', 'Low') 85 | ruleset = checker.vulrules 86 | for name, rules in ruleset.items(): 87 | for rule in rules: 88 | self.assertIn(rule['severity'], ALLOW_SEVERITY) 89 | 90 | checker = Checker(self.db, 'foo', {}, 'java', 'Low') 91 | ruleset = checker.vulrules 92 | self.assertEqual(ruleset, {}) 93 | 94 | def test_java_version_in(self): 95 | checker = Checker(self.db, 'Maven', {}, 'java', 'High') 96 | 97 | self.assertTrue(checker._version_in( 98 | '2.6.0', '1.3.0', '2.9.0' 99 | )) 100 | 101 | self.assertTrue(checker._version_in( 102 | '0.2.0-incubating', '0.1.0-incubating', '0.3.0-incubating' 103 | )) 104 | 105 | self.assertTrue(checker._version_in( 106 | '2.9.10.1', '2.0.0', '2.9.10.1' 107 | )) 108 | 109 | self.assertFalse(checker._version_in( 110 | '2.16', '2.0', '2.9' 111 | )) 112 | 113 | def test_other_version_in(self): 114 | checker = Checker(self.db, 'Composer', {}, 'php', 'High') 115 | 116 | self.assertTrue(checker._version_in( 117 | '1.3', '1.0', '2.0' 118 | )) 119 | 120 | self.assertTrue(checker._version_in( 121 | 'v1.3', '1.0', '2.0' 122 | )) 123 | 124 | self.assertFalse(checker._version_in( 125 | '1.3', 'v1.0', 'v1.2' 126 | )) 127 | 128 | self.assertTrue(checker._version_in( 129 | '1.3.rc1', '1.0', '1.3' 130 | )) 131 | 132 | def test_target_version_compare(self): 133 | checker = Checker(self.db, 'Composer', {}, 'php', 'High') 134 | 135 | self.assertTrue(checker._target_version_compare( 136 | {'target_version': ['2.6.6']}, 137 | {'target_version': ['2.6.5']}, 138 | )) 139 | 140 | self.assertTrue(checker._target_version_compare( 141 | {'target_version': ['4.0']}, 142 | {'target_version': ['2.6.5']}, 143 | )) 144 | 145 | def test_get_vuln(self): 146 | checker = Checker(self.db, 'Maven', {}, 'java', 'High') 147 | vuln = checker.get_vuln('com.alibaba:fastjson', '1.2.33') 148 | self.assertEqual(vuln['title'], 'Deserialization of Untrusted Data') 149 | self.assertEqual(vuln['severity'], 'High') 150 | self.assertEqual(vuln['target_version'], ['1.2.69']) 151 | 152 | def test_check_vuln(self): 153 | dependencies = { 154 | 'com.alibaba:fastjson': { 155 | 'name': 'com.alibaba:fastjson', 156 | 'version': '1.2.33', 157 | 'from': ['com.study:example@1.0.0', 'com.alibaba:fastjson@1.2.33'], 158 | 'dependencies': { 159 | 'com.study:inner': { 160 | 'name': 'com.study:inner', 161 | 'version': '1.2.3', 162 | 'from': ['com.study:example@1.0.0', 'com.alibaba:fastjson@1.2.33', 'com.study:inner@1.2.3'], 163 | 'dependencies': {} 164 | } 165 | } 166 | }, 167 | 'com.study:another': { 168 | 'name': 'com.study:another', 169 | 'version': '1.2.33', 170 | 'from': ['com.study:example@1.0.0', 'com.study:another@1.2.33'], 171 | 'dependencies': {} 172 | } 173 | } 174 | 175 | expect = { 176 | 'ok': False, 177 | 'dependencyCount': 2, 178 | 'vulnerabilities': [{ 179 | 'packageName': 'com.alibaba:fastjson', 180 | 'version': '1.2.33', 181 | 'from': ['com.study:example@1.0.0', 'com.alibaba:fastjson@1.2.33'], 182 | 'severity': 'High', 183 | 'target_version': ['1.2.69'], 184 | 'cve': 'CWE-502', 185 | 'title': 'Deserialization of Untrusted Data', 186 | }] 187 | } 188 | checker = Checker(self.db, 'Maven', dependencies, 'java', 'High') 189 | result = checker.check_vuln() 190 | self.assertEqual(expect, result) 191 | 192 | 193 | dependencies = { 194 | 'com.study:example': { 195 | 'name': 'com.study:example', 196 | 'version': '1.2.0', 197 | 'from': ['com.study:parent@1.0.0', 'com.study:example@1.2.0'], 198 | 'dependencies': {} 199 | } 200 | } 201 | expect = { 202 | 'ok': True, 203 | 'dependencyCount': 1, 204 | 'vulnerabilities': [] 205 | } 206 | checker = Checker(self.db, 'Maven', dependencies, 'java', 'High') 207 | result = checker.check_vuln() 208 | self.assertEqual(expect, result) 209 | 210 | 211 | if __name__ == '__main__': 212 | unittest.main() 213 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | https://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | Copyright 2020 momosecurity. 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /static/mosec-x-plugin-backend.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
开始
开始
当前依赖的父级依赖
是否有漏洞或已被忽略?
当前依赖的父级依赖 是否有漏洞或已被忽略?
end
end
Yes
Yes
No
No
对于列表中的
每一个依赖项
对于列表中的 每一个依赖项
使用当前依赖名称
进行漏洞数据检索
使用当前依赖名称 进行漏洞数据检索
使用当前依赖版本
进行漏洞数据版本范围匹配
使用当前依赖版本 进行漏洞数据版本范围匹配
依赖树平坦化
生成依赖列表
依赖树平坦化 生成依赖列表
将当前依赖节点
加入可忽略集合
将当前依赖节点 加入可忽略集合
漏洞规则数据
漏洞规则数据
版本匹配成功?
版本匹配成功?
No
No
列表遍历结束?
列表遍历结束?
No
No
当前依赖加入
最终结果列表
当前依赖加入 最终结果列表
结果返回
结果返回
Yes
Yes
Yes
Yes
版本匹配部分
对于Java 语言采用开源工具
fabric8-analytics-version-comparator 进行版本号解析与比对
对于其他语言采用 pkg_resources 库进行版本号解析与比对
版本匹配部分对于Java 语言采用开源工具...
依赖树数据结构参考
API小节内容
依赖树数据结构参考 API小节内容
Viewer does not support full SVG 1.1
--------------------------------------------------------------------------------