Skip to content

Redis ShortKey encoding is not reversible for keys containing literal percent-encoded sequences #13

@gfraiteur

Description

@gfraiteur

Description

The ShortKey encoding in PostSharp.Patterns.Caching.Backends.Redis is not reversible when user cache keys contain literal percent-encoded sequences like %7B, %7D, or %3A.

Root Cause

GetShortKeyFromUserKey escapes {, }, : to %7B, %7D, %3A respectively, but does not escape the % character itself. This means GetUserKeyFromShortKey cannot distinguish between an escaped { (which becomes %7B) and a literal %7B that was already in the original key.

Example:

  • User key: key-with-%7B-literal
  • After encoding: key-with-%7B-literal (unchanged, no {, }, or : present)
  • After decoding: key-with-{-literal (incorrect — %7B was decoded even though it was literal)

Fix

Escape % to %25 before escaping the other characters in GetShortKeyFromUserKey, and unescape %25 back to % after unescaping the others in GetUserKeyFromShortKey.

Fixed in PR #35.

Related: metalama/Metalama#1427

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions