Skip to content

Merge master into next (2.3.6 security fixes and 2.3.x fixes) - #1720

Open
dimitri-yatsenko wants to merge 51 commits into
nextfrom
merge/master-into-next
Open

dimitri-yatsenko wants to merge 51 commits into
nextfrom
merge/master-into-next

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Summary

This brings next up to date with master, so the v2.4 line carries the 2.3.6 security fixes and the 2.3.x fixes merged since next was branched.

Merge this PR with a merge commit. Do not squash or rebase it. A merge commit keeps master an ancestor of next, so later merges from master stay small and conflict-free.

Changes

next has had no commits of its own since it was branched: it is an ancestor of master. The merge therefore had no conflicts, and the resulting tree is identical to master at 207068d.

Conflicts and resolutions: none.

What next gains from master:

Effect on open PRs against next

I compared git merge-tree --write-tree origin/next <pr-head> with git merge-tree --write-tree <this merge> <pr-head>. None of these PRs conflict with next today. After this merge, four of them conflict:

These two stay clean:

Each conflicting PR needs next merged into it after this lands. For pixi.lock, regenerate the lock file rather than editing the conflict.

Tests

The full suite ran locally on the merge commit, unit and integration, against both MySQL and PostgreSQL: 2041 passed, 17 skipped, 0 failed. The tree is identical to master, whose CI is green at 207068d.

mayuriphad and others added 30 commits October 18, 2026 15:38
…otes for the backend

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
For s3, gcs and azure stores, full_path built <protocol>://<bucket>/<path> and left out the store's location, so it pointed to a path where the object is not when location is set. Use StorageBackend.get_url(), which builds the URL from the same _full_path the backend writes to.

Fixes #1646
Dependabot rejects time "9:00" (must match ^\d\d:\d\d$), so the
config failed to parse and no GitHub Actions updates were scheduled.
Adds a pip entry for pyproject.toml alongside the github-actions one.
increase-if-necessary keeps minimum-version requirements unchanged when
they already admit a new release; security updates are grouped.
numpy, pandas, pyparsing, tqdm, networkx, pydot, and packaging had no
version specifier. GitHub's dependency graph omits such requirements, so
they were missing from the SBOM and from Dependabot alerts.

The minimums were verified by running the full test suite on Python 3.10
with each dependency at its minimum. pyparsing 3.1.0 and pydot 2.x fail
it: pyparsing 3.1.0 strips the quotes from quoted defaults, and pydot 2.x
produces DOT that graphviz rejects. tqdm>=4.66.3 excludes CVE-2024-34062.
pyproject.toml keeps deepdiff<9 for Python 3.15 on purpose: deepdiff 9
requires cachebox<6, which has no 3.15 wheels. With increase-if-necessary,
Dependabot would propose widening that cap at every new deepdiff major, so
ignore semver-major updates for deepdiff.

Also state that version updates stay one PR per package, since each raises
an upper bound and deserves its own test run and review.
Pin every action in the lint, test, and stale workflows to the commit its
current tag resolves to, so a moved or compromised tag cannot change what
runs. Lint and test get a read-only GITHUB_TOKEN, and their checkouts do not
persist the token in the working copy.
- pandas>=2.2.2: pandas does not cap numpy, so pandas 1.5.3 with numpy 2
  installs and then fails on import (numpy.dtype size changed). 2.2.2 is
  the first pandas built against numpy 2; 2.2.1 still requires numpy<2.
- deepdiff>=6.6.0: DeepHash(ignore_iterable_order=...) first appears in
  6.4, and deepdiff before 6.6 uses np.float_, which numpy 2 removed.
- pymysql>=1.0.0: connections pass ssl_disabled, which pymysql 0.x does
  not accept, so every MySQL connection fails on 0.7.2 through 0.10.1.

Full suite on Python 3.10 with every core dependency at its minimum
passes, and again with numpy 2.2.6 in place of numpy 1.22.4.
Dependabot rejects time "9:00" (must match ^\d\d:\d\d$), so the
config failed to parse and no GitHub Actions updates were scheduled.

(cherry picked from commit 247125c)
pre-commit/action calls actions/cache by tag and installs an unpinned
pre-commit. Run the same steps directly: pre-commit pinned to a version and
actions/cache pinned by SHA.
PR 1588 adds a workflow_call trigger just before jobs:, where the
permissions block was, so the two PRs conflicted.
…nimums

A new test job runs the full suite on Python 3.10 with every runtime
dependency pinned at the minimum pyproject.toml declares.
.github/scripts/minimum_requirements.py derives the pins and fails when a
runtime dependency declares no minimum.

deepdiff and pymysql now start at the first release without known
vulnerabilities rather than the oldest that works: deepdiff>=8.6.2
(CVE-2025-58367, CVE-2026-33155; was 6.6.0) and pymysql>=1.1.1
(CVE-2024-36039; was 1.0.0). pixi.lock moves deepdiff from 8.6.1 to 9.1.0
where Python < 3.15.
CVE-2025-58367 and CVE-2026-33155 are in deepdiff's Delta class and
pickle_load. datajoint uses only DeepHash, so the oldest working version
stays the minimum and Dependabot reports the advisories. pymysql stays at
1.1.1 for CVE-2024-36039.
…hed rows

aggr (exclude_nonmatching=False), extend, and union of operands with
secondary attributes use a left join. A restriction on the right operand,
including dj.Top, went into the outer WHERE, where it removed the left rows
with no match. It is now applied inside a subquery for the right operand. An
unrestricted right operand is joined directly, and inner joins are unchanged.

Fixes #1650.
…uery

An expression restricted by dj.Top keeps its ORDER BY/LIMIT in _top, and
several operations ignored it or broke on it:

- join() joined a limited operand directly, on either side, so the limit was
  dropped from *, aggr, and extend. A limited operand is now a subquery.
- Restriction by a limited expression put the LIMIT inside IN (...), which
  MySQL rejects (error 1235). The expression is now a subquery there.
- dj.U.aggr ignored the group's limit, and dj.U & expr applied DISTINCT
  before the limit. Both now apply the limit first.
- Union put its ORDER BY/LIMIT inside the quoted alias name (a syntax error),
  and ignored it for operands with secondary attributes.
- proj() kept the limit while dropping or redefining an attribute its
  ORDER BY names, so keys() and similar calls failed or selected other rows.
  It now adds a subquery in exactly those cases.
- Top.merge let a second Top with an offset reach past the first Top's limit.
- bool() ignored the limit.
- Diagram.restrict() ignored a dj.Top on its seed; it now builds the seed as
  cascade and trace do.
- A subquery heading dropped table_info, so a later rename quoted with
  backticks on PostgreSQL.

dj.Top still cannot be negated or nested in a list or AndList; the error now
says so and names the complement, dj.Top(None, order_by=..., offset=n).

Fixes #1656.
…ctories

The search for datajoint.json walks up from the working directory and the
.secrets/ directory is read next to the file it finds. A file or directory
owned by another user (other than root) is now skipped, with a warning, when
it or a directory above it is writable by all users (for example /tmp). A
world-writable file that is used produces a warning.

To use such a file, name it explicitly: dj.config.load(path), or the new
DJ_CONFIG_FILE environment variable, which loads the named file without
searching. DJ_IGNORE_CONFIG_FILE=true still turns the search off. Platforms
without os.getuid (Windows) are unchanged.

fix(npy): keep the mmap download cache in a per-user private directory

NpyRef.load(mmap_mode=...) on a remote store cached downloads in a
directory shared by all users. The cache is now <tempdir>/datajoint_mmap_<uid>,
created with mode 0700; an existing directory is used only if the current
user owns it, and otherwise a new private directory is created for the
session. On Windows the per-user temp directory keeps datajoint_mmap.
…ompression

Foreign key references in table definitions are now parsed and looked up in
the declaration context attribute by attribute. A reference is a dotted name
(Parent, module.Parent, Master.Part), optionally projected with
.proj(new_name="old_name"); anything else raises a DataJointError naming the
supported forms. alter() re-parses the definition that describe() builds from
the database catalog, and that text is now only ever read as a table name.

describe() keeps each element of the definition on its own line: line breaks
in table and attribute comments become spaces, and attribute names that are
not plain identifiers raise a DataJointError.

Compressed blobs now expand only up to the size declared in their header. A
payload that holds more, or less, raises a DataJointError, as does a corrupt
zlib stream.
<attach> fetch now accepts only a plain stored file name (no directory
part, "..", or NUL byte; on Windows, no drive or ":"), creates the file
exclusively, and never opens or reuses a symbolic link, device, or pipe
already in the download path. encode has always stored only the base
name, so attachments written by DataJoint are unaffected.

Store paths are confined to the store location: StorageBackend rejects
paths with ".." components and, for file stores, absolute paths. This
covers every store operation, including <hash@>, <object@>, <npy@>, and
<filepath@> access, and pre-computed <object@> metadata on insert.
<filepath@> checks its reserved sections and filepath_prefix on the
normalized path.

The new setting allow_filepath_outside_store (DJ_ALLOW_FILEPATH_OUTSIDE_STORE)
lets <filepath@> values point outside their store, for data whose
references deliberately do, such as rows migrated from DataJoint 0.14.
Values in dict restrictions are now rendered through one function that
uses the backend adapter's string quoting, for strings, lists, dates,
decimals and JSON objects alike. List values and JSON objects compared
against a JSON path were previously placed between quotes without
escaping, so a value containing a quote produced malformed SQL.

- JSON return types after `:` (e.g. `attr.path:decimal(4,1)`) must be
  a known type name with optional length/precision.
- A key that is neither an attribute name nor a valid JSON path is
  rejected instead of being quoted as an identifier.
- Values of unsupported types (bytes, sets, objects) raise
  DataJointError instead of producing invalid SQL.
- JSON path segments are quoted with the adapter's string quoting.

Rendered SQL is unchanged for values that need no escaping. On
PostgreSQL, backslashes in string values are still doubled, so string
restrictions match the same rows as before.
…ficate options

MySQL: use_tls=True now requires TLS. It previously passed ssl={} to PyMySQL,
which treats an empty dict as TLS not requested, so the connection was not
encrypted. True and {} use TLS without certificate verification. A use_tls dict
is passed to PyMySQL; with "ca", the server certificate is verified. When TLS is
required and the server does not offer it, the connection is refused before the
credentials are sent.

PostgreSQL: a use_tls dict maps "ca", "cert", "key", "password" to sslrootcert,
sslcert, sslkey, sslpassword. With "ca", sslmode is verify-full (verify-ca when
"check_hostname" is False); otherwise require. These keys were ignored before.

use_tls not set (default): the retry without TLS now happens only when TLS
negotiation fails (the server does not support TLS, or the TLS handshake
fails), not after authentication or other errors. On MySQL, the default now
uses TLS when the server offers it, as documented.

use_tls=False is unchanged.
- The return types accepted after `:` in a JSON attribute key now
  include the PostgreSQL type names that worked before (integer, bigint,
  numeric(p,s), double precision, text, varchar(n), character varying(n),
  boolean, jsonb, timestamp[tz], with/without time zone, uuid, ...).
  Restrictions, projections and index declarations accept the same set.
- NaN and infinite values in a mapping restriction raise DataJointError
  instead of rendering as bare `nan`/`inf`.
- A malformed JSON key reports an invalid JSON path.
- Pattern constants added to datajoint.condition are module-private.
<filepath@> accepts an absolute path that lies inside a file store's
location again, as before the previous change: insert records it relative
to the location, and existing rows holding such absolute paths stay
readable. Absolute paths outside the location and paths with ".."
components are still refused unless allow_filepath_outside_store is set,
and the error message now names that setting.

The reserved-section check for <filepath@> ignores case, so "_HASH/x" is
refused like "_hash/x" on case-insensitive file systems.

ObjectRef.full_path applies the same store confinement as file access.
ObjectRef.download into a directory takes the local file name from the
last path component, splitting on both "/" and "\", and refuses a name
that is not a plain file name.

<attach> fetch refuses stored names containing path separators, including
backslashes, which are legal in POSIX file names; attachments with such
names can no longer be fetched. The plain-file-name check is shared in
datajoint.utils.is_plain_file_name.
…sticky roots

Files found by the config search are now opened first and checked through
the open descriptor (os.fstat), then read from it, so the file that is
checked is the file that is read. The final path component is opened
without following symbolic links, and a link owned by another user is
judged by the directory it was found in. Secret files are read the same way.

The directory rule now matches how shared directories are set up: another
user's file is skipped when the directory it is in is world-writable (such
as /tmp), or when a directory above it is world-writable without the sticky
bit. A group directory under a sticky world-writable root such as /scratch
is used.

A skipped config file now produces one warning naming the file, DJ_CONFIG_FILE
and dj.config.load(), without the "No datajoint.json found" warning.
DJ_CONFIG_FILE naming a missing file raises FileNotFoundError.

fix(npy): clear the mmap cache directory when restricting its permissions

A per-user cache directory that other users had access to is reset to 0700
and emptied, so files written while it was open are not reused. Tests
requiring POSIX ownership are skipped on Windows.
…lt on MySQL

dj.conn(use_tls=...) now creates the shared connection with use_tls even when
no credentials are passed, and reconnects an existing shared connection that
was made with weaker TLS settings (True is met by True or a dict; a dict only
by the same dict). datajoint.connection.conn does the same.

use_tls=False now reaches the adapters: MySQL disables TLS, PostgreSQL uses
sslmode=disable. Before, both received None.

use_tls not set (default):
- MySQL makes one connection that uses TLS when the server offers it and
  continues without TLS otherwise. No second connection, no warning; errors
  during the TLS handshake are not retried.
- PostgreSQL connects with sslmode=require, then with sslmode=disable only if
  the server does not support SSL or pg_hba.conf has no entry for SSL
  connections from this client. Authentication and other errors are not
  retried. libpq's sslmode=prefer is not used because it also retries without
  SSL after an authentication failure.

PostgreSQL use_tls dict keys that are ignored, including check_hostname
without ca, are now reported in a warning.
…eferences

describe() no longer raises on names, defaults or types it cannot write as
plain tokens: line breaks become spaces and projection names are written as
escaped string literals, so describe() and Diagram work for every table.

Foreign key references also accept the forms that worked before and only name
a table: a reference in parentheses, Parent().proj(...), and identifiers with
non-ASCII letters. Calls, expressions, ** arguments and dunder names are still
refused. Every refused or unknown reference reports that it "could not be
resolved", with the supported forms, so alter() keeps its message for a parent
missing from the context.

Tests: projection arguments are passed through as strings; a reference that
names a function does not call it; decompression of a blob larger than its
declared size stays within a fixed memory bound; test_long_table_name checks
the length message.
…tions

The reviewer asked for a case that pins the trailing-slash location. It asserts that full_path equals what the backend builds for reads and writes, so it holds whether or not _full_path ever normalizes the slash.
fix: Dependabot config fails to parse (schedule time must be HH:MM)
ci: Dependabot watches Python dependencies, not only GitHub Actions
fix: declare minimum versions for all core dependencies
ci: pin actions to commit SHAs and run workflows with read-only tokens
dimitri-yatsenko and others added 21 commits November 10, 2026 13:52
fix: aggr, extend and union keep unmatched rows when the right operand is restricted
fix: dj.Top is honored when a limited expression is used in another query
fix(heading): keep table_info in set_primary_key so a later rename quotes for the backend
…location

fix: include the store location in ObjectRef.full_path
…ectories

A world-writable secrets directory with the sticky bit, such as a Kubernetes
secret volume mounted at /run/secrets/datajoint, no longer produces a
"writable by all users" warning: each file in it is still checked when read.
A world-writable secrets directory without the sticky bit still warns.

Tests also cover running as root, another user's datajoint.json in a
world-writable directory without the sticky bit, and a named pipe in place
of a secret file.
… not given

Connection now falls back to database.use_tls (DJ_USE_TLS) from its config
when use_tls is None, as dj.conn and Schema already did. This covers
dj.Instance, which passes its own config, and a direct dj.Connection. An
explicit use_tls argument still wins.

The docstrings for an existing connection now say it is reconnected with
the requested TLS settings unless it already satisfies them.
- MySQL string literals double single quotes ('') instead of writing \',
  so a literal stays closed even if the session's sql_mode includes
  NO_BACKSLASH_ESCAPES. The value read back in the default sql_mode is
  unchanged.
- On PostgreSQL, a list value whose text contains a backslash is
  rendered as an E'...' literal, which reads the same whether or not
  standard_conforming_strings is on. Plain string and JSON object values
  are rendered as before.
ObjectRef.download of a folder object lists the keys under the object and
refuses the whole download, before writing any file, if a key relative to
the object is not made of plain file names (for example, one containing a
".." component). It no longer relies on the installed fsspec version to
keep such keys inside the destination. Files still land at
destination/<object name>/..., and fsspec still fetches them in one batch.

The store-path error message now says that allow_filepath_outside_store
applies to <filepath@> values only, and to use it only with trusted data.
The check for mentioned names used `if not self.heading.names`, which
never refers to the attribute and is always false, so a rename or
replicate of an attribute missing from the heading was silently dropped.

Fixes #1677

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
With a file store whose location is "" or ".", a stored path is used
as given, and fsspec reads a leading "file:" or "local:" as a protocol
and expands a leading "~". Such a path passed the store-path check and
then resolved outside the working directory. The full path is now also
checked after fsspec resolves it, so it must lie inside the location
whatever the location is.
Keep attachment and store paths inside their roots
fix(connection): require TLS when use_tls is set; honor use_tls certificate options
Render values in mapping restrictions as quoted literals
Parse foreign key references instead of evaluating them; cap blob decompression
fix(config): skip config files other users could place in shared directories
fsspec before 2024 leaves "." segments in a resolved path, so a store whose
location is "" or "." rejected every path, including ones inside it. Compare
normalized paths instead.

The working-directory test now checks what the store does with each path: it
is rejected, or fsspec resolves it inside the store and I/O stays there. Old
fsspec does not read some "file:" and "local:" forms as a protocol, so it
accepts them as names inside the store. The Windows download test accepts
OSError, which Windows raises for a source path containing ":".
codespell flags "acter" in the char(?:acter)? pattern in condition.py; add
it to the ignore list. mypy reports server_capabilities and
_request_authentication on the TLS connection subclass, which are PyMySQL
internals that types-PyMySQL does not declare; mark those three lines with
targeted type-ignore codes. No behavior change.
fix(proj): raise for a rename or replicate of a missing attribute
fix(storage): accept paths in a file store located in the working directory on fsspec before 2024
Fix lint: codespell regex fragment and mypy errors in the MySQL TLS connection

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants