Repository navigation
Update zen-internals to v0.1.74 #760
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
Changes from all commits
0b9536f
d39dea1
bd6f257
7100ebf
293dfb6
391f3eb
f79332f
2185567
0678732
4b71dd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,30 +6,74 @@ | |||||||||||
| import ctypes | ||||||||||||
| import os | ||||||||||||
| import platform | ||||||||||||
| import sysconfig | ||||||||||||
|
|
||||||||||||
| from aikido_zen.helpers.get_lib_path import get_binary_path | ||||||||||||
| from aikido_zen.helpers.logging import logger | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| _TARGET = f"{platform.system().lower()}-{platform.machine().lower()}" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def _binary_path(): | ||||||||||||
| os_name = platform.system().lower() | ||||||||||||
| machine = platform.machine().lower() | ||||||||||||
| is_arm = "arm64" in machine or "aarch64" in machine | ||||||||||||
| file_name = "libzen_internals_" | ||||||||||||
|
|
||||||||||||
| # On macOS, platform.machine() returns "arm64" for Apple Silicon | ||||||||||||
| # On Linux, platform.machine() returns "aarch64" for ARM64 | ||||||||||||
| if is_arm: | ||||||||||||
| file_name += "aarch64-" | ||||||||||||
| # On macOS, platform.machine() returns "x86_64" for Intel | ||||||||||||
| # On Linux, platform.machine() returns "x86_64" for AMD64 | ||||||||||||
| elif "x86_64" in machine or "amd64" in machine: | ||||||||||||
| file_name += "x86_64-" | ||||||||||||
|
|
||||||||||||
| if os_name == "windows": | ||||||||||||
| file_name += "pc-windows-msvc.dll" if is_arm else "pc-windows-gnu.dll" | ||||||||||||
| elif os_name == "darwin": | ||||||||||||
| file_name += "apple-darwin.dylib" | ||||||||||||
| elif os_name in ["linux", "linux2"]: | ||||||||||||
| # The library must use the same libc as this Python, which records it at build | ||||||||||||
| # time (for example "x86_64-pc-linux-musl"). platform.libc_ver() and files under | ||||||||||||
| # /lib describe the system, which can have both glibc and musl installed. | ||||||||||||
| host = sysconfig.get_config_var("HOST_GNU_TYPE") or "" | ||||||||||||
| libc = "musl" if "musl" in host else "gnu" | ||||||||||||
| file_name += f"unknown-linux-{libc}.so" | ||||||||||||
|
|
||||||||||||
| return os.path.join( | ||||||||||||
| os.path.dirname(os.path.abspath(__file__)), "../libs", file_name | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def _load(): | ||||||||||||
| binary_path = get_binary_path() | ||||||||||||
| target = f"{platform.system().lower()}-{platform.machine().lower()}" | ||||||||||||
| binary_path = _binary_path() | ||||||||||||
| if not os.path.exists(binary_path): | ||||||||||||
| logger.warning( | ||||||||||||
| "Zen will NOT block SQL injection attacks. Cannot find the zen-internals library for %s. " | ||||||||||||
| "Cannot find the zen-internals library for %s. " | ||||||||||||
| "Request support: https://github.com/AikidoSec/firewall-python/issues", | ||||||||||||
| target, | ||||||||||||
| _TARGET, | ||||||||||||
| ) | ||||||||||||
| return None | ||||||||||||
| try: | ||||||||||||
| return ctypes.CDLL(binary_path) | ||||||||||||
| except OSError as e: | ||||||||||||
| logger.warning( | ||||||||||||
| "Zen will NOT block SQL injection attacks. Failed to load the zen-internals library for %s: %s", | ||||||||||||
| target, | ||||||||||||
| e, | ||||||||||||
| ) | ||||||||||||
| return None | ||||||||||||
| error = e | ||||||||||||
| # A musl Python built without HOST_GNU_TYPE picks the glibc build, which musl | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have CI tests using alpine linux? If not, let's add?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, adding now |
||||||||||||
| # cannot load. | ||||||||||||
| musl_path = os.path.join( | ||||||||||||
| os.path.dirname(binary_path), | ||||||||||||
| os.path.basename(binary_path).replace("-gnu.so", "-musl.so"), | ||||||||||||
| ) | ||||||||||||
|
Comment on lines
+64
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Building Show fix
Suggested change
Details✨ AI Reasoning Reply on this comment to give feedback or ignore the issue.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would bring back an earlier bug: replace changes every -gnu.so in the path, including folder names, so a library in a folder like app-gnu.so/ would never get the musl retry. test_load_falls_back_to_the_musl_build_when_the_glibc_build_fails covers this and fails with the suggested line.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔ You don't have permission to ignore issues. |
||||||||||||
| if musl_path != binary_path and os.path.exists(musl_path): | ||||||||||||
| try: | ||||||||||||
| return ctypes.CDLL(musl_path) | ||||||||||||
| except OSError: | ||||||||||||
| pass | ||||||||||||
| logger.warning( | ||||||||||||
| "Failed to load the zen-internals library for %s: %s", _TARGET, error | ||||||||||||
| ) | ||||||||||||
| return None | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def _bind(internals_lib, name, argtypes, restype): | ||||||||||||
|
|
@@ -39,7 +83,9 @@ def _bind(internals_lib, name, argtypes, restype): | |||||||||||
| try: | ||||||||||||
| function = getattr(internals_lib, name) | ||||||||||||
| except AttributeError: | ||||||||||||
| logger.debug("The zen-internals library has no function %s", name) | ||||||||||||
| logger.warning( | ||||||||||||
| "The zen-internals library for %s has no %s function.", _TARGET, name | ||||||||||||
| ) | ||||||||||||
| return None | ||||||||||||
| function.argtypes = argtypes | ||||||||||||
| function.restype = restype | ||||||||||||
|
|
@@ -60,6 +106,8 @@ def _bind(internals_lib, name, argtypes, restype): | |||||||||||
| ], | ||||||||||||
| ctypes.c_int, | ||||||||||||
| ) | ||||||||||||
| if _detect_sql_injection is None: | ||||||||||||
| logger.warning("Zen will NOT block SQL injection attacks.") | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def detect_sql_injection(query: bytes, user_input: bytes, dialect: int) -> int: | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binary, code or archive is pulled from a remote source without integrity verification - medium severity
A GitHub Actions Workflow was built using an artifact from a remote source without any integrity verification. If the remote artifact were silently replaced with a malicious version (for example, through a supply chain attack), the integrity and confidentiality of the environment in which the container is deployed could be compromised.
Show fix
Remediation: Validate the artifact against a trusted SHA-512 checksum in the CI/CD pipeline using
sha512sumin check mode. Store the expected checksum in a file (e.g.,artifact.sha512), then verify it with:sha512sum -c artifact.sha512. Enable strict error handling (for example,set -ein shell scripts) so the pipeline fails if verification fails or outputs errors.Reply
@AikidoSec ignore: [REASON]to ignore this issue.More info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same safe-chain install line used in the other 8 workflows here and in firewall-node, and none of them pin a version.