Weakness · Medium

CWE-462: Duplicate Key in Associative List (Alist)

What it is

Duplicate keys in associative lists can lead to non-unique keys being mistaken for an error.

Likelihood of exploit: LowMITRE CWE 4.19.1

Severity (our rating)
Medium
Likelihood of exploit
Low
Introduced during
Implementation
Exploited in the wild
No CVE in CISA's catalog

In more detail

A duplicate key entry -- if the alist is designed properly -- could be used as a constant time replace function. However, duplicate key entries could be inserted by mistake. Because of this ambiguity, duplicate key entries in an association list are not recommended and should not be allowed.

What an attacker can do

  • Quality Degradation (Other)
  • Varies by Context (Other)

How to prevent it

Architecture and Design

  • Use a hash table instead of an alist.
  • Use an alist which checks the uniqueness of hash keys with each entry before inserting the entry.

CWE-462 on MITRE's CWE site

H2 Security

Found it in your code?

We review where it appears, fix it with your team, and check it was not already used against you.

Talk to our team

T Academy

Stop writing it in the first place

Learn to build software and systems without weaknesses like this one, with practice on real hosts in your browser, every objective checked on the machine.

Start free

Source: MITRE Common Weakness Enumeration, CWE version 4.19.1. CWE is a trademark of The MITRE Corporation.