Skip to content

djb2_hash_u32 truncates path components after 32 bytes can trigger policies in a false positive way #21

@JackySu

Description

@JackySu

fn djb2_hash_u32(s: &str) -> u32 {
let mut hash: u32 = 5381;
for c in s.bytes().take(32) {
hash = hash.wrapping_mul(33).wrapping_add(c as u32);
}
hash
}

djb2_hash_u32 (hash = hash * 33 + c) can easily cause collisions, e.g.

  • .ssh and 01sh
  • .aws and .axR

I would say replacing it with a stronger crypto-safe method like SipHash-1-3, or double-checks with both hashing and string matching (which requires BPF map, linux kernel ver. 5.17+)

love to hear feedback from maintainers : )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions