Repository navigation
Conversation
strip_newlines only replaced U+000A, so a value containing CRLF or a lone CR kept a raw carriage return inside the quoted GraphQL string literal. CR is a LineTerminator in the GraphQL grammar and is not a legal unescaped character inside a string, so the server rejects the request with 'Unterminated string' rather than running the query. Text that passed through a Windows newline is the common source.
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
|
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge. |
|
I have read and I agree with the Contributor License Agreement. |
|
Bumping two at once rather than making you read them separately. #2166 — client-side batching under-reports failures and misattributes them. The wholesale-failure handler in #2168 — The question on #2166 is the one I am least sure of: I fixed the reader by re-keying each chunk's errors against its offset in the batch. The alternative is to fix it at the point of construction, so an error map never contains chunk-local indices in the first place. The second is arguably less code and less prone to the same mistake appearing in the other batch helpers — there are a few more that build the same shape. For #2168 there is nothing outstanding from me; it is a small, self-contained fix with the reproduction in the description. If either is unwanted I would rather know and close it than leave it hanging. |
|
Hi @weaviate maintainers — #2168 has been open since 26 September with CI green, so this is the one nudge I planned. Recap: One thing I checked rather than assumed, so you do not have to: the neighbour that escapes backslashes and quotes runs on the same string, so the only path to a raw CR reaching the server is this one — I grepped the package for other writers into the same literal. If you would rather CR be escaped rather than collapsed ( |
|
Thanks for the fix and the tests, @feiiiiii5! This sanitizer only runs on the GraphQL aggregate path, which the client uses only for Weaviate 1.27 and 1.28. From 1.29 on, aggregations go over gRPC and never touch this code. That path is also slated for removal once 1.29 becomes the minimum supported version which is happening with the next release. Because of that, we're closing this one. If you hit this on a setup we're missing, or have another reason to merge it, please explain here and we'll reopen. |
|
Understood — I won't push for a reopen. One thing worth knowing when you remove the aggregate path: |
Problem
_sanitize_str()can emit a GraphQL string literal containing a raw carriage return, which makes the whole query fail to parse server-side.strip_newlines()only replacesU+000A:A
"foo\r\nbar"value therefore becomes"foo bar"with a stray\rleft in front of the space, and a lone"foo\rbar"is untouched. In the GraphQL grammarLineTerminatoris LF or CR, and an unescapedLineTerminatoris not a legal character inside a string literal — which is exactly why this function replaces newlines at all. CR simply never got the same treatment as LF.Reachable through the ordinary filter path: any
Whereoperand whosevalueText/valueTextList/valueStringvalue carries a carriage return goes through_sanitize_str(weaviate/gql/filter.py:692,695), as does an aggregatequery(weaviate/gql/aggregate.py:46). Text that passed through a Windows newline is the common source.Change
Collapse both line terminators, and CRLF to a single space rather than to "space + stray CR":
No new dependency, no change to any other character, and existing LF behaviour is byte-identical.
How this was verified
Regression cases added to the repo's own parametrized
test_sanitize_strintest/test_util.py(that test previously pinned only the backslash/quote cases, nothing about line terminators).Base control —
weaviate/util.pyrestored from142d798a93177215e68d44601c9653a856b3c373withgit diff --stat -- weaviate/util.pyprinting nothing, so the run measures upstream code while the new cases are kept:With the patch applied:
Whole unit suite, base and head, to show the diff changes only what it claims:
The three
test/test_timeout.pyfailures are present at base142d798aunchanged, so they are not caused by this diff; they look environment-related (they spawn interpreters to test the timeout decorator). The mock suite passes:python -m pytest mock_tests -q→65 passed.Consequence, measured rather than asserted from the spec — building a real Weaviate-shaped query and lexing it with
graphql-core(a spec-faithful parser, since I have no Weaviate server in this environment):I did not run the integration/compose suite, so the server-side rejection is demonstrated through the grammar and a spec parser rather than against a live Weaviate instance.
CLA:CONTRIBUTING.mdrequires a Contributor License Agreement for this repo; that is an account-owner action outside this diff.