Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-lastversion for
openSUSE:Factory checked in at 2026-11-27 19:45:28
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-lastversion (Old)
and /work/SRC/openSUSE:Factory/.python-lastversion.new.1340718 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-lastversion"
Fri Nov 27 19:45:28 2026 rev:5 rq:1401170 version:3.6.20
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-lastversion/python-lastversion.changes
2026-10-06 19:16:53.641709903 +0200
+++
/work/SRC/openSUSE:Factory/.python-lastversion.new.1340718/python-lastversion.changes
2026-11-27 19:49:47.423977094 +0100
@@ -1,0 +2,9 @@
+Fri Nov 27 15:15:37 UTC 2026 - Markéta Machová <[email protected]>
+
+- update to 3.6.20 (bsc#1292110, CVE-2026-137539)
+ * lastversion extract now rejects tar entries and links that
+ point outside the extraction directory. Safe links within the
+ archive are preserved.
+- Convert to libalternatives on SLE-16-based and newer systems
+
+-------------------------------------------------------------------
Old:
----
lastversion-3.6.19.tar.gz
New:
----
lastversion-3.6.20.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-lastversion.spec ++++++
--- /var/tmp/diff_new_pack.M5WgMD/_old 2026-11-27 19:49:48.754033566 +0100
+++ /var/tmp/diff_new_pack.M5WgMD/_new 2026-11-27 19:49:48.761033863 +0100
@@ -16,8 +16,13 @@
#
+%if 0%{?suse_version} > 1500
+%bcond_without libalternatives
+%else
+%bcond_with libalternatives
+%endif
Name: python-lastversion
-Version: 3.6.19
+Version: 3.6.20
Release: 0
Summary: Find the latest stable release version of an arbitrary project
License: BSD-2-Clause
@@ -39,9 +44,14 @@
Requires: python-python-dateutil
Requires: python-requests >= 2.16.0
Requires: python-tqdm
+BuildArch: noarch
+%if %{with libalternatives}
+BuildRequires: alts
+Requires: alts
+%else
Requires(post): update-alternatives
Requires(postun): update-alternatives
-BuildArch: noarch
+%endif
# SECTION test requirements
BuildRequires: %{python_module CacheControl}
BuildRequires: %{python_module PyYAML}
@@ -80,6 +90,9 @@
%postun
%python_uninstall_alternative lastversion
+%pre
+%python_libalternatives_reset_alternative lastversion
+
%check
# Mosts tests require network connection
%pytest -k "test_version_parse"
++++++ lastversion-3.6.19.tar.gz -> lastversion-3.6.20.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/.cursor/rules/00-maintenance.mdc
new/lastversion-3.6.20/.cursor/rules/00-maintenance.mdc
--- old/lastversion-3.6.19/.cursor/rules/00-maintenance.mdc 2026-10-03
17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/.cursor/rules/00-maintenance.mdc 1970-01-01
01:00:00.000000000 +0100
@@ -1,12 +0,0 @@
----
-description: Project maintenance standards (Always)
-globs:
-alwaysApply: true
----
-
-- Keep these rules up to date. When you add architecture decisions, new
modules/services, or workflows, update or add a rule file so future iterations
are faster and consistent.
-- Use /Generate Cursor Rules after major changes to persist new guidance.
-- Split large rules into smaller, focused rules (under ~500 lines).
-- Reference files with @ so current code is attached to the context when the
rule triggers.
-- For PRs: summarize rule updates in the description; new features MUST update
or add rules alongside tests.
-- Prefer nested rules (`.cursor/rules` in subdirectories) for module-specific
guidance; they’ll auto-attach when those files are in context.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/.cursor/rules/12-python.mdc
new/lastversion-3.6.20/.cursor/rules/12-python.mdc
--- old/lastversion-3.6.19/.cursor/rules/12-python.mdc 2026-10-03
17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/.cursor/rules/12-python.mdc 1970-01-01
01:00:00.000000000 +0100
@@ -1,13 +0,0 @@
----
-description: Python interpreter and tooling (Always)
-globs:
- alwaysApply: true
----
-
-- Use the Python interpreter at
`${env:HOME}/.virtualenvs/lastversion/bin/python` for all Python execution in
this workspace.
-- When running tests, use: `${env:HOME}/.virtualenvs/lastversion/bin/python -m
pytest` (not bare `pytest`).
-- When invoking scripts or modules (formatters, linters, CLI tools), call them
via the interpreter: `${env:HOME}/.virtualenvs/lastversion/bin/python -m
<module>`.
-- Prefer this interpreter for local runs, CI, and any automation unless
explicitly overridden.
-- Source `~/.secrets` prior to running tests, as this file contains the
required API tokens.
-- Run pylint via the interpreter before commits/PRs:
`${env:HOME}/.virtualenvs/lastversion/bin/python -m pylint src tests`.
-- Use project-local config if present (e.g., `pyproject.toml` or `pylintrc`).
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/.cursor/rules/50-docstrings.mdc
new/lastversion-3.6.20/.cursor/rules/50-docstrings.mdc
--- old/lastversion-3.6.19/.cursor/rules/50-docstrings.mdc 2026-10-03
17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/.cursor/rules/50-docstrings.mdc 1970-01-01
01:00:00.000000000 +0100
@@ -1,16 +0,0 @@
-Title: Google-style docstrings for all functions
-
-Scope:
-- Apply to all Python functions, methods, and coroutines in this repo
-- New and edited code must include Google-style docstrings
-
-Rules:
-- Use Google docstring format with sections: Summary, Args, Returns, Raises
(as applicable)
-- First line: one-sentence summary in imperative mood, ending with a period
-- Add type information in Args and Returns sections even if type hints exist
-- Document coroutine behavior where relevant (e.g., long-running tasks,
cancellation)
-- Keep docstrings concise and specific to behavior; avoid restating obvious
type hints
-
-Enforcement:
-- PRs must include docstrings for all new/modified functions
-- Lint review may reject code without proper docstrings
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/.github/workflows/docs.yml
new/lastversion-3.6.20/.github/workflows/docs.yml
--- old/lastversion-3.6.19/.github/workflows/docs.yml 2026-10-03
17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/.github/workflows/docs.yml 2026-11-25
18:47:02.000000000 +0100
@@ -20,7 +20,7 @@
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
- python-version: '3.10'
+ python-version: '3.12'
cache: 'pip' # caching pip dependencies will speed up subsequent runs
- run: pip install -e .
- run: pip install -r docs/requirements.txt
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lastversion-3.6.19/.github/workflows/pythonpackage.yml
new/lastversion-3.6.20/.github/workflows/pythonpackage.yml
--- old/lastversion-3.6.19/.github/workflows/pythonpackage.yml 2026-10-03
17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/.github/workflows/pythonpackage.yml 2026-11-25
18:47:02.000000000 +0100
@@ -54,9 +54,27 @@
with:
name: nginx-module-security-headers.spec
path: tests/nginx-module-security-headers.spec
+ py36-el7-deps:
+ # The EL7 RPM runs on distro python36-* packages, far older than what pip
+ # resolves for the py36 job above (3.6.18 crashed on EL7's urllib3 1.25).
+ runs-on: ubuntu-latest
+ container: python:3.6
+ steps:
+ - uses: actions/checkout@v4
+ - name: Install dependencies pinned to EL7 versions
+ run: |
+ python -m pip install --upgrade pip
+ pip install -c ci/constraints-el7.txt -e '.[tests]'
+ python -c "import urllib3, requests, cachecontrol, packaging;
print(urllib3.__version__, requests.__version__, cachecontrol.__version__,
packaging.__version__)"
+ - name: Test with pytest
+ run: pytest -v -n auto
+ env:
+ # Use custom token if available, otherwise fall back to GITHUB_TOKEN
(for Dependabot PRs)
+ LASTVERSION_GITHUB_API_TOKEN: ${{
secrets.LASTVERSION_GITHUB_API_TOKEN || github.token }}
build:
- runs-on: ubuntu-latest
+ # setup-python provides Python 3.9 for Ubuntu 24.04.
+ runs-on: ubuntu-24.04
strategy:
max-parallel: 7
matrix:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/CHANGELOG.md
new/lastversion-3.6.20/CHANGELOG.md
--- old/lastversion-3.6.19/CHANGELOG.md 2026-10-03 17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/CHANGELOG.md 2026-11-25 18:47:02.000000000 +0100
@@ -1,6 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.
+## [3.6.20] - 2026-11-26
+### Security
+* `lastversion extract` now rejects tar entries and links that point outside
the extraction directory. Safe links within the archive are preserved. [Issue
#246](https://github.com/dvershinin/lastversion/issues/246)
+
+### Changed
+* Added type annotations to three GitHub tag classification helpers. [Issue
#245](https://github.com/dvershinin/lastversion/issues/245)
+
## [3.6.19] - 2026-10-03
### Fixed
* Fixed crash on urllib3 < 1.26 (EL7/EL8 system packages): `Retry() got an
unexpected keyword argument 'allowed_methods'`
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/CLAUDE.md
new/lastversion-3.6.20/CLAUDE.md
--- old/lastversion-3.6.19/CLAUDE.md 2026-10-03 17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/CLAUDE.md 1970-01-01 01:00:00.000000000 +0100
@@ -1,90 +0,0 @@
-# CLAUDE.md
-
-This file provides guidance to Claude Code (claude.ai/code) when working with
code in this repository.
-
-## Project
-
-**lastversion** — CLI tool and Python library that finds the latest stable
release version of software projects across multiple hosting platforms (GitHub,
GitLab, PyPI, Bitbucket, SourceForge, WordPress, etc.). Used heavily in RPM
build automation and CI/CD pipelines.
-
-## Development Setup
-
-- **Virtualenv:** `~/.virtualenvs/lastversion/`
-- **Secrets:** Source `~/.secrets` before running tests (contains
`GITHUB_API_TOKEN` and other API tokens)
-
-## Common Commands
-
-```bash
-# Run all tests (sources secrets, activates venv, parallel execution with
10min timeout)
-make test
-
-# Run a single test
-source ~/.secrets && ~/.virtualenvs/lastversion/bin/python -m pytest
tests/test_github.py::test_function_name -v
-
-# Lint
-~/.virtualenvs/lastversion/bin/python -m flake8 src tests
-~/.virtualenvs/lastversion/bin/python -m pylint src tests
-
-# Security scan
-~/.virtualenvs/lastversion/bin/python -m bandit -c pyproject.toml -r
src/lastversion
-
-# Release (CI auto-publishes to PyPI on GitHub release creation)
-# 1. Bump __version__ in src/lastversion/__about__.py
-# 2. Commit: git commit -m "chore(release): X.Y.Z"
-# 3. Tag: git tag -s vX.Y.Z -m "vX.Y.Z"
-# 4. Push: git push origin master && git push origin vX.Y.Z
-# 5. Create release: gh release create vX.Y.Z --title "vX.Y.Z" --notes "..."
-# CI workflow pythonpublish.yml handles PyPI upload automatically.
-# Do NOT use `make publish` or manual `twine upload`.
-make publish # backup only, prefer CI
-
-# Build single binary
-make one-file
-```
-
-## Architecture
-
-### Repository Holder Pattern
-
-Core abstraction: `BaseProjectHolder` (in
`src/lastversion/repo_holders/base.py`) is the abstract base class for all
hosting platform adapters. Each adapter lives in
`src/lastversion/repo_holders/` and implements release discovery for its
platform.
-
-`HolderFactory` (`holder_factory.py`) maintains an ordered registry of
adapters and selects the appropriate one based on the input URL/name. Detection
order matters — adapters are tried in registration order.
-
-### Key Modules
-
-- **`lastversion.py`** — Core logic: `latest()`, `has_update()`,
`check_version()` entry points
-- **`cli.py`** — CLI argument parsing, all subcommands (get, download,
extract, install, update-spec, etc.)
-- **`version.py`** — `Version` class extending `packaging.Version` with
normalization for messy real-world version strings (dashed versions,
Java-style, pre-release variants)
-- **`cache.py`** — Dual-level caching: HTTP-level (CacheControl/ETag) +
release-data-level (File or Redis backend) with PID-based file locking
-- **`config.py`** — Platform-aware config singleton
(`~/.config/lastversion/lastversion.yml` on Linux, `~/Library/Application
Support/lastversion/lastversion.yml` on macOS)
-
-### GitHub Adapter (`repo_holders/github.py`)
-
-Most complex adapter. Uses GraphQL API with REST fallback. Handles rate
limiting, API tokens (`GITHUB_API_TOKEN`/`GITHUB_TOKEN` env vars), commit-based
version extraction, and release note parsing.
-
-### RPM Spec Integration
-
-`update-spec` command parses `.spec` files for `%{upstream_github}`, `%global
lastversion_repo`, and `%global lastversion_*` directives to determine repo and
version constraints.
-
-## Testing
-
-- **Framework:** pytest with pytest-xdist (parallel: `-n auto`)
-- **CI matrix:** Python 3.6, 3.9, 3.13
-- Tests include live API calls — require valid API tokens
-- Test files mirror the module structure: `test_github.py`, `test_gitlab.py`,
`test_pypi.py`, etc.
-- Helper utilities in `tests/helpers.py`
-
-## Linting
-
-- **flake8:** max-line-length=120, select C,E,F,W,B,B950, ignore
E203/E501/E704 (configured in `setup.cfg`)
-- **bandit:** security scanning configured in `pyproject.toml`
-- **pre-commit:** ruff, flake8, black, isort, bandit — all at line-length 120
-
-## Code Style
-
-- **Docstrings:** Google-style on all new/modified functions. First line:
one-sentence imperative summary ending with a period. Include Args, Returns,
Raises sections with type info even if type hints exist. Document coroutine
behavior where relevant.
-- **Interpreter:** Always use `~/.virtualenvs/lastversion/bin/python` — never
bare `python` or `pytest`.
-- **PRs:** Must include docstrings for new/modified functions. Must update
`.cursor/rules/` if adding new modules or architectural changes.
-
-## Python Compatibility
-
-Supports Python 3.6+. Conditional dependencies exist for `cachecontrol` and
`urllib3` based on Python version (see `setup.py`).
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/Makefile
new/lastversion-3.6.20/Makefile
--- old/lastversion-3.6.19/Makefile 2026-10-03 17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/Makefile 2026-11-25 18:47:02.000000000 +0100
@@ -1,10 +1,12 @@
+SECRETS_FILE ?= $(HOME)/.secrets
+
test:
- @if [ -f ~/.secrets ]; then \
- echo "Sourcing ~/.secrets..."; \
- . ~/.secrets; \
+ @if [ -f "$(SECRETS_FILE)" ]; then \
+ echo "Sourcing $(SECRETS_FILE)..."; \
+ . "$(SECRETS_FILE)"; \
fi; \
if [ -z "$$GITHUB_API_TOKEN" ]; then \
- echo "Error: GITHUB_API_TOKEN is not set. Please set it in
~/.secrets or environment."; \
+ echo "Error: GITHUB_API_TOKEN is not set. Please set it in
$(SECRETS_FILE) or environment."; \
exit 1; \
fi; \
if [ -f ${HOME}/.virtualenvs/lastversion/bin/python ]; then \
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/README-ZH-CN.md
new/lastversion-3.6.20/README-ZH-CN.md
--- old/lastversion-3.6.19/README-ZH-CN.md 2026-10-03 17:06:48.000000000
+0200
+++ new/lastversion-3.6.20/README-ZH-CN.md 2026-11-25 18:47:02.000000000
+0100
@@ -68,6 +68,18 @@
sudo yum install lastversion
```
+## 在 Debian 或 Ubuntu 上安装 `lastversion`
+
+支持 Ubuntu 20.04、22.04、24.04、26.04 以及 Debian 12、13。
+
+```bash
+curl -fsSL https://extras.getpagespeed.com/release-latest.deb \
+ -o /tmp/getpagespeed-extras-release.deb
+sudo apt-get install -y /tmp/getpagespeed-extras-release.deb
+sudo apt-get update
+sudo apt-get install -y lastversion
+```
+
## 在其它系统上安装 `lastversion`
用 `pip` 安装是最简单的方法。
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/README.md
new/lastversion-3.6.20/README.md
--- old/lastversion-3.6.19/README.md 2026-10-03 17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/README.md 2026-11-25 18:47:02.000000000 +0100
@@ -93,6 +93,21 @@
sudo yum -y install lastversion
```
+## Installation for Debian and Ubuntu
+
+Supported:
+
+* Ubuntu 20.04, 22.04, 24.04, 26.04
+* Debian 12, 13
+
+```bash
+curl -fsSL https://extras.getpagespeed.com/release-latest.deb \
+ -o /tmp/getpagespeed-extras-release.deb
+sudo apt-get install -y /tmp/getpagespeed-extras-release.deb
+sudo apt-get update
+sudo apt-get install -y lastversion
+```
+
## Installation for other systems
Installing with `pip` is easiest:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/ci/constraints-el7.txt
new/lastversion-3.6.20/ci/constraints-el7.txt
--- old/lastversion-3.6.19/ci/constraints-el7.txt 1970-01-01
01:00:00.000000000 +0100
+++ new/lastversion-3.6.20/ci/constraints-el7.txt 2026-11-25
18:47:02.000000000 +0100
@@ -0,0 +1,9 @@
+# Oldest dependency versions lastversion must keep working with: the EL7 RPM
+# runs on distro python36-* packages (versions taken from the GetPageSpeed
+# builder, CentOS 7 + EPEL). requests is pinned to 2.22.0 rather than EL7's
+# 2.14.2 because pip's requests < 2.16 vendors its own urllib3, unlike the
+# unbundled distro package (EL8 ships 2.22.0 with the same urllib3 1.25 line).
+urllib3==1.25.6
+requests==2.22.0
+cachecontrol==0.12.6
+packaging==16.8
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/src/lastversion/__about__.py
new/lastversion-3.6.20/src/lastversion/__about__.py
--- old/lastversion-3.6.19/src/lastversion/__about__.py 2026-10-03
17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/src/lastversion/__about__.py 2026-11-25
18:47:02.000000000 +0100
@@ -1,4 +1,4 @@
"""Package metadata"""
-__version__ = "3.6.19"
+__version__ = "3.6.20"
__self__ = "dvershinin/lastversion"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lastversion-3.6.19/src/lastversion/repo_holders/github.py
new/lastversion-3.6.20/src/lastversion/repo_holders/github.py
--- old/lastversion-3.6.19/src/lastversion/repo_holders/github.py
2026-10-03 17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/src/lastversion/repo_holders/github.py
2026-11-25 18:47:02.000000000 +0100
@@ -6,6 +6,7 @@
import re
import time
from datetime import datetime, timedelta, timezone
+from typing import Iterable, Optional
from urllib.parse import unquote
import feedparser
@@ -105,18 +106,28 @@
RELEASE_URL_FORMAT =
"https://{hostname}/{repo}/archive/{tag}/{name}-{tag}.{ext}"
SHORT_RELEASE_URL_FORMAT = "https://{hostname}/{repo}/archive/{tag}.{ext}"
- def is_update_style_tag(self, tag_name):
- """Return True if tag name looks like an update-style tag (e.g.,
8u462-b08)."""
+ def is_update_style_tag(self, tag_name: Optional[str]) -> bool:
+ """Check whether a tag name uses update-style versioning.
+
+ Args:
+ tag_name (Optional[str]): Tag name to check, such as ``8u462-b08``.
+
+ Returns:
+ bool: Whether the tag name contains an update-style version.
+ """
try:
return bool(re.search(r"(?i)\b\d{1,3}u\d{1,4}\b", tag_name or ""))
except TypeError:
return False
- def detect_prefer_update_style(self, names):
- """Decide whether update-style tags should be preferred for this repo.
+ def detect_prefer_update_style(self, names:
Optional[Iterable[Optional[str]]]) -> bool:
+ """Prefer update-style tags when any provided name uses that style.
- Preference is enabled if update-style tags are the majority among
provided names
- and there are at least 2 such tags to avoid flukes.
+ Args:
+ names (Optional[Iterable[Optional[str]]]): Tag names to inspect,
ignoring empty names.
+
+ Returns:
+ bool: Whether any provided name contains an update-style version.
"""
filtered = [n for n in (names or []) if n]
if not filtered:
@@ -125,10 +136,15 @@
# Prefer update-style if any such tags exist among recent names
return update_count > 0
- def detect_dominant_major_from_names(self, names, pre_ok=False):
+ def detect_dominant_major_from_names(self, names: Optional[Iterable[str]],
pre_ok: bool = False) -> Optional[str]:
"""Detect the most frequent major version among provided tag names.
- Returns the major as a string or None if it cannot be determined.
+ Args:
+ names (Optional[Iterable[str]]): Tag names to parse for major
versions.
+ pre_ok (bool): Unused compatibility argument; parsing always
allows prereleases.
+
+ Returns:
+ Optional[str]: Most frequent major version, or None if none can be
parsed.
"""
counts = {}
for name in names or []:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/src/lastversion/utils.py
new/lastversion-3.6.20/src/lastversion/utils.py
--- old/lastversion-3.6.19/src/lastversion/utils.py 2026-10-03
17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/src/lastversion/utils.py 2026-11-25
18:47:02.000000000 +0100
@@ -12,6 +12,7 @@
import tarfile
import tempfile
import zipfile
+from copy import copy
from pathlib import Path
from urllib.parse import unquote
@@ -345,50 +346,138 @@
return local_filename
-def check_if_tar_safe(tar_file: tarfile.TarFile) -> bool:
- """CVE-2007-4559"""
- all_members = tar_file.getnames()
- root_dir = Path(all_members[0]).parent.resolve()
- for member in all_members:
- member_path = Path(member).resolve()
- # Check if the member path resolves within the root directory
- if os.path.commonpath([member_path, root_dir]) != str(root_dir):
- return False
+def _tar_members(tar_file):
+ """Map archive member names and hard link targets into the output layout.
+
+ Args:
+ tar_file (tarfile.TarFile): Open archive.
+
+ Yields:
+ tarfile.TarInfo: Member with its final relative output name.
+
+ Raises:
+ TarPathTraversalException: A member cannot be mapped inside the
destination.
+ """
+ members = tar_file.getmembers()
+ assert members, "Empty TAR archive"
+ top = Path(members[0].name)
+ strip_top = (
+ members[0].isdir()
+ and not top.name.endswith(".app")
+ and all(top == Path(member.name) or top in Path(member.name).parents
for member in members)
+ )
+ for member in members:
+ name = Path(member.name)
+ if name.anchor or ".." in name.parts:
+ raise TarPathTraversalException("Unsafe tar member name:
{}".format(member.name))
+ if strip_top:
+ if name == top and member.isdir():
+ continue
+ member = copy(member)
+ member.name = str(name.relative_to(top))
+ if member.islnk():
+ try:
+ member.linkname =
str(Path(member.linkname).relative_to(top))
+ except ValueError as exc:
+ raise TarPathTraversalException("Hard link outside the top
directory") from exc
+ yield member
+
+
+def _check_tar_member(member, root):
+ """Check paths against the destination as it exists at extraction time.
+
+ Args:
+ member (tarfile.TarInfo): Member in the final output layout.
+ root (Path): Resolved extraction directory.
+
+ Raises:
+ TarPathTraversalException: A path leaves the destination or the type
is unsafe.
+ """
+ path = root / member.name
+ if path == root and not member.isdir():
+ raise TarPathTraversalException("Only a directory may name the
extraction root")
+ paths = [path, path.parent] if path != root else [root]
+ if member.issym() or member.islnk():
+ target = Path(member.linkname)
+ if target.anchor:
+ raise TarPathTraversalException("Absolute tar link:
{}".format(member.name))
+ base = path.parent if member.issym() else root
+ paths.append(base / target)
+ elif not (member.isreg() or member.isdir()):
+ raise TarPathTraversalException("Unsupported tar member type:
{}".format(member.name))
+
+ for candidate in paths:
+ try:
+ candidate.resolve().relative_to(root)
+ except (ValueError, RuntimeError, OSError) as exc:
+ raise TarPathTraversalException("Unsafe tar member:
{}".format(member.name)) from exc
+
+
+def check_if_tar_safe(tar_file: tarfile.TarFile, to_dir=".") -> bool:
+ """Check archive metadata against the prospective extraction directory.
+
+ Args:
+ tar_file (tarfile.TarFile): Open archive.
+ to_dir (str or Path): Extraction directory.
+
+ Returns:
+ bool: Whether all member names, types and link targets pass validation.
+ """
+ root = Path(to_dir).resolve()
+ try:
+ for member in _tar_members(tar_file):
+ _check_tar_member(member, root)
+ except TarPathTraversalException:
+ return False
return True
def extract_tar(buffer: io.BytesIO, to_dir):
- """Extract a tar/zip archive to dir.
- If the archive has only one top dir, it will be stripped.
- """
+ """Extract a tar archive, stripping a single outer directory except for
app bundles.
- archive_file: tarfile.TarFile
- with tarfile.open(fileobj=buffer, mode="r") as archive_file: # NOSONAR
- if not check_if_tar_safe(archive_file):
- raise TarPathTraversalException("Attempted Path Traversal in Tar
File")
-
- contents = archive_file.getmembers()
- assert contents, "Empty TAR archive"
- top_dir = Path(contents[0].name).resolve()
- only_one_top_dir = True
- # If the directory is .app, it's a macOS app bundle, don't strip it
- if not contents[0].isdir() or top_dir.name.endswith(".app"):
- only_one_top_dir = False
- if only_one_top_dir:
- for item in contents[1:]:
- item_path = Path(item.name).resolve()
- # Check if the item path resolves within the top directory
- if os.path.commonpath([item_path, top_dir]) != str(top_dir):
- only_one_top_dir = False
- break
-
- log.info("only one top dir: %s", only_one_top_dir)
- if only_one_top_dir:
- for item in contents[1:]:
- item.path = str(Path(item.name).resolve().relative_to(top_dir))
- archive_file.extract(item, to_dir)
- else:
- archive_file.extractall(path=to_dir) # nosec B202 - trusted
sources
+ Args:
+ buffer (io.BytesIO): Archive data positioned for reading.
+ to_dir (str or Path): Destination directory.
+
+ Raises:
+ TarPathTraversalException: An archive member is unsafe to extract.
+ """
+ root = Path(to_dir).resolve()
+ with tarfile.open(fileobj=buffer, mode="r") as archive_file:
+ members = list(_tar_members(archive_file))
+ for member in members:
+ _check_tar_member(member, root)
+
+ has_data_filter = hasattr(tarfile, "data_filter")
+ for member in members:
+ # Earlier members may have changed what a path resolves to.
+ _check_tar_member(member, root)
+ path = root / member.name
+ if member.issym() or member.islnk():
+ # Create the checked link directly. tarfile can fall back to
extracting
+ # another archive member whose metadata has not passed our
checks.
+ path.parent.mkdir(parents=True, exist_ok=True)
+ if member.islnk():
+ source = (root / member.linkname).resolve(strict=True)
+ if path.exists() and path.samefile(source):
+ continue
+ if os.path.lexists(str(path)):
+ path.unlink()
+ if member.issym():
+ os.symlink(member.linkname, str(path))
+ else:
+ os.link(str(source), str(path))
+ elif has_data_filter:
+ archive_file.extract(member, str(root), filter="data")
+ elif member.isdir():
+ path.mkdir(parents=True, exist_ok=True)
+ else:
+ # Older tarfile versions have no data filter. Keep file data,
+ # timestamps and ordinary permissions without restoring
ownership.
+ archive_file.extract(member, str(root), set_attrs=False) #
nosec B202 - checked regular file
+ mode = member.mode & (0o755 if member.mode & 0o100 else 0o644)
+ path.chmod(mode | 0o600)
+ os.utime(str(path), (member.mtime, member.mtime))
def extract_zip(buffer: io.BytesIO, to_dir):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/tests/test_network_retries.py
new/lastversion-3.6.20/tests/test_network_retries.py
--- old/lastversion-3.6.19/tests/test_network_retries.py 2026-10-03
17:06:48.000000000 +0200
+++ new/lastversion-3.6.20/tests/test_network_retries.py 2026-11-25
18:47:02.000000000 +0100
@@ -51,8 +51,12 @@
assert set(retries.status_forcelist) == {429, 500, 502, 503, 504}
-def test_make_retry_uses_allowed_methods_on_current_urllib3():
- """Current urllib3 gets the policy via ``allowed_methods``."""
+def test_make_retry_limits_methods_on_installed_urllib3():
+ """The installed urllib3 (>= 1.26 or the EL7 1.25 line) gets the method
policy."""
retries = _make_retry(3, 0.1)
- assert retries.allowed_methods == RETRY_METHODS
+ try:
+ methods = retries.allowed_methods
+ except AttributeError:
+ methods = retries.method_whitelist
+ assert methods == RETRY_METHODS
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lastversion-3.6.19/tests/test_tar.py
new/lastversion-3.6.20/tests/test_tar.py
--- old/lastversion-3.6.19/tests/test_tar.py 1970-01-01 01:00:00.000000000
+0100
+++ new/lastversion-3.6.20/tests/test_tar.py 2026-11-25 18:47:02.000000000
+0100
@@ -0,0 +1,97 @@
+"""Cover tar extraction into a caller-supplied destination."""
+
+import io
+import os
+import tarfile
+
+import pytest
+
+from lastversion.exceptions import TarPathTraversalException
+from lastversion.utils import check_if_tar_safe, extract_tar
+
+
+def tar_buffer(entries):
+ """Build an in-memory tar with the given (name, type, link target) entries.
+
+ Args:
+ entries (list): Member descriptions in extraction order.
+
+ Returns:
+ io.BytesIO: Archive positioned for reading.
+ """
+ buffer = io.BytesIO()
+ with tarfile.open(fileobj=buffer, mode="w") as archive:
+ for name, kind, target in entries:
+ member = tarfile.TarInfo(name)
+ member.type = kind
+ member.linkname = target
+ if member.isfile():
+ member.size = 2
+ archive.addfile(member, io.BytesIO(b"ok"))
+ else:
+ archive.addfile(member)
+ buffer.seek(0)
+ return buffer
+
+
[email protected]("kind", [tarfile.SYMTYPE, tarfile.LNKTYPE])
+def test_tar_rejects_absolute_link(tmp_path, kind):
+ """Reject an absolute target using only a single dangling link."""
+ buffer = tar_buffer([("alias", kind, str(tmp_path / "unused"))])
+ with tarfile.open(fileobj=buffer) as archive:
+ assert not check_if_tar_safe(archive)
+ buffer.seek(0)
+ with pytest.raises(TarPathTraversalException):
+ extract_tar(buffer, tmp_path / "output")
+ assert not os.path.lexists(str(tmp_path / "output" / "alias"))
+
+
+def test_tar_checks_links_after_stripping(tmp_path):
+ """Check link targets against the directory structure users receive."""
+ buffer = tar_buffer([("release", tarfile.DIRTYPE, ""), ("release/alias",
tarfile.SYMTYPE, "../unused")])
+ with pytest.raises(TarPathTraversalException):
+ extract_tar(buffer, tmp_path / "output")
+
+
[email protected]("wrapper", ["", "release", "Example.app"])
+def test_tar_preserves_internal_links(tmp_path, wrapper):
+ """Keep safe symbolic and hard links in each supported archive layout."""
+ prefix = wrapper + "/" if wrapper else ""
+ entries = [(wrapper, tarfile.DIRTYPE, "")] if wrapper else []
+ entries.extend(
+ [
+ (prefix + "file", tarfile.REGTYPE, ""),
+ (prefix + "bin/alias", tarfile.SYMTYPE, "../file"),
+ (prefix + "hard", tarfile.LNKTYPE, prefix + "file"),
+ ]
+ )
+ extract_tar(tar_buffer(entries), tmp_path)
+ extract_tar(tar_buffer(entries), tmp_path)
+ root = tmp_path / wrapper if wrapper.endswith(".app") else tmp_path
+ assert (root / "file").read_bytes() == b"ok"
+ assert (root / "bin" / "alias").is_symlink()
+ assert (root / "bin" / "alias").read_bytes() == b"ok"
+ assert (root / "hard").samefile(root / "file")
+
+
+def test_tar_preflight_uses_output_directory(tmp_path):
+ """Resolve existing links relative to the caller's output directory."""
+ output = tmp_path / "output"
+ output.mkdir()
+ (output / "alias").symlink_to(tmp_path)
+ buffer = tar_buffer([("alias/example", tarfile.REGTYPE, "")])
+ with tarfile.open(fileobj=buffer) as archive:
+ assert not check_if_tar_safe(archive, output)
+
+
+def test_tar_ignores_working_directory_links(tmp_path, monkeypatch):
+ """Strip the archive wrapper independently of names in the working
directory."""
+ working_dir = tmp_path / "cwd"
+ working_dir.mkdir()
+ (working_dir / "release").mkdir()
+ (working_dir / "release" / "file").symlink_to(tmp_path / "unused")
+ monkeypatch.chdir(working_dir)
+ entries = [("release", tarfile.DIRTYPE, ""), ("release/file",
tarfile.REGTYPE, "")]
+ output = tmp_path / "output"
+ extract_tar(tar_buffer(entries), output)
+ assert (output / "file").read_bytes() == b"ok"