generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 30
fix: report known malware even when not labeled #956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Parent:
chore: merge changes to main
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,83 @@ | ||
| # Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved. | ||
| # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. | ||
|
|
||
| """This module contains implementation of deps.dev service.""" | ||
|
|
||
| import json | ||
| import logging | ||
| import urllib.parse | ||
| from json.decoder import JSONDecodeError | ||
| from urllib.parse import quote as encode | ||
|
|
||
| from macaron.config.defaults import defaults | ||
| from macaron.errors import APIAccessError | ||
| from macaron.util import send_get_http_raw | ||
|
|
||
| logger: logging.Logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class DepsDevService: | ||
| """The deps.dev service class.""" | ||
|
|
||
| @staticmethod | ||
| def get_package_info(purl: str) -> dict | None: | ||
| """Check if the package identified by the PackageURL (PURL) exists and return its information. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| purl: str | ||
| The PackageURL (PURL). | ||
|
|
||
| Returns | ||
| ------- | ||
| dict | None | ||
| The package metadata or None if it doesn't exist. | ||
|
|
||
| Raises | ||
| ------ | ||
| APIAccessError | ||
| If the service is misconfigured, the API is invalid, a network error happens, | ||
| or unexpected response is returned by the API. | ||
| """ | ||
| section_name = "deps_dev" | ||
| if not defaults.has_section(section_name): | ||
| return None | ||
| section = defaults[section_name] | ||
|
|
||
| url_netloc = section.get("url_netloc") | ||
| if not url_netloc: | ||
| raise APIAccessError( | ||
| f'The "url_netloc" key is missing in section [{section_name}] of the .ini configuration file.' | ||
| ) | ||
| url_scheme = section.get("url_scheme", "https") | ||
| purl_endpoint = section.get("purl_endpoint") | ||
| if not purl_endpoint: | ||
| raise APIAccessError( | ||
| f'The "purl_endpoint" key is missing in section [{section_name}] of the .ini configuration file.' | ||
| ) | ||
|
|
||
| path_params = "/".join([purl_endpoint, encode(purl, safe="")]) | ||
| try: | ||
| url = urllib.parse.urlunsplit( | ||
| urllib.parse.SplitResult( | ||
| scheme=url_scheme, | ||
| netloc=url_netloc, | ||
| path=path_params, | ||
| query="", | ||
| fragment="", | ||
| ) | ||
| ) | ||
| except ValueError as error: | ||
| raise APIAccessError("Failed to construct the API URL.") from error | ||
|
|
||
| response = send_get_http_raw(url) | ||
| if response and response.text: | ||
| try: | ||
| metadata: dict = json.loads(response.text) | ||
| except JSONDecodeError as error: | ||
| raise APIAccessError(f"Failed to process response from deps.dev for {url}.") from error | ||
| if not metadata: | ||
| raise APIAccessError(f"Empty response returned by {url} .") | ||
| return metadata | ||
|
|
||
| return None |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
| /* Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved. */ | ||
| /* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. */ | ||
|
|
||
| #include "prelude.dl" | ||
|
|
||
| Policy("check-malicious-package", component_id, "Check the malicious package.") :- | ||
| check_passed(component_id, "mcn_detect_malicious_metadata_1"). | ||
|
|
||
| apply_policy_to("check-malicious-package", component_id) :- | ||
| is_component(component_id, "pkg:pypi/ultralytics"). |
This file contains hidden or 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,21 @@ | ||
| # Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved. | ||
| # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. | ||
|
|
||
| description: | | ||
| Analyzing a popular package that some of its versions are compromised. | ||
|
|
||
| tags: | ||
| - macaron-python-package | ||
| - macaron-docker-image | ||
|
|
||
| steps: | ||
| - name: Run macaron analyze | ||
| kind: analyze | ||
| options: | ||
| command_args: | ||
| - -purl | ||
| - pkg:pypi/ultralytics | ||
| - name: Run macaron verify-policy to verify that the malicious metadata check passes. | ||
| kind: verify | ||
| options: | ||
| policy: policy.dl |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.