Skip to content

Commit 6f9c823

Browse files
committed
Merge branch 'main' into lelia/version-check-pypi-retry
2 parents 9a01000 + 2ab48d9 commit 6f9c823

9 files changed

Lines changed: 413 additions & 89 deletions

File tree

‎.github/workflows/version-check.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ jobs:
7777
7878
# This is a required check, so a dropped connection to PyPI would
7979
# otherwise block the merge until someone reruns the job. Retry
80-
# network errors, timeouts and 5xx responses, and if PyPI still can't
81-
# be read, say so instead of failing with a bare traceback that looks
82-
# like a version problem. OSError covers URLError, timeouts and SSL
80+
# network errors, timeouts, rate limits (429) and 5xx responses, and
81+
# if PyPI still can't be read, say so instead of failing with a bare
82+
# traceback that looks like a version problem. OSError covers URLError, timeouts and SSL
8383
# errors; HTTPException covers a response cut off mid-read, which
8484
# urllib doesn't wrap in URLError.
8585
pypi_url = "https://pypi.org/pypi/socketsecurity/json"
@@ -91,7 +91,7 @@ jobs:
9191
pypi_data = json.load(response)
9292
break
9393
except urllib.error.HTTPError as exc:
94-
if exc.code < 500:
94+
if exc.code < 500 and exc.code != 429:
9595
print(
9696
f"❌ PyPI returned HTTP {exc.code} for {pypi_url}, so the "
9797
f"latest published version couldn't be read. This is "

‎CHANGELOG.md‎

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,103 @@
11
# Changelog
22

3-
## 2.15.2
3+
## 2.15.11
44

55
### Changed: retry the PyPI lookup in the version check
66

77
- The `check_version` CI job now retries the PyPI request on connection
8-
errors, timeouts and HTTP 5xx, and says when a failure is PyPI's rather
9-
than the PR's version. No change to the CLI itself.
8+
errors, timeouts, HTTP 429 and HTTP 5xx, and says when a failure is PyPI's
9+
rather than the PR's version. No change to the CLI itself.
10+
11+
## 2.15.10
12+
13+
### Added
14+
15+
- Set `SOCKET_COANA_MIRROR_URL` to download the reachability engine through a
16+
mirror of `storage.googleapis.com/socket-coana-cli`.
17+
18+
### Changed: update the Docker image's PyPy to 8.1.1
19+
20+
- The amd64 Docker image now ships PyPy `8.1.1` (Python 3.12), up from PyPy
21+
`8.0.1`.
22+
23+
### Changed: bump pinned Coana CLI to 15.15.12
24+
25+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.11` to
26+
`15.15.12`. See the
27+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
28+
for engine changes.
29+
30+
## 2.15.9
31+
32+
### Changed: bump pinned Coana CLI to 15.15.11
33+
34+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.10` to
35+
`15.15.11`. See the
36+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
37+
for engine changes.
38+
39+
## 2.15.8
40+
41+
### Changed: bump pinned Coana CLI to 15.15.10
42+
43+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.9` to
44+
`15.15.10`. See the
45+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
46+
for engine changes.
47+
48+
## 2.15.7
49+
50+
### Changed: bump pinned Coana CLI to 15.15.9
51+
52+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.8` to
53+
`15.15.9`. See the
54+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
55+
for engine changes.
56+
57+
## 2.15.6
58+
59+
### Changed: bump pinned Coana CLI to 15.15.8
60+
61+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.7` to
62+
`15.15.8`. See the
63+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
64+
for engine changes.
65+
66+
## 2.15.5
67+
68+
### Changed: bump pinned Coana CLI to 15.15.7
69+
70+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.6` to
71+
`15.15.7`. See the
72+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
73+
for engine changes.
74+
75+
## 2.15.4
76+
77+
### Changed: bump pinned Coana CLI to 15.15.6
78+
79+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.5` to
80+
`15.15.6`. See the
81+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
82+
for engine changes.
83+
84+
## 2.15.3
85+
86+
### Changed: bump pinned Coana CLI to 15.15.5
87+
88+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.4` to
89+
`15.15.5`. See the
90+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
91+
for engine changes.
92+
93+
## 2.15.2
94+
95+
### Changed: bump pinned Coana CLI to 15.15.4
96+
97+
- Bumped the pinned reachability engine (the Coana CLI) from `15.15.3` to
98+
`15.15.4`. See the
99+
[reachability analysis changelog](https://docs.socket.dev/docs/reachability-analysis-changelog)
100+
for engine changes.
10101

11102
## 2.15.1
12103

‎Dockerfile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ RUN if [ "$DOTNET_VERSION" = "6" ]; then \
8989
# This is a custom build of PyPy3.12 for Alpine on x86-64.
9090
ARG TARGETARCH # Passed by Docker buildx
9191
RUN if [ "$TARGETARCH" = "amd64" ]; then \
92-
PYPY_URL="https://github.com/BarrensZeppelin/alpine-pypy/releases/download/alp3.24.2-pypy3.12-8.0.1/pypy3.12-v8.0.1-linux64-alpine3.24.tar.gz" && \
93-
PYPY_SHA256="b6d5dd429c6394f1710a52e3e20d5c9198547caff9528547c457d3f2ed37db09" && \
92+
PYPY_URL="https://github.com/BarrensZeppelin/alpine-pypy/releases/download/alp3.24.4-pypy3.12-8.1.1/pypy3.12-v8.1.1-linux64-alpine3.24.tar.gz" && \
93+
PYPY_SHA256="c6c630c7a37a97977014cdd6252a6331fb2cfccddffe15a0a5590480f4741c2c" && \
9494
curl -L -o /tmp/pypy.tar.gz "$PYPY_URL" && \
9595
echo "$PYPY_SHA256 /tmp/pypy.tar.gz" | sha256sum -c - && \
9696
mkdir -p /opt/pypy && \

‎docs/cli-reference.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ docs.socket.dev use `SOCKET_SECURITY_API_KEY`. Either works. If both are set,
353353
| Parameter | Required | Default | Description |
354354
|:---------------------------------|:---------|:--------|:---------------------------------------------------------------------------------------------------------------------------|
355355
| `--reach` | False | False | Enable reachability analysis to identify which vulnerable functions are actually called by your code. Creates a full application reachability scan (`scan_type=socket_tier1`). |
356-
| `--reach-version` | False | 15.15.3 | Version of the Coana CLI to use. Defaults to the pinned version that ships with this CLI release, so the engine only changes when you upgrade the Socket CLI. Pass `latest` to always use the newest published version (opt-in auto-update), or an explicit version (e.g. `1.2.3`) to pin it. |
356+
| `--reach-version` | False | 15.15.12 | Version of the Coana CLI to use. Defaults to the pinned version that ships with this CLI release, so the engine only changes when you upgrade the Socket CLI. Pass `latest` to always use the newest published version (opt-in auto-update), or an explicit version (e.g. `1.2.3`) to pin it. |
357357
| `--reach-analysis-timeout` | False | 10m | Timeout for each reachability analysis run, e.g. `90s`, `10m` or `1h`. Omitted by default, so coana applies its own default (`10m`). Alias: `--reach-timeout` |
358358
| `--reach-analysis-memory-limit` | False | 8GB | Memory limit for each reachability analysis run, e.g. `512MB` or `8GB`. Omitted by default, so coana applies its own default (`8GB`). Alias: `--reach-memory-limit` |
359359
| `--reach-concurrency` | False | 1 | Control parallel analysis execution (must be >= 1). Omitted by default, so coana applies its own default. |

‎pyproject.toml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.15.2"
9+
version = "2.15.11"
1010
requires-python = ">= 3.11"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [
1313
"requests==2.34.2",
1414
"mdutils==1.8.1",
15-
"prettytable==3.18.0",
15+
"prettytable==3.19.0",
1616
"gitpython==3.2.1",
17-
"packaging==26.3",
17+
"packaging==26.4",
1818
"python-dotenv==1.2.4",
1919
"socketdev==3.6.4",
2020
"beautifulsoup4==4.15.0",
21-
"markdown==3.11.3",
21+
"markdown==3.11.4",
2222
"brotli==1.2.1; platform_python_implementation == 'CPython'",
2323
"brotlicffi==1.2.1.0; platform_python_implementation != 'CPython'",
2424
# requests' CA bundle. A floor rather than an exact pin, so later trust-store
@@ -51,9 +51,9 @@ test = [
5151
"pytest-watch==4.2.0"
5252
]
5353
dev = [
54-
"ruff==0.17.5",
54+
"ruff==0.17.6",
5555
"twine==7.0.0", # for building
56-
"uv==0.13.8", # for dependency management
56+
"uv==0.13.10", # for dependency management
5757
"pre-commit==4.7.0",
5858
"hatch==1.18.2"
5959
]

‎socketsecurity/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.15.2'
2+
__version__ = '2.15.11'
33
USER_AGENT_NAME = 'socket-python-cli'
44
USER_AGENT = f'{USER_AGENT_NAME}/{__version__}'

‎socketsecurity/core/tools/reachability.py‎

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import tempfile
1212
from dataclasses import dataclass
1313
from typing import Any, Dict, Final, List, Mapping, Optional
14+
from urllib.parse import unquote, urlsplit
1415

1516
import requests
17+
from urllib3.util import parse_url
1618

1719
from socketsecurity import USER_AGENT, __version__
1820
from socketsecurity.core.cli_client import CliClient
@@ -22,13 +24,15 @@
2224
# Pinned Coana CLI version. Bumped deliberately per Python CLI release so the
2325
# reachability engine version only changes through a standard pip upgrade (advance notice).
2426
# Pass --reach-version latest to opt into the newest published version instead.
25-
DEFAULT_COANA_CLI_VERSION: Final = "15.15.3"
27+
DEFAULT_COANA_CLI_VERSION: Final = "15.15.12"
2628

2729
# Vendored from coana-package-manager, where it is generated; the only code that may read or
2830
# write the cache Coana shares with the Socket CLIs. See "Launching Coana" in that repo's
2931
# packages/cli/docs/gcs-releases.md.
3032
_COANA_CACHE_SCRIPT: Final = pathlib.Path(__file__).with_name("coana-cache.mjs")
3133
_COANA_COMPONENT: Final = "cli"
34+
# SOCKET_COANA_MIRROR_URL replaces this prefix of the signed URLs.
35+
_COANA_BUCKET_URL: Final = "https://storage.googleapis.com/socket-coana-cli/"
3236
_NOT_CACHED_EXIT_CODE: Final = 4
3337

3438
_EXACT_VERSION: Final = re.compile(r"\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?")
@@ -75,6 +79,54 @@ def parse(cls, value: object) -> Optional["_CoanaArtifacts"]:
7579
return cls(version=version, cli=_CoanaComponent(sha256=sha256, size=size, url=url))
7680

7781

82+
@dataclass(frozen=True)
83+
class _CoanaMirror:
84+
"""A mirror of Coana's bucket, which SOCKET_COANA_MIRROR_URL names.
85+
86+
"Downloading through a mirror" in coana-package-manager's packages/cli/docs/gcs-releases.md
87+
specifies the rule.
88+
"""
89+
90+
# Ends in "/".
91+
base_url: str
92+
93+
@classmethod
94+
def parse(cls, value: Optional[str]) -> Optional["_CoanaMirror"]:
95+
"""The mirror ``value`` names, or None when it is unset or empty."""
96+
if not value:
97+
return None
98+
try:
99+
parts = urlsplit(value)
100+
# Raises ValueError for an invalid port.
101+
parts.port
102+
except ValueError:
103+
parts = None
104+
# urlsplit drops a bare "?" or "#".
105+
if (
106+
parts is None
107+
or parts.scheme not in ("http", "https")
108+
or not parts.hostname
109+
or "?" in value
110+
or "#" in value
111+
):
112+
# The value may carry credentials.
113+
raise Exception("SOCKET_COANA_MIRROR_URL must be an http or https URL without a query or fragment.")
114+
return cls(value if value.endswith("/") else f"{value}/")
115+
116+
def download_url(self, signed_url: str) -> str:
117+
"""Where to download ``signed_url`` from. The query, which holds the signature, is kept."""
118+
rest = signed_url.removeprefix(_COANA_BUCKET_URL)
119+
# A dot segment could climb out of the bucket, or out of the mirror's base URL.
120+
if rest == signed_url or any(
121+
unquote(segment) in (".", "..") for segment in rest.partition("?")[0].split("/")
122+
):
123+
raise Exception(
124+
f"Socket provided the Coana CLI at {signed_url.partition('?')[0]}, "
125+
f"outside {_COANA_BUCKET_URL}, which SOCKET_COANA_MIRROR_URL mirrors."
126+
)
127+
return self.base_url + rest
128+
129+
78130
class _DownloadRefused(Exception):
79131
"""The download host refused a signed URL with a 4xx, e.g. because it expired."""
80132

@@ -356,18 +408,20 @@ def request_artifacts(spec: str) -> _CoanaArtifacts:
356408
return artifacts
357409

358410
def download(component: _CoanaComponent, dest: pathlib.Path) -> None:
411+
url = component.url if mirror is None else mirror.download_url(component.url)
412+
host = parse_url(url).netloc
359413
with requests.get(
360-
component.url,
414+
url,
361415
headers={"User-Agent": USER_AGENT},
362416
stream=True,
363417
timeout=_DOWNLOAD_TIMEOUT,
364418
verify=not self.client.config.allow_unverified_ssl,
365419
) as response:
366420
if 400 <= response.status_code < 500:
367-
raise _DownloadRefused(
368-
f"The download host refused the Coana CLI URL with status {response.status_code}"
369-
)
370-
response.raise_for_status()
421+
raise _DownloadRefused(f"{host} refused the Coana CLI URL with status {response.status_code}")
422+
# The URL holds the signature, and a mirror's URL may carry credentials.
423+
if not response.ok:
424+
raise Exception(f"{host} responded with status {response.status_code} to the Coana CLI download")
371425
digest = hashlib.sha256()
372426
received = 0
373427
with dest.open("wb") as f:
@@ -397,6 +451,8 @@ def regular_files_only(member: tarfile.TarInfo, path: str) -> Optional[tarfile.T
397451
if artifacts.version != version_spec and (cached := lookup(artifacts.version)):
398452
return cached
399453

454+
# Parsed only once a download is certain, so a warm cache never trips on a stale value.
455+
mirror = _CoanaMirror.parse(env.get("SOCKET_COANA_MIRROR_URL"))
400456
log.info(f"Downloading the Coana CLI {artifacts.version}...")
401457
with tempfile.TemporaryDirectory(prefix="socket-coana-cli-") as tmp:
402458
tarball = pathlib.Path(tmp, "cli.tar.gz")

0 commit comments

Comments
 (0)