Skip to content

fix(api): Reject query operands the column cannot take (backport #925) - #932

Merged
bupd merged 1 commit into
release-2.15from
backport/pr-925-to-release-2.15
Sep 16, 2026
Merged

bupd merged 1 commit into
release-2.15from
backport/pr-925-to-release-2.15

Conversation

@bupd

@bupd bupd commented Sep 16, 2026

Copy link
Copy Markdown
Member

Backport of #925 to release-2.15. Replaces #909, which carried the superseded #874 commit.

A search filter whose value did not fit the column returned 500, leaking the raw Postgres error. It should be 400.

GET /projects?q=creation_time=[a~b]     → 500  invalid input syntax for type timestamp: "a"
GET /audit-logs?q=op_time=[x~y]         → 500
GET /artifacts?q=push_time=[2020~abc]   → 500

What changed

Filter values are checked against the column's type before the query is built, and a mismatch returns 400 instead of reaching the database. This covers every endpoint that filters through orm.QuerySetter.

The check is deliberately permissive, so queries that work today keep working:

  • text columns take anything; fuzzy matches and __icontains are exempt, since they search as text
  • number columns take numbers and numeric strings, within the column's width
  • time columns take the documented 2020-04-09 02:36:00 format plus the other forms Postgres accepts
  • booleans take Postgres's full set, including yes, on and n

Relationship to #909

#909 backported #874, which was closed and continued as #925 after picking up review fixups — column-width checks, the boolean token set, the __icontains exemption, and a corrected DB test case. Rather than retrofit #909 in place, this is a fresh branch cut from the merged commit so the content is exactly what landed on main.

How it was produced

Cherry-pick equivalent of a39a4d7, the squashed merge of #925. All five touched files were byte-identical between release-2.15 and a39a4d7's parent before the pick, so nothing release-specific was overwritten.

How it was verified

Built against the release-2.15 base, with lib/orm and lib/q green and the db-tagged pkg/project/dao filter-value suite passing against a freshly migrated Postgres on this branch:

--- PASS: TestDaoTestSuite/TestListInvalidFilterValue
--- PASS: TestDaoTestSuite/TestListValidFilterValue

A filter operand that does not match its column type reached Postgres
verbatim and the driver error surfaced to the client as a 500:

    GET /projects?q=creation_time=[a~b]
    -> 500, core: invalid input syntax for type timestamp: "a"

Same for /audit-logs?q=op_time=[x~y] and artifacts ?q=push_time=[2020~abc],
and for exact matches and or-lists against integer columns.

Record each model field type while parsing the model metadata and check
the operand against it before the filter is applied, returning a bad
request instead. The check is deliberately permissive so nothing that
works today stops working: text columns take any literal, number columns
take numerics within the column's own width, timestamp columns take the
documented format and the other forms Postgres reads, booleans take the
full Postgres token set, and fuzzy matches and __icontains are exempt
because both render as ILIKE, which casts the column to text.

Clean backport of the merged a39a4d7, which is #874 plus the review
fixups that landed on it. Replaces #909, which carried the superseded
#874 commit.

Signed-off-by: Prasanth Baskar <prasanth@8gears.com>
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: d59372c7-01f3-4330-823c-16a2d8702e55

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@bupd
bupd merged commit 30d06ea into release-2.15 Sep 16, 2026
26 checks passed
@bupd
bupd deleted the backport/pr-925-to-release-2.15 branch September 16, 2026 07:51
@github-actions github-actions Bot added the tests label Sep 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Preview images for this PR are available in 8gears.container-registry.com/8gcr-pr with tag pr-932.

  • 8gears.container-registry.com/8gcr-pr/harbor-core:pr-932
  • 8gears.container-registry.com/8gcr-pr/harbor-jobservice:pr-932
  • 8gears.container-registry.com/8gcr-pr/harbor-registryctl:pr-932
  • 8gears.container-registry.com/8gcr-pr/harbor-exporter:pr-932
  • 8gears.container-registry.com/8gcr-pr/harbor-portal:pr-932
  • 8gears.container-registry.com/8gcr-pr/harbor-registry:pr-932
  • 8gears.container-registry.com/8gcr-pr/trivy-adapter:pr-932

Verify a preview image:

cosign verify \
  --certificate-identity-regexp="https://github.com/container-registry/harbor-next/.github/workflows/pr-ci.yml@.*" \
  --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \
  8gears.container-registry.com/8gcr-pr/harbor-core:pr-932

Verify SBOM attestation:

cosign verify-attestation \
  --certificate-identity-regexp="https://github.com/container-registry/harbor-next/.github/workflows/pr-ci.yml@.*" \
  --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \
  --type spdxjson \
  8gears.container-registry.com/8gcr-pr/harbor-core:pr-932

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.

1 participant