Skip to content

fix(engine): refuse a malformed ExpressionAttributeNames map on SearchVectors - #1322

Open
LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/729-searchvectors-expression-names
Open

LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/729-searchvectors-expression-names

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

What

SearchVectors now checks its ExpressionAttributeNames map with deserialize_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 a ValidationException with the GetItem message.

The check runs after the IndexName, SearchVector and TopK checks. The input struct still reads the map as strings, so a value of another JSON type keeps its SerializationException.

The upgrade manual gets a v1.1.0 entry for the change. docs/differences-from-dynamodb.md gets a row for the dynamodb:Attributes value of SearchVectors. The dynamodb:Attributes code changes only in its module comments.

Why

SearchVectors accepted a key such as n or ##n. Its projection removed every leading # from each key, so 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. Under a Deny on ssn, a SearchVectors with {"n": "ssn"} returned ssn.

Measured on DynamoDB in us-east-1 on 2026-11-21, each request twice with the same answer:

SearchVectors request DynamoDB ExtendDB before
ProjectionExpression #n, names {"n": "ssn"} ExpressionAttributeNames contains invalid key: Syntax error; key: "n" 200, returns ssn
ProjectionExpression #n, names {"##n": "ssn"} ... Syntax error; key: "##n" 200, returns ssn
SearchConditionExpression #s = :v, names {"s": "ssn"} ... Syntax error; key: "s" 200
names {} ExpressionAttributeNames must not be empty 200
a 256-byte key ExpressionAttributeNames contains invalid key: The expression attribute map contains a key that is too long; size of key: 256 200
names {"#n": ""} ExpressionAttributeNames contains invalid value: Empty attribute name for key #n 200

GetItem 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:SearchVectors it answers the {"n": "ssn"} request with the ValidationException. 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, as in {"n": 5}, gets SerializationException.

The issue also asks to put the SearchConditionExpression names in dynamodb:Attributes. The service puts no name in that key on a SearchVectors request. Under a Deny gated on Null {"dynamodb:Attributes": "true"}, it refused every SearchVectors, a projected one included. Under a Deny on ssn, it served a SearchVectors whose projection or condition named ssn, and refused a GetItem of ssn. It also served a search under a Deny on the table key pk, 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.py adds one data table of ten measured rows and a GetItem control. Each refusal row asserts the status and __type.
  • On the head, the three test_dynamodb_attributes_* files and test_fgac_attributes.py passed 102 tests.
  • search_vectors_holds_its_projected_paths in crates/server/src/request_attributes/tests.rs now pins the dynamodb:Attributes value of four SearchVectors requests. It passes on main too, because the key code does not change.
  • Mutants, each on the committed tree and reverted afterwards:
    • The check removed, which makes the handler main's: six wire rows (the key, map and name rows) failed with 200.
    • The check moved ahead of the IndexName check: the TopK row failed with the key message.
    • The condition names added to the key: the unit test failed at "a condition on ssn", and two wire rows got AccessDeniedException.
    • A key lookup that strips # in request_attributes.rs: the unit test failed at "a key without #", and two wire rows got AccessDeniedException.
  • A build with deserialize_with on the struct field in place of the check failed the TopK row and the {"n": 5} row with the key message.
  • cargo +1.97.0 fmt --all -- --check passed. The two clippy commands of clippy.yml gave no warnings with -D warnings, run with -p extenddb-engine -p extenddb-server. The first one ran without its --features list of storage test hooks, which these two crates do not have. cargo +1.91.1 check of both crates passed. The new lines add no pedantic warning.
  • cargo test -p extenddb-engine --lib passed 871 tests. cargo test -p extenddb-server --lib passed 513 tests. Five backup_store tests failed on this host because of its directory owners. They fail the same way on main there.
  • I ran no wire test on PostgreSQL. CI runs this file on SQLite and on PostgreSQL with pgvector.

Not covered, each with the measurement in its issue:

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, 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.

…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 demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#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.

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.

2 participants