-
-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unity uses npm packages to distribute various types of features and assets. See: https://docs.unity3d.com/Manual/upm-manifestPkg.html The manifest files are using the same name and syntax, but the content, naming convention and of course the upstream repository are not the same. This is quite annoying because a Unity `package.json` file is gonna be detected as a NPM package from the npmjs registry, but it's actually coming from Unity's repo, which makes a big difference. Indeed, since both Unity and NodeJS are using NPM and the same package.json files, malicious packages have been pushed to the npmjs registry with the name of Unity packages. For example the package: `com.unity.scriptablebuildpipeline` is perfectly fine in Unity (https://docs.unity3d.com/Packages/[email protected]/manual/index.html), but is a malware in npmjs (https://www.npmjs.com/package/com.unity.scriptablebuildpipeline). This means that if ScanCode is being used in a Unity codebase and malicious packages checks are being executed, then we end up with a LOT of scary false positives. See this advisory: https://github.com/ossf/malicious-packages/blob/cca311974602d1940fab6a98adba611b505cf27d/malicious/npm/com.unity.scriptablebuildpipeline/MAL-2022-2102.json#L13 When matching an inventory against a list of malicious packages, one must take into account the repository from where the packages were fetched, we can't just rely on a canonical purl. This PR changes the NPM code that parses `package.json` to detect when a file is from UPM and change the urls accordingly so that scanners can take better decisions. This is probably out of scope for this PR, but maybe we should consider creating a separate purl type for UPM since they don't really share anything with NPM, except the package manager (different languages, different packages, different repositories, different tools etc). Signed-off-by: Adrien Schildknecht <[email protected]>
- Loading branch information
Showing
4 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "com.unity.ml-agents", | ||
"displayName": "ML Agents", | ||
"version": "3.0.0-exp.1", | ||
"unity": "2022.3", | ||
"description": "Use state-of-the-art machine learning to create intelligent character behaviors in any Unity environment (games, robotics, film, etc.).", | ||
"dependencies": { | ||
"com.unity.sentis": "1.2.0-exp.2", | ||
"com.unity.modules.imageconversion": "1.0.0", | ||
"com.unity.modules.jsonserialize": "1.0.0", | ||
"com.unity.modules.physics": "1.0.0" | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
tests/packagedcode/data/npm/upm/package/package.json.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
[ | ||
{ | ||
"type": "npm", | ||
"namespace": null, | ||
"name": "com.unity.ml-agents", | ||
"version": "3.0.0-exp.1", | ||
"qualifiers": {}, | ||
"subpath": null, | ||
"primary_language": null, | ||
"description": "Use state-of-the-art machine learning to create intelligent character behaviors in any Unity environment (games, robotics, film, etc.).", | ||
"release_date": null, | ||
"parties": [], | ||
"keywords": [], | ||
"homepage_url": "https://docs.unity3d.com/Packages/[email protected]/manual/index.html", | ||
"download_url": "https://download.packages.unity.com/com.unity.ml-agents/-/com.unity.ml-agents-3.0.0-exp.1.tgz", | ||
"size": null, | ||
"sha1": null, | ||
"md5": null, | ||
"sha256": null, | ||
"sha512": null, | ||
"bug_tracking_url": null, | ||
"code_view_url": null, | ||
"vcs_url": null, | ||
"copyright": null, | ||
"holder": null, | ||
"declared_license_expression": null, | ||
"declared_license_expression_spdx": null, | ||
"license_detections": [], | ||
"other_license_expression": null, | ||
"other_license_expression_spdx": null, | ||
"other_license_detections": [], | ||
"extracted_license_statement": null, | ||
"notice_text": null, | ||
"source_packages": [], | ||
"file_references": [], | ||
"extra_data": {}, | ||
"dependencies": [ | ||
{ | ||
"purl": "pkg:npm/com.unity.sentis", | ||
"extracted_requirement": "1.2.0-exp.2", | ||
"scope": "dependencies", | ||
"is_runtime": true, | ||
"is_optional": false, | ||
"is_resolved": false, | ||
"resolved_package": {}, | ||
"extra_data": {} | ||
}, | ||
{ | ||
"purl": "pkg:npm/com.unity.modules.imageconversion", | ||
"extracted_requirement": "1.0.0", | ||
"scope": "dependencies", | ||
"is_runtime": true, | ||
"is_optional": false, | ||
"is_resolved": false, | ||
"resolved_package": {}, | ||
"extra_data": {} | ||
}, | ||
{ | ||
"purl": "pkg:npm/com.unity.modules.jsonserialize", | ||
"extracted_requirement": "1.0.0", | ||
"scope": "dependencies", | ||
"is_runtime": true, | ||
"is_optional": false, | ||
"is_resolved": false, | ||
"resolved_package": {}, | ||
"extra_data": {} | ||
}, | ||
{ | ||
"purl": "pkg:npm/com.unity.modules.physics", | ||
"extracted_requirement": "1.0.0", | ||
"scope": "dependencies", | ||
"is_runtime": true, | ||
"is_optional": false, | ||
"is_resolved": false, | ||
"resolved_package": {}, | ||
"extra_data": {} | ||
} | ||
], | ||
"repository_homepage_url": "https://docs.unity3d.com/Manual/Packages.html", | ||
"repository_download_url": "https://packages.unity.com", | ||
"api_data_url": null, | ||
"datasource_id": "npm_package_json", | ||
"purl": "pkg:npm/[email protected]" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters