Repository navigation
fix(engine): refuse a malformed ExpressionAttributeNames map on SearchVectors - #1322
LeeroyHannigan wants to merge 1 commit into
Conversation
…hVectors SearchVectors read ExpressionAttributeNames without the checks that the other operations run. It accepted a key such as n or ##n, and the projection removed every leading # from each key. So a search with ProjectionExpression #n returned the attribute that key named. Authorization finds a placeholder in the map as written. So dynamodb:Attributes did not hold that attribute, and a Deny on it did not refuse the search. DynamoDB refuses such a key on SearchVectors before it evaluates the policy. The message is the GetItem text: ExpressionAttributeNames contains invalid key: Syntax error; key: "n". It also answers an empty map, a key over 255 bytes and an empty attribute name as GetItem does. It answers an IndexName of two characters, an empty SearchVector and a TopK of 0 ahead of a bad key. A value that is not a string, such as 5, gets SerializationException (measured in us-east-1 on 2026-11-21). The handler now keeps the raw ExpressionAttributeNames member. After the TopK checks, it runs deserialize_expression_names on it. The other operations use the same deserializer. The input struct still reads the map as strings, so a value of another JSON type keeps its SerializationException. The service sets no dynamodb:Attributes value on a SearchVectors request. A Deny gated on Null true refused every search. A Deny on an attribute refused none, whether the projection or the SearchConditionExpression named it. So the SearchConditionExpression names stay out of the key, and a unit test checks that. A wire test sends the measured rows under a Deny on ssn and under an Allow of dynamodb:*. The upgrade manual records the change. docs/differences-from-dynamodb.md records the difference in the key. Refs #729
demohan
left a comment
There was a problem hiding this comment.
#1449, merged on 2026-11-26, closes the issues this names (#1317 to #1320) and does what this does and more, and the branch now conflicts with main at 222d80a in search_vectors.rs, request_attributes.rs, its tests, the upgrade manual and test_authz_search_vectors_index.py. With 113 SearchVectors shapes sent twice to the us-east-1 search endpoint and to this head and main on SQLite and PostgreSQL with pgvector, main matches the service where this head differs: an empty key gets Syntax error; key: "" here and ...contains an empty key; there and on main; an unused name, names with no expression, a 65,536-byte name and values with no condition answer 200 here and are refused there; a condition syntax error loses its detail; and a caller denied the action gets AccessDeniedException here where main gives ValidationException on all 15 malformed-map shapes. The new wire file passes 21 of 21 on main without this change.
I suggest closing this PR in favour of #1449. One line here would still merge without a conflict and is not true on main: docs/differences-from-dynamodb.md:41 says ExtendDB holds the projected attributes, while main leaves dynamodb:Attributes absent, as the service does, and 10-security-model.md:241 says so.
What
SearchVectors now checks its
ExpressionAttributeNamesmap withdeserialize_expression_names, the deserializer that GetItem, Query, Scan and the other operations use. It refuses a key that is not#followed by letters, digits and underscores. It also refuses an empty map, a key over 255 bytes and an empty attribute name. Each refusal is aValidationExceptionwith the GetItem message.The check runs after the
IndexName,SearchVectorandTopKchecks. The input struct still reads the map as strings, so a value of another JSON type keeps itsSerializationException.The upgrade manual gets a v1.1.0 entry for the change.
docs/differences-from-dynamodb.mdgets a row for thedynamodb:Attributesvalue of SearchVectors. Thedynamodb:Attributescode changes only in its module comments.Why
SearchVectors accepted a key such as
nor##n. Its projection removed every leading#from each key, soProjectionExpression#nreturned the attribute that key named. Authorization finds a placeholder in the map as written, sodynamodb:Attributesdid not hold that attribute. Under a Deny onssn, a SearchVectors with{"n": "ssn"}returnedssn.Measured on DynamoDB in us-east-1 on 2026-11-21, each request twice with the same answer:
ProjectionExpression#n, names{"n": "ssn"}ExpressionAttributeNames contains invalid key: Syntax error; key: "n"ssnProjectionExpression#n, names{"##n": "ssn"}... Syntax error; key: "##n"ssnSearchConditionExpression#s = :v, names{"s": "ssn"}... Syntax error; key: "s"{}ExpressionAttributeNames must not be emptyExpressionAttributeNames contains invalid key: The expression attribute map contains a key that is too long; size of key: 256{"#n": ""}ExpressionAttributeNames contains invalid value: Empty attribute name for key #nGetItem answers the first two maps and the last three with the same messages. The service sends them before the policy decision: under a Deny of
dynamodb:SearchVectorsit answers the{"n": "ssn"}request with theValidationException. It answers anIndexNameof two characters, an emptySearchVectorand aTopKof 0 ahead of a bad key. A value that is not a string, as in{"n": 5}, getsSerializationException.The issue also asks to put the
SearchConditionExpressionnames indynamodb:Attributes. The service puts no name in that key on a SearchVectors request. Under a Deny gated onNull {"dynamodb:Attributes": "true"}, it refused every SearchVectors, a projected one included. Under a Deny onssn, it served a SearchVectors whose projection or condition namedssn, and refused a GetItem ofssn. It also served a search under a Deny on the table keypk, on the vector attribute and on a search schema attribute. So this PR leaves the condition names out of the key, as main does.Refs #729
Testing done
The head is
43b3ab43e.tests/test_authz_search_vectors_index.pyadds one data table of ten measured rows and a GetItem control. Each refusal row asserts the status and__type.ValidationExceptionrows assert the full message.SerializationExceptionrow asserts the text that ExtendDB and the service share. The service adds the position in the body, and ExtendDB puts a sentence of its own before the text (A request member of the wrong JSON type gets serde_json's error text, where the service sends its own #1012).tests/test_search_vectors_condition_limit.py, 64 passed.test_dynamodb_attributes_*files andtest_fgac_attributes.pypassed 102 tests.search_vectors_holds_its_projected_pathsincrates/server/src/request_attributes/tests.rsnow pins thedynamodb:Attributesvalue of four SearchVectors requests. It passes on main too, because the key code does not change.IndexNamecheck: theTopKrow failed with the key message.AccessDeniedException.#inrequest_attributes.rs: the unit test failed at "a key without #", and two wire rows gotAccessDeniedException.deserialize_withon the struct field in place of the check failed theTopKrow and the{"n": 5}row with the key message.cargo +1.97.0 fmt --all -- --checkpassed. The two clippy commands ofclippy.ymlgave no warnings with-D warnings, run with-p extenddb-engine -p extenddb-server. The first one ran without its--featureslist of storage test hooks, which these two crates do not have.cargo +1.91.1 checkof both crates passed. The new lines add no pedantic warning.cargo test -p extenddb-engine --libpassed 871 tests.cargo test -p extenddb-server --libpassed 513 tests. Fivebackup_storetests failed on this host because of its directory owners. They fail the same way on main there.Not covered, each with the measurement in its issue:
ExpressionAttributeValueskey without:: SearchVectors accepts an ExpressionAttributeValues key that does not start with ":" #1317.SearchConditionExpressionof 4,107 bytes, which the service refuses for its size: SearchVectors serves a SearchConditionExpression over the expression size limit #1318.##cin aSearchConditionExpressionthrough the key#c: SearchVectors resolves ##c in a SearchConditionExpression through the name #c #1319.ExpressionAttributeNamesentry: SearchVectors does not refuse an unused ExpressionAttributeNames entry #1320.AccessDeniedException, where the service answers theValidationException. A comment on Query: a principal the policy does not allow gets AccessDeniedException for a request with a fault, where DynamoDB answers the fault #1191 adds SearchVectors and GetItem.{"n": 5}withValidationException, where the service answersSerializationException: An ExpressionAttributeNames entry with a malformed key and a value that is not a string answers ValidationException, where DynamoDB answers SerializationException #1321.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
Breaking changes
A SearchVectors request with one of the name maps above gets
ValidationException. Earlier releases served it.By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.