Skip to content

OpenConceptLab/ocl_online#718 | A collection named in the query string counts only through versions the requester can view - #1027

Merged
snyaggarwal merged 31 commits into
masterfrom
ocl_online-718-query-collection-version
Nov 23, 2026
Merged

snyaggarwal merged 31 commits into
masterfrom
ocl_online-718-query-collection-version

Conversation

@paynejd

@paynejd paynejd commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Follows #1023 (merged; master merged in at 529f23f). Tracks OpenConceptLab/ocl_online#718; follow-up in OpenConceptLab/ocl_online#739.

What this fixes

A collection named in the query string wasn't access-checked on the concept and mapping lists:

  • On a search (the default for these lists once a collection facet is named), collection, collection_url and collection_owner_url filter on the names and URLs of every version a concept or mapping is in. That includes versions the requester can't view, and it ignores org and version. ! and * values work too.
  • On the database read behind ?csv=true, collection (with the owner and version) filters the same way.
  • So the public members of a private collection, or of a private version of a public collection, showed to anyone who named it, signed out included. Rows kept their own access; which rows came back was the leak.

What changes

  • Search: each value of those three facets (plain, ! or *) is matched only through the URLs of the current collection versions the requester can view (terms collection_url). That also drops a deleted version's members, which keep its URL in the index until they're indexed again. Staff's searches are unchanged. A prefix is literal (an Elasticsearch prefix query, so @ is no wildcard).
  • Cache: a source version's first page isn't cached when a collection facet is named, as its rows now depend on who asks.
  • Database read: get_base_queryset takes the viewable versions, in the same filter as the collection's own criterion, so one expansion has to match both.
  • Collection named with its owner (check_query_collection_version_access, next to OpenConceptLab/ocl_online#717 OpenConceptLab/ocl_online#718 | Reads under a source version get that version's access check #1023's source check): 404 unless the named version exists, then 401 or 403 unless the requester can view the collection and that version. A collection that doesn't exist under that owner is skipped, as the search reads the name as a facet.
  • ConceptContainerModel.get_viewable_versions_criteria(user) is has_view_access as a query.
  • Query shape (de591bb): for a signed-in requester, the private-HEAD check is one top-level NOT EXISTS that leaves out their own and their orgs' HEADs, rather than a check inside the OR, which the database ran once per version. The results are the same; a test compares it with has_view_access. Drop this commit if a partial index on collections (mnemonic) WHERE version = 'HEAD' is preferred.
  • $match: a filter naming one of the three facets counts only the versions the requester can view, as a list search does (the view now declares its document_model; after the facet change it answered 500).
  • Collection version routes: a route that names a version answers 400 when the query string names a different one (CollectionBaseView.get_filter_params). So the route's access check, its search and its writes all act on the version the URL names. Routes with no version in the URL still read the query string's.

Choices for review (each can be overturned)

  1. A collection named with no owner, when nothing the requester can view is left (for example a click on the web app's collection facet), gives an empty list, not 404. OpenConceptLab/ocl_online#717 OpenConceptLab/ocl_online#718 | Reads under a source version get that version's access check #1023 answers 404 for a source version named with no owner.
  2. A collection's HEAD is checked when it's named with an owner. OpenConceptLab/ocl_online#717 OpenConceptLab/ocl_online#718 | Reads under a source version get that version's access check #1023 leaves a source's HEAD to its content's own access, but a collection's HEAD holds other repositories' content.
  3. A prefix (collection=abc*) that matches more than 1,000 viewable versions answers 400 when the requester can't view some of what it matches; with nothing hidden, it stays a plain prefix. Staff never see this. On a server with many public collections, such as OCL's, a bare collection=* from anyone but staff answers 400; no OCL web client sends a collection wildcard.
  4. On a route that names a collection version, a different version in the query string answers 400. Before, it mostly overrode the URL's version. No OCL web client sends one.

Not in this PR

  • The collection facet's buckets on a global search still list hidden collections' names and counts (OpenConceptLab/ocl_online#739).
  • Deleting a collection doesn't reindex its members, so the index keeps its name and URLs on them (OpenConceptLab/ocl_online#740). Matching through current versions closes most of that here. Two leftovers wait for Bump boto3 from 1.24.28 to 1.35.54 #740: a private collection deleted and recreated public under the same name, and a prefix past 1,000 viewable versions with nothing hidden (Codex F2.2, F2.3).
  • Pre-existing items on read paths this PR doesn't change: OpenConceptLab/ocl_online#741, OpenConceptLab/ocl_online#742.
  • Collection version lists (CollectionVersionConceptsView) get the search rewrite but not the owner check, as they read their own URL's collection.

Tests

QueryCollectionAccessTest in tests_access_control.py: signed out, an outsider, a member and staff, on /concepts/ and /mappings/, by search, q and csv; plain, comma, ! and * values; collection_url and collection_owner_url; the owner check, including latest, a missing version, and the source routes; the 400 past the limit; $match filters; and a version route with a query-string version. ViewableVersionsCriteriaTest checks the query against has_view_access. pylint -j0 core/ is clean, and the full suite passes (3,561 tests, plus 692 search tests).

Production EXPLAIN (Nov 23) is on the private tracking ticket. The database read's extra join adds no cost, and signed-out lookups take milliseconds. A signed-in lookup on a collection with hundreds of versions took about 0.3 s; with de591bb it takes 2 ms.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR

paynejd and others added 17 commits November 21, 2026 12:04
…same access check as that version's list

Every GET or HEAD under a source now checks the source and the version the URL names before the view runs, as
that version's own concept and mapping lists do: 401 signed out, 403 signed in without access. That covers the
lists, a concept or mapping and its revisions, version history, mappings, children, parents, summary, names,
extras, collection versions and $cascade, searched or not. For `latest`, the version is the newest released one,
plus any version named `latest`. Item-level checks stay, and POST, PUT, PATCH and DELETE are unchanged.

The list checks added for OpenConceptLab/ocl_online#715 (check_parent_permissions and
SourceVersionListHeadMixin) are folded into this check; their tests pass unchanged. $cascade under a source the
requester can't view now answers 401/403 like the source's other reads, rather than 404.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX9yqYaS1WjeoK2WiT
…'t exist answers 404

A read under a source that doesn't exist, or under a named version of it that doesn't exist, answers 404 for
every caller before anything is listed, as collections already do. `latest` on a source with no released version
keeps its empty list.

Fuzzy search's `source_version` targets get the same access check as the versions' own lists: each version it
names must be one the requester can view, otherwise 401 or 403. Expressions that don't resolve are skipped, as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX9yqYaS1WjeoK2WiT
…releases the requester can view

With IncludeSearchLatest, the global concept and mapping searches answer from each source's latest release.
Their hits and facets now leave out the sources whose latest release the requester can't view, as that
release's own lists do. Those are released versions that aren't public while their HEAD is; a private HEAD's
content is already private itself. Staff, the owner and the owning organization's members see them as before.

Source.get_latest_releases_hidden_from finds them in one query, picking each source's latest release as
get_latest_released_version does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX9yqYaS1WjeoK2WiT
…on, and a search of latest releases, keep to versions the reader can view

A concept's Atom feed under a source version (named or `latest`) answers only when the version it reads exists
and is public, as feeds are served without signing in. Source.get_url_versions resolves the versions a URL under a
source reads, for the feed and for the reads' access check.

A search of latest releases now keeps each source that has a release the requester can't view to the members of
its exact latest release, or leaves it out when that release isn't viewable either. The index marks a new latest
release's members only some time after it's published, so the latest-release flag alone could still point at the
previous release in the meantime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX9yqYaS1WjeoK2WiT
…the source versions it names, as GET does

HEAD on a source's concept list with `fuzzy` resolves and checks its `source_version` targets before counting,
the same way GET does, instead of failing before the search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX9yqYaS1WjeoK2WiT
…xpressions that don't name a source version

A `source_version` expression that resolves to a collection's version, or that can't be parsed, is skipped like
one that doesn't resolve, instead of scoping the search by a collection's name or failing the request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX9yqYaS1WjeoK2WiT
…he signed-in user's own source

The concept Atom feed on /user/sources/... routes looked the concept up under any owner. It now reads the signed-in
user's own source and answers 404 signed out, as the API's other /user/ routes do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX9yqYaS1WjeoK2WiT
…rom the response headers

CI's pylint reads `response['num_found']` on the test client's response as unsubscriptable (E1136).
`response.headers` is how the other count tests read it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX9yqYaS1WjeoK2WiT
…se cover HEAD on every route in one test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXcAwHwLtCieQ2LSK5
…>/<version>/ answers 404, as that route names no owner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXcAwHwLtCieQ2LSK5
…tring gets the same read check as one in the URL

The reads under a source take `source`, `org`, `user` and `version` from
the query string over the URL's, but the check ran on the URL's alone.
`check_query_source_version_access` now runs from `initial()` after the
URL's check, for GET and HEAD, whenever the query string names a version
other than HEAD for a source: 401 or 403 unless the requester can view
that version, and its HEAD, of each source named (commas separate
several). Precedence is unchanged.

- Owner: the one the query string names (org, else user). When it names
  none (no owner in the URL, or `?org=` empty), the reads match every
  owner's source of that name, so each one that has the version is
  checked. A same-named source of another owner can then refuse a
  request; a version no source has is left to the reads (empty, as
  before).
- HEAD, or no version, isn't checked here: HEAD's content carries its
  own access and is checked where it's read, and plain requests make no
  extra queries.
- `get_parent_owner_filters` takes the params to find their owner.

Tests: `SourceVersionReadAccessTest` (detail, sub-resources, revision,
lists, HEAD requests, `?version=latest`, another source's URL, `?user=`,
no owner) and `SourceVersionSearchAccessTest` (global lists, searched
lists): 401 signed out, 403 to a non-member, 200 to members; HEAD, a
public version or an empty `?version=` stay visible. They fail on the
previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVxv4g3w33csUQuubF
…ust exist under the owner named, and `latest` there is the release the reads use

From the Codex check of e86a9bf:
- FC.1: a source renamed after a release keeps that release under its
  old mnemonic. The source and version the query string names are now
  looked up under the owner it names, and either missing answers 404,
  as in the URL, instead of being skipped.
- With no owner (none in the URL, or an empty `org`), no owner names
  the version: 404, instead of checking every owner's source of that
  name.
- FC.4: `latest` is the newest released version
  (`find_latest_released_version_by`), as `get_base_queryset` resolves
  it, and no longer also a version literally named `latest`.
- FC.3: on a collection's route, the URL's version is the collection's.
  A `source` in the query string there doesn't check a source version
  of that name (`$cascade` is the collection route served by a source's
  view).

Tests: a renamed source, no owner and a missing version answer 404; a
newer public release answers `?version=latest` with an older private
version literally named `latest`; a collection version's `$cascade`
with `?source=` stays visible. They fail on the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVxv4g3w33csUQuubF
…the owner doesn't have is skipped, as a search reads it as a facet

From the Codex check of dd0eb7d, FC.2: a `source` in the query string
that isn't one of the owner's sources (a search's facet, such as a
prefix) answered 404. Nothing is read under a source that doesn't
exist, so it's skipped. A source that exists without the named version
still answers 404.

Test: `SourceVersionSearchAccessTest.test_a_source_facet_under_a_public_release_stays_a_search`
(fails on the previous commit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVxv4g3w33csUQuubF
… are each checked, and a version named with no owner leaves out the sources the requester can't view

- A URL naming several sources (`/orgs/O/sources/A,B/...`), as the reads match each, answers 404 unless each
  exists, then 401 or 403 unless the requester can view each, instead of 404 for every list.
- A query-string version with no owner (`?org=&source=S&version=v1`) is read from each owner's `S` that has it:
  the reads leave out the ones the requester can't view, and answer 404 when none is left.
- A latest-release search reads its scopes once per request (hits and facets shared one), from active rows only.
- A concept feed answers only under a URL naming the source's owner.
- The reads under a source reuse the source versions the access check read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUNfkgDYc59V43e44Y
… already-read source versions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUNfkgDYc59V43e44Y
…g counts only through versions the requester can view

The global /concepts/ and /mappings/ lists, and the source and owner lists, can be filtered by collection from the
query string: `collection`, `collection_url` and `collection_owner_url` on a search, and `collection` (with the owner
and `version`) on the database read behind `?csv=true`. Neither checked the collection, so the public members of a
private collection, or of a private version of a public one, showed to anyone who named it.

- A search counts a concept's or mapping's membership only through the collection versions the requester can view,
  for plain, `!` and `*` values. Staff, and anyone who can view every version the value matches, get the same
  search as before. A prefix that matches more than 1,000 viewable versions, when some are hidden, answers 400.
- The database read keeps to the members of the versions the requester can view, in the same filter as the
  collection's own.
- A collection named with its owner answers as a source named that way does: 404 unless the version named exists,
  then 401 or 403 unless the requester can view the collection and that version. A collection's HEAD is checked
  too, as it holds other repositories' content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
@paynejd
paynejd requested a review from snyaggarwal November 23, 2026 04:09
paynejd and others added 5 commits November 22, 2026 23:13
…o the versions the requester can view, and each source named is checked once

A renamed source's versions keep their old name, so finding the versions to leave out by name missed them. The reads
now keep to the members of the versions found viewable instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUNfkgDYc59V43e44Y
…versions the requester can view, as literal prefixes, and aren't cached

Codex pass 1 on oclapi2#1027:
- An exact collection facet value always matches through the viewable versions' URLs, so a version deleted since it
  was indexed (whose members keep its URL until they're indexed again) matches nothing (F1.3).
- A prefix is literal, as the database reads it: `@` is no wildcard, and `*` alone is checked too (F1.1).
- An owner URL matches that owner's versions only, and the 1,000-version limit applies to prefixes (F1.8).
- A source version's first page isn't cached when a collection facet is named, as its rows depend on who asks
  (F1.2).
- A test pins that a CSV export's version and access match in one expansion (F1.9).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
…o ocl_online-718-query-collection-version

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
…lection check in, and `*` alone is checked per requester

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
…he viewable versions' URLs up to the limit, so deleted versions match nothing there too

Codex pass 1 on oclapi2#1027, F1.3 for prefixes: a prefix stays a prefix only past the limit with nothing hidden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 1 (codex-cli 0.169.0, commit c5f9b4e)

Verdict: findings (7 P1, 2 P2). Fixed in b46db42 and 6221056; #1023's head 36f75b3 merged in 0adfb63.

Finding Response
F1.1 P1: a * prefix skipped the check, and @ is a regexp wildcard Fixed. A collection prefix is now a literal prefix query, as the database reads it, and * alone is checked too. Tests cover * and @.
F1.2 P1: the shared first-page cache of a source version list could serve one requester's collection-facet rows to another Fixed. The list isn't cached when a collection facet (any spelling) is named. The test fails without the fix.
F1.3 P1: a deleted version's members keep its URL in the index Fixed. Exact values always match through the URLs of current versions the requester can view. A prefix does too, up to 1,000; past that it stays a prefix only when nothing it matches is hidden. Test: a deleted private version matches nothing by URL, name or prefix.
F1.4 P1: a source route skips the collection's query-string version No change. On a repository route, the query string's version is that repository's (#1023 reads it as the source's). The collection's members still count only through its viewable versions, so a private v1 adds no rows.
F1.5 P1: version=latest on a collection with no release passes No change, by design. This matches #1023: latest of a repository with no release checks HEAD only. The database read finds nothing for an unresolved latest, and a search counts viewable versions only.
F1.6 P1: a query-string user can't override the URL's org No change. Owner precedence is #1023's get_parent_owner_filters. No rows leak: the search counts the user's private collection through no hidden version, and the database read, given both owners, matches nothing.
F1.7 P1: a source route's CSV ignores a query-string collection Already on base, not an access gap. A source's list reads its own versions, so the export holds more of the source's own rows, which the requester can already view. Recorded, not fixed here.
F1.8 P2: owner URL matched as a URI prefix, and the limit applied to exact values Fixed. An exact owner URL matches that owner's versions only, and the limit applies to prefixes only.
F1.9 P2: the CSV test didn't pin one expansion Fixed. A row in both Q's public HEAD and its private v1: an owner-less version=v1 export leaves it out for outsiders and keeps it for members.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "full",
  "commit": "c5f9b4e2",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "F1.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 477,
      "claim": "Collection prefixes can match private memberships that the database visibility lookup never checks.",
      "scenario": "A bare `*` becomes an empty prefix and skips the visibility lookup. Elasticsearch still matches every indexed collection membership, including rows whose only membership is private. The two matchers also disagree on `@`. The database treats it literally, while the fallback regexp treats it as a wildcard under Lucene's default flags. [Elasticsearch regexp syntax](https://www.elastic.co/docs/reference/query-languages/query-dsl/regexp-syntax#regexp-optional-operators)",
      "action": "Check visibility for empty prefixes and use the same literal prefix semantics in PostgreSQL and Elasticsearch. Add coverage for an empty prefix and a prefix containing `@`.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.2",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1211,
      "claim": "The shared source-version list cache bypasses the new collection facet visibility check.",
      "scenario": "An org member filters an accessible source release by the URL of a private collection version. With default paging and no search text, the list caches the matching rows under a key shared by all callers. An outsider requesting the same list receives those rows before the facet visibility check runs.",
      "action": "Bypass shared list caching whenever a collection membership facet is present. Test the same request first as a member and then as an outsider.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.3",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 489,
      "claim": "Deleting a private collection version lets its stale indexed memberships through the visibility check.",
      "scenario": "A private collection version contains public resources and is then deleted. The delete task removes the expansion and collection rows without reindexing the member documents. A search for the old version URL finds no hidden database row, keeps the original Elasticsearch filter, and returns the former members.",
      "action": "Require a current viewable version for indexed membership matches. Add a regression case where an indexed membership remains after its collection version is deleted.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.4",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1443,
      "claim": "A source route skips the collection version check even when the version is supplied explicitly in the query string.",
      "scenario": "An outsider lists an accessible source release with `collection=C&version=v1`. The collection's HEAD is public and its `v1` is private. The guard checks only HEAD and the request can return 200. An explicitly named nonexistent collection version likewise skips the required 404.",
      "action": "Read an explicit query-string `version` for the named collection and keep the URL's version scoped to its repository. Test both a private and a missing query-string version from a source route.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.5",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1456,
      "claim": "An explicit `latest` request succeeds for an existing collection with no released version.",
      "scenario": "A public collection contains members in HEAD and has never been released. An owner-qualified request for that collection with `version=latest` passes the guard and can return HEAD members in search, despite the required 404.",
      "action": "Return 404 when an existing collection has no release that resolves an explicit `latest` selector. Cover a populated HEAD with no released version.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.6",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1440,
      "claim": "A query-string user owner cannot override an organization owner from the URL.",
      "scenario": "On an organization-owned source route, an outsider supplies `user=U&collection=C` for a private collection owned by U. The merged parameters retain the URL's `org`, and `get_parent_owner_filters` gives it priority. If the organization has no C, the guard skips the collection and returns 200 instead of 403.",
      "action": "Resolve the explicit query-string owner before falling back to the URL owner. Use the resolved owner consistently in collection authorization and database filtering.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.7",
      "severity": "P1",
      "tag": null,
      "file": "core/concepts/views.py",
      "line": 246,
      "claim": "CSV exports under a source route ignore the query-string collection membership filter.",
      "scenario": "A public source contains two concepts and a viewable collection contains only one. Exporting the source's concepts with `csv=true&collection=C` takes the parent queryset branch and exports both. The mapping list has the same parent queryset branch.",
      "action": "Apply the collection criterion and version visibility to the source-scoped CSV queryset before slicing it. Test exported rows for both resource types.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.8",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 491,
      "claim": "The facet limit counts candidate URIs before checking whether their owner URLs actually match.",
      "scenario": "An exact `collection_owner_url` of `/orgs/` matches no indexed owner URL. If the database contains more than 1,000 viewable organization-owned versions and at least one hidden version, the broad URI lookup raises 400 before checking owner URL equality. A valid exact owner URL also receives the prefix limit when the owner has enough versions.",
      "action": "Match the actual owner URL before testing for hidden versions or counting viewable versions. Apply the 1,000-version limit to prefix filters.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.9",
      "severity": "P2",
      "tag": null,
      "file": "core/integration_tests/tests_access_control.py",
      "line": 2202,
      "claim": "The CSV regression test does not exercise the same-expansion join required by criterion 5.",
      "scenario": "The fixture keeps the private Q v1 member out of the public Q HEAD. The test would still pass if a second join let a row satisfy `version=v1` through the private expansion and satisfy visibility through the public HEAD expansion.",
      "action": "Put the same concept and mapping rows in both expansions, then assert that the ownerless v1 CSV export excludes them for an outsider and includes them for a member.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…thing, quoted names are checked, and the database read always keeps to viewable versions

Codex pass 2 on oclapi2#1027:
- A version counts as viewable only while active, as its own lists answer 404 otherwise (F2.1).
- The owner check strips quotes from names, as a search does (F2.4).
- An owner URL prefix longer than any owner URL matches no version (F2.5).
- The database read keeps to the viewable versions on every non-staff read that names a collection, with no
  separate check first (F2.6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 2 (codex-cli 0.169.0, commit 6221056)

Verdict: findings (2 P1, 4 P2). Pass 1: F1.1, F1.2 and F1.8 resolved. F1.4–F1.7 stand as answered in pass 1. F1.3 is narrowed to F2.2 and F2.3 below. F1.9's test fails with the read split into two joins and passes as written (checked by swapping the file in). Fixes are in a495486.

Finding Response
F2.1 P1: an inactive release passed once its private HEAD was inactive too (owner deactivated) Fixed. A version counts as viewable only while active, as its own lists answer 404 otherwise. The test fails without the fix.
F2.2 P1: a deleted private collection recreated public at the same URL brings back the old members' index entries Accepted, not fixed here. The index never held a version id, so the URL is the only key a search has; this is the index keeping a deleted version's URL. Only the collection's owner can set it up, by deleting and recreating it under the same name. The fix belongs where a version is deleted (reindex its members), which is proposed as a follow-up.
F2.3 P2: a prefix past 1,000 viewable versions with nothing hidden still matches a deleted version's entries Accepted. Past the limit with nothing current hidden, the prefix stays a prefix. Needs over 1,000 viewable matches and a deleted private version; same follow-up as F2.2.
F2.4 P2: a quoted name (collection="C") skipped the owner check Fixed. The check strips quotes as a search does. (The search was already limited to viewable versions, so no rows leaked.)
F2.5 P2: an owner URL prefix longer than any owner URL could still hit the limit Fixed. Such a prefix matches no version.
F2.6 P2: a CSV export could race with an access change between the check and the read Fixed. The database read now keeps to the viewable versions on every non-staff read that names a collection, with no separate check first.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "62210563",
  "verdict": "findings",
  "prior": [
    {"id": "F1.1", "status": "resolved"},
    {"id": "F1.2", "status": "resolved"},
    {"id": "F1.3", "status": "unresolved"},
    {"id": "F1.4", "status": "unresolved"},
    {"id": "F1.5", "status": "unresolved"},
    {"id": "F1.6", "status": "unresolved"},
    {"id": "F1.7", "status": "unresolved"},
    {"id": "F1.8", "status": "resolved"},
    {"id": "F1.9", "status": "unresolved"}
  ],
  "findings": [
    {
      "id": "F2.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/models.py",
      "line": 1187,
      "claim": "Deactivating a collection owner can expose memberships that the collection's private HEAD previously hid.",
      "scenario": "A user-owned collection has a release that retains its public access value after HEAD becomes private. Deactivating the owner marks both rows inactive. The collection's own list now returns 404, but the new lookup ignores the inactive private HEAD and still admits the inactive release. An outsider can see its public members through an ownerless search or CSV export.",
      "action": "Require an active collection version in the membership visibility query and add a regression test for a deactivated owner with a private HEAD and a formerly public release.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.2",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 468,
      "claim": "Reusing a collection URL grants access to stale memberships from the deleted collection.",
      "scenario": "An owner deletes a private collection and creates an empty public collection with the same name. Deletion leaves the old collection URL on indexed member documents. The new public row puts that URL back in the allowlist, and an outsider's exact facet search returns the deleted collection's former members.",
      "action": "Match search membership against a stable collection version ID and cover deletion followed by recreation at the same URL.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.3",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 496,
      "claim": "The large-prefix fallback still returns stale memberships from deleted private versions.",
      "scenario": "A prefix matches 1,001 current public versions and one deleted private version whose membership is still indexed. The database finds no hidden current version, so the search falls back to a raw prefix and returns rows that matched only through the deleted version.",
      "action": "Keep the visibility restriction on broad prefixes even when every current match is public. Add a regression case that reaches the fallback with a deleted private match.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.4",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1464,
      "claim": "The owner-qualified guard skips exact collection names that search accepts in quotes.",
      "scenario": "With private collection C under O, a request for `/concepts/?org=O&collection=%22C%22` looks up a mnemonic that includes the quotes and skips the guard. Search strips the quotes and treats the filter as an exact match for C. The request returns 200 instead of 401 or 403.",
      "action": "Use the same exact collection value parsing for the guard and the search facet, and test the owner-qualified quoted form.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.5",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 491,
      "claim": "An owner URL prefix can trigger the 1,000-version limit even when it matches zero owner URLs.",
      "scenario": "An organization has more than 1,000 public collection versions and at least one private version. `collection_owner_url=/orgs/O/collections/*` matches their collection URIs in PostgreSQL, but no indexed owner URL extends beyond `/orgs/O/`. An outsider receives 400 for a filter whose result should be empty.",
      "action": "Match the prefix against owner URLs before counting viewable versions or checking for hidden matches.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.6",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1495,
      "claim": "The CSV visibility check can race with a collection permission change.",
      "scenario": "An outsider starts an ownerless CSV export while all versions of the named collection are public. The preliminary existence check returns false. If an editor makes the selected version private before the export queryset runs, the export uses an unrestricted expansion join and includes its members.",
      "action": "Apply the viewability predicate in the same expansion join on every non-staff CSV read, including when the preliminary lookup would find no hidden versions.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

Base automatically changed from ocl_online-717-718-version-checks to master November 23, 2026 04:54
paynejd and others added 2 commits November 22, 2026 23:58
…1007) into ocl_online-718-query-collection-version

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
…rch reads as `collection`

Codex pass 3 on oclapi2#1027, F3.3: `Collection=` named a private collection with its owner and got 200 (with no
rows), not 401 or 403.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qW8QKbfuEJubgQgsHR
@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 3 (codex-cli 0.169.0, commit a495486)

Verdict: findings (2 P1, 1 P2). Pass 2: F2.1, F2.4, F2.5 and F2.6 resolved, and F1.9 is resolved too. F1.4–F1.7, F2.2 and F2.3 stand as answered. The F3.3 fix is eb83b09, on top of a merge of master 24a8e90 (529f23f, after #1023 and #1024 merged). The full suite on the merged code passes: 3,560 tests, plus 690 search tests.

Finding Response
F3.1 P1: the expansion URI parser cuts a version named concepts (or a collection named so) at that segment, so a private release named concepts is indexed under its HEAD's URL Accepted, not fixed here. This is the indexer's URL parsing, already on base: the index records that release's members under the HEAD URL. Only a version or collection named after a resource segment hits it. Matching by version id needs the index change in OpenConceptLab/ocl_online#739.
F3.2 P1: a global CSV list keeps only versioned objects, so a release that holds only resource versions exports empty, and the fixture holds both rows Already on base, not an access gap. ConceptListView applies id=versioned_object_id whenever the URL names no version, on base too. The fixture holds both rows so membership shows on both read paths.
F3.3 P2: the owner check reads only collection, while search also reads Collection Fixed. The check reads every query-string key that a search reads as collection. (The search was already limited to viewable versions, so no rows leaked.)
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "a4954860",
  "verdict": "findings",
  "prior": [
    {"id": "F1.1", "status": "resolved"},
    {"id": "F1.2", "status": "resolved"},
    {"id": "F1.3", "status": "unresolved"},
    {"id": "F1.4", "status": "unresolved"},
    {"id": "F1.5", "status": "unresolved"},
    {"id": "F1.6", "status": "unresolved"},
    {"id": "F1.7", "status": "unresolved"},
    {"id": "F1.8", "status": "resolved"},
    {"id": "F1.9", "status": "resolved"},
    {"id": "F2.1", "status": "resolved"},
    {"id": "F2.2", "status": "unresolved"},
    {"id": "F2.3", "status": "unresolved"},
    {"id": "F2.4", "status": "resolved"},
    {"id": "F2.5", "status": "resolved"},
    {"id": "F2.6", "status": "resolved"}
  ],
  "findings": [
    {
      "id": "F3.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 468,
      "claim": "The search allowlist can mistake a live private release's indexed membership for public HEAD membership.",
      "scenario": "A collection has a public HEAD and a private release named `concepts`. The expansion URI parser cuts the path at `/concepts/`, so the release's members are indexed under the HEAD URL. The allowlist admits that URL, and an outsider's collection search returns public rows that belong only to the private release. The same parser also leaves the indexed version URL empty for a collection named `concepts`, so the rewritten owner facet drops that public collection's members.",
      "action": "Index and match membership using the expansion's collection version ID, backfill existing documents, and test both path-segment cases.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.2",
      "severity": "P1",
      "tag": null,
      "file": "core/integration_tests/tests_access_control.py",
      "line": 2139,
      "claim": "The CSV test adds HEAD rows to releases and masks empty exports from ordinary versioned expansions.",
      "scenario": "A locked collection release replaces HEAD concepts and mappings with their resource versions, as `Collection.replace_head_resources` specifies. A member exports that release from a global list. The expansion join finds the versioned rows, but the list applies `id=versioned_object_id` because the version was supplied in the query string. The export is empty. The test passes because it inserts both the HEAD and versioned row into the release.",
      "action": "Use only versioned resource rows in the release fixture and make global CSV lists preserve the rows selected by a query-string collection.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.3",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1460,
      "claim": "The owner-qualified check misses collection parameter spellings that search accepts.",
      "scenario": "An outsider names a private collection with its owner using `Collection` as the query parameter. Search normalizes the key to `collection`, but the guard reads only the lowercase key. The request returns 200 with no hits instead of 403.",
      "action": "Read the collection value using the same key normalization and precedence as search. Add an owner-qualified test for an alternate spelling.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

paynejd and others added 2 commits November 23, 2026 00:17
…lper

Simplification review S1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qU5uSpgMo1niq3ECJx
…y viewable versions; a collection version's URL wins over a query-string version

Adversarial pass, A5 and A1:
- POST /concepts/$match/ with a filter naming a collection facet reads the view's document_model since this PR's facet change; the view now declares it (ConceptDocument), so the filter counts only the collection versions the requester can view, as a list search does.
- CollectionBaseView.get_filter_params takes the version the URL names, and the query string's only on routes that name none, so a version route's access check and its search read the same version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qU5uSpgMo1niq3ECJx
@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Simplification review (claude subagent, commit eb83b09)

Verdict: findings (3 cuts proposed, 1 applied). Applied in e1d7390; the access tests (161) and Pylint (pylint -j0 core/, exit 0) pass on it.

Cut Response
S1 dup-test: the two CSV export tests each define the same export closure Applied. One exported helper on the test class; both tests keep every case.
S2 shrink: return early for an exact value in get_viewable_collection_urls Declined. It saves no real lines, and one place storing to the per-request cache reads more simply.
S3 dup-test: drop the collection=*&collection_url=<prefix>* line Declined. It's the only line that checks a member's or staff's collection=*; the * loop above it covers signed-out and outsider requests only.
simplify-findings.json
{"reviewer":"claude subagent","perspective":"simplify","mode":"full","commit":"eb83b09a","verdict":"findings","prior":[],"findings":[
{"id":"S1","tag":"dup-test","file":"core/integration_tests/tests_access_control.py","line":2297,"claim":"test_csv_exports_count_only_versions_the_requester_can_view and test_csv_exports_match_the_version_and_its_access_in_one_expansion each define the same `export` closure and exports list.","action":"Pull one helper (e.g. a `csv_rows(url, user, resource)` method that patches write_csv_to_s3 and returns the exported mnemonics) onto the test class and use it in both; the tests themselves (they pin F1.9) stay.","lines_delta":-12,"confidence":"medium","severity":null,"scenario":null},
{"id":"S2","tag":"shrink","file":"core/common/views.py","line":139,"claim":"The `if not prefix: urls = list(urls) else: ...` split in get_viewable_collection_urls nests the limit logic one level deeper than needed.","action":"Handle the exact-value case first with an early `cache[key] = list(urls)` / continue-style return, so the prefix branch (limit, 400, owner-url filter) is un-nested: `if not prefix: cache[key] = list(urls); return cache[key]`.","lines_delta":-3,"confidence":"low","severity":null,"scenario":null},
{"id":"S3","tag":"dup-test","file":"core/integration_tests/tests_access_control.py","line":2155,"claim":"In test_collection_facets_count_only_versions_the_requester_can_view, the three assert_lists calls combining `collection_url=<owner>collections/<prefix>*`, `collection=*` and `collection_owner_url=<owner>` with `collection=<prefix>*` assert the identical expected sets as the plain `collection=<prefix>*` line.","action":"Keep one of the combined-facet lines (one per distinct facet code path: collection_url prefix and collection_owner_url); drop the `collection=*&collection_url=...` variant, which the `collection=*` loop and the collection_url prefix line already cover.","lines_delta":-2,"confidence":"low","severity":null,"scenario":null}
]}

@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Adversarial pass (claude subagent, commit eb83b09)

A fresh reviewer had only the diff and one goal: find any way a requester learns which concepts or mappings are in a collection version they can't view. Channels: global and repository lists, CSV, facets, $match filters and HEAD requests. Details are on the private tracking ticket.

  • Fixed in 7126b2d, each with a test that fails without the fix:
    • $match with a collection filter: since this PR's facet change, it answered 500. It now counts only versions the requester can view, as a list search does.
    • A collection version's own routes: the version the URL names now wins over a version in the query string, so the access check and a search read the same version. Routes with no version in the URL still read the query string's.
  • Already tracked: two index-side items, as answered in passes 2 and 3 (F2.2, F3.1).
  • Elsewhere: other items concern read paths this PR doesn't change. They're recorded on the private ticket.
  • Recorded: with the 1,000-version limit as decided, a bare collection=* from a non-staff requester can answer 400 on a large server. No OCL web client sends a collection wildcard.

The reviewer found everything else closed at this head:

  • every spelling, casing and encoding of the three collection facets;
  • !, * and comma lists;
  • source-scoped lists and their cache;
  • CSV on the global list;
  • item routes and HEAD requests;
  • search stats and fuzzy search.

paynejd and others added 2 commits November 23, 2026 01:00
…on refuses a different version in the query string

Codex final check FC.1 and FC.3: with the URL's version winning, a DELETE or PUT sent to HEAD/ with a query-string version would act on HEAD, and an unresolved `latest` could lose its version. A route that names a version now answers 400 when the query string names a different one, before any read or write; routes that name none still read the query string's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qU5uSpgMo1niq3ECJx
…ng version naming the release it resolves to

Codex check FC2.1: the conflict check now compares the query string's version with `latest` as resolved, so `latest/concepts/?version=v1` answers as before when v1 is the newest release; a different version, or one with no release to resolve to, still answers 400.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qU5uSpgMo1niq3ECJx
@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits a495486..7126b2d (codex-cli 0.169.0, commit 7126b2d)

Verdict: findings (1 P1, 2 P2), all on the version precedence that 7126b2d changed. This pass judged only this PR's own lines in the range (eb83b09, e1d7390, 7126b2d), not the master merge 529f23f.

Finding Response
FC.1 P1: with the URL's version winning, a client that sent DELETE …/collections/C/HEAD/?version=v1 to remove one release would delete the whole collection (DELETE on HEAD/ deletes the repository) Fixed in a88cc2b. A route that names a version now refuses a different version in the query string with 400, before any read or write. It neither picks one silently nor acts on another version. The test sends that DELETE as staff and checks 400, with HEAD and v1 still active.
FC.2 P2: the owner check reads both Collection and collection, while a search keeps only one, so a request naming a private collection under one spelling and a public one under the other is refused Accepted, fails closed. This is the F3.3 fix as intended. The search and the database read don't read the same spelling (the database read takes collection only), so the check refuses a request where either one names a collection the requester can't view. A client would have to send both spellings to hit this.
FC.3 P2: …/C/latest/concepts/?version=v1 on a collection with no release lost its version and could raise MultipleObjectsReturned Fixed by FC.1's fix: a different query-string version on a latest route answers 400. Without a query-string version, latest resolves as it does on master; this PR doesn't change that path.

Pylint is clean and the full suite passes on a88cc2b: 3,560 tests, plus 692 search tests (on a fresh index).

findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "7126b2d4",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "FC.1",
      "severity": "P1",
      "tag": null,
      "file": "core/collections/views.py",
      "line": 116,
      "claim": "The shared version lookup can turn a release deletion into deletion of the entire collection.",
      "scenario": "An authorized client sends DELETE to the explicit HEAD version route with `?version=v1`, using the existing query-string override to select the release. The previous lookup passed v1 to `delete_collection`. The new lookup passes HEAD, whose deletion also removes every sibling version.",
      "action": "Reject conflicting version selectors before a mutation. Add a regression test that verifies the request schedules no deletion.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.2",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1512,
      "claim": "The owner check can reject a search based on a collection value that the search discards.",
      "scenario": "An owner-scoped list request sends `Collection` for a private collection followed by `collection` for a public one. Search normalization keeps the later public value. The new check evaluates both and returns 401 or 403 to someone who could previously run the public search.",
      "action": "Use the effective collection value from the active search or database parser for the owner check, and test both orders of the two spellings.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "FC.3",
      "severity": "P2",
      "tag": null,
      "file": "core/collections/views.py",
      "line": 116,
      "claim": "Giving an unresolved `latest` URL precedence can produce a 500 by dropping the version constraint.",
      "scenario": "A collection has HEAD and an unreleased v1. A member requests its `latest/concepts/?version=v1` list. The previous lookup selected v1. The new lookup selects `latest`, finds no released version, and drops the resulting null version from the queryset. The single-object lookup then finds both rows and raises `MultipleObjectsReturned`.",
      "action": "Return 404 when an explicit `latest` version cannot be resolved, before building the queryset.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 7126b2d..a88cc2b (codex-cli 0.169.0, commit a88cc2b)

Verdict: findings (1 P2). FC.1 and FC.3 resolved; FC.2 stands as accepted.

Finding Response
FC2.1 P2: …/C/latest/concepts/?version=v1 answered 400 even when v1 is the newest release, so both name the same version Fixed in 9df45c9. The conflict check compares the query string's version with latest as resolved. A different version, or any version on a latest route with no release, still answers 400. The test lists v1's members on latest/…?version=v1 and expects 400 for latest/…?version=HEAD. Pylint is clean and the full suite passes on 9df45c9 (3,560 tests, plus 692 search tests).
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "a88cc2b6",
  "verdict": "findings",
  "prior": [
    {"id": "FC.1", "status": "resolved"},
    {"id": "FC.2", "status": "unresolved"},
    {"id": "FC.3", "status": "resolved"}
  ],
  "findings": [
    {
      "id": "FC2.1",
      "severity": "P2",
      "tag": null,
      "file": "core/collections/views.py",
      "line": 118,
      "claim": "The conflict check rejects requests where `latest` and the explicit version select the same release.",
      "scenario": "When `v1` is the newest released version, a member requesting `GET /orgs/O/collections/C/latest/concepts/?version=v1` previously received the `v1` list and now receives 400. A configured Term Browser v2 organization tab can send this combination through its `defaultURI` and `query_params` settings. The added test expects 400 with `v1` as the fixture's only release.",
      "action": "Resolve `latest` before comparing the selectors. Test that a matching release succeeds and that a conflicting or unresolved selector fails before any write.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…ery-string version naming the release it resolves to"

This reverts commit 9df45c9. Codex check FC3.1: comparing the query string's version with `latest` as resolved answered differently when it named that release, before the access check. A route that names a version again refuses any different query-string version with 400.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qU5uSpgMo1niq3ECJx
@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits a88cc2b..9df45c9 (codex-cli 0.169.0, commit 9df45c9)

Verdict: findings (1 P1). FC2.1 resolved by 9df45c9, but that fix brought in FC3.1.

Finding Response
FC3.1 P1: comparing a query-string version with latest as resolved gives a different status, before the access check, when the version names a private collection's newest release Fixed in e13b215 by reverting 9df45c9. The tree is again a88cc2b's: a route that names a version answers 400 for any different query-string version, before any access check, whatever the requester can view. Pylint, the 3,560 tests and the 692 search tests passed on that tree.
FC2.1 P2 (from the previous check), reopened Accepted. …/latest/concepts/?version=v1 answers 400 even when v1 is the newest release. No OCL web client sends a version query parameter to a versioned collection route, and the 400 names both versions. Accepting the match safely would need an access check inside the version lookup, which isn't worth it for a request no client sends.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "9df45c9c",
  "verdict": "findings",
  "prior": [
    {
      "id": "FC2.1",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "FC3.1",
      "severity": "P1",
      "tag": null,
      "file": "core/collections/views.py",
      "line": 128,
      "claim": "The conflict check reveals whether a supplied version is a private collection's latest release.",
      "scenario": "A signed-in nonmember requests a private collection's latest concept list. When the query version matches the private latest release, the request reaches the object permission check and returns 403. A different version returns 400. Before this commit, both explicit version names returned 400. The status difference now confirms the private release's version name.",
      "action": "Check access to the resolved release before comparing the selectors. Test that a nonmember receives the same permission denial for matching and conflicting versions while a member can still use a matching version.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…ivate HEADs once for all versions

For a signed-in requester, the private-HEAD check sat inside an OR with their own and their orgs' versions, so the database ran it once per version: 0.3 s for a collection with 675 versions. It is now a top-level NOT EXISTS that leaves out the requester's own and their orgs' HEADs; a version shares its HEAD's owner, so the versions matched are the same. A test compares the query with has_view_access on every version, for each kind of requester.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qU5uSpgMo1niq3ECJx
@paynejd

paynejd commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits e13b215..de591bb (codex-cli 0.169.0, commit de591bb)

Verdict: findings (1 P2). The commit changes the shape of the viewable-versions query (a top-level anti-join; 301 ms → 2 ms for a signed-in lookup on a collection with 675 versions, measured on production).

Finding Response
FC4.1 P2: a legacy collection row with both an org and a user as owner could be hidden from the org's other members when that user also has a private personal HEAD with the same name, because the private-HEAD check matches on either owner Accepted. Production has no such rows: a read-only count today found 0 collection rows with both owners set, and 0 that also have a same-named personal HEAD. Collections get one owner on creation. The earlier query matched HEADs on either owner the same way on its public path. Fixing it inside the query would need a condition on the outer row's owner type. That isn't worth it for rows that don't exist.

Pylint is clean and the full suite passes on de591bb (3,561 tests, plus 692 search tests).

findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "de591bb1",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "FC4.1",
      "severity": "P2",
      "tag": null,
      "file": "core/common/models.py",
      "line": 1198,
      "claim": "The rewritten predicate can hide a legacy collection from members of its owning organization.",
      "scenario": "Before [OpenConceptLab/oclapi2#979](https://github.com/OpenConceptLab/oclapi2/pull/979), collection creation could populate both owner fields. If an org collection version also has Alice's user ID and Alice has a private personal collection with the same mnemonic, her personal HEAD matches the subquery by user ID. For another member of the org, that HEAD survives the exclusion and blocks the org version. The previous predicate allowed the version through org membership. Collection facets and database reads now omit content that matches only through that version.",
      "action": "Apply the ownership bypass to the candidate version and add a regression test with a legacy dual-owner row and a same-named private personal HEAD.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at de591bb. Merge once its CI is green; it was still running when I looked. The fix holds on the paths I traced:

  • get_viewable_versions_criteria gives has_view_access's answer. Public versions need a public HEAD, own and org versions skip the private-HEAD check (their HEAD is theirs too), and inactive versions are left out. de591bb's single anti-join keeps that answer and takes the signed-in BEMRS lookup from 301 ms to 2 ms on prod. Keep it rather than the partial index, as it needs no migration.
  • The three facets match only through version URLs the requester can view. An empty list matches nothing, and ! excludes only versions they can view, so a hidden collection answers like one that doesn't exist.
  • The database read keeps the viewable versions in the same filter as the collection's own criterion, so one expansion must match both. Your EXPLAIN shows no extra cost.
  • The owner check gives a query-string collection the source check from #1023, plus its HEAD.
  • A version route refuses a different query-string version with a 400, which also closes FC.1's DELETE …/HEAD/?version=v1.

Choices for review: I agree with all four. That covers the empty list for an owner-less name, checking a collection's HEAD, the 400 past 1,000 viewable versions when some are hidden, and the 400 for a conflicting version. Fine to leave FC.2, FC2.1 and FC4.1 as accepted (prod has no collection rows with both owners).

The collection facet's buckets still list hidden collections' names and counts. That's #739, so it's not part of this PR.

The description spells out the leak, and master would have the fix before prod does. So once this merges, the release should follow soon.

I haven't run the tests. You report 3,561 tests plus 692 search tests passing on de591bb.

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.

2 participants