Skip to content

Raise TypeError when string is passed as IndexDefinition prefix#3983

Open
Br1an67 wants to merge 1 commit intoredis:masterfrom
Br1an67:fix/index-definition-prefix-type-check
Open

Raise TypeError when string is passed as IndexDefinition prefix#3983
Br1an67 wants to merge 1 commit intoredis:masterfrom
Br1an67:fix/index-definition-prefix-type-check

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Description of change

Passing a string to the prefix parameter of IndexDefinition causes it to be iterated character-by-character, resulting in each character being treated as a separate prefix. For example:

defn = IndexDefinition(prefix="MY:KEY:", index_type=IndexType.HASH)
# Actually indexes hashes prefixed by 'M', 'Y', ':', 'K', 'E', ...

This adds a type check in _append_prefix that raises TypeError with a helpful error message suggesting to wrap the string in a list:

TypeError: prefix must be a list of strings, not a single string. Did you mean prefix=['MY:KEY:']?

Pull Request check-list

  • Do tests and lints pass with this change?
  • Is the new or changed code fully tested?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?

Fixes #3890


Note

Low Risk
Low risk: adds a small input validation check and a targeted test; the only behavioral change is that previously-accepted (but buggy) string prefix values now raise TypeError.

Overview
Prevents accidental character-by-character prefix expansion by making IndexDefinition(prefix=...) raise TypeError when prefix is a single string (with a hint to wrap it in a list).

Adds a regression test ensuring IndexDefinition(prefix="...") fails with the expected error.

Written by Cursor Bugbot for commit 6a6a418. This will update automatically on new commits. Configure here.

Passing a string to the prefix parameter of IndexDefinition causes
it to be iterated character-by-character, resulting in each character
being treated as a separate prefix. This adds a type check that raises
TypeError with a helpful suggestion to wrap the string in a list.
@jit-ci
Copy link

jit-ci bot commented Mar 1, 2026

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@petyaslavova
Copy link
Collaborator

Hi @Br1an67, thank you for your contribution! We will have a look at it.

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.

IndexDefinition Prefix Footgun

2 participants