IpInetAddressMatcher throws ArrayIndexOutOfBoundsException instead of returning false for mismatched IPv4/IPv6 families
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 88/100
Direzione di ricerca
Parti da IpInetAddressMatcher.matches(InetAddress), segnalato in IpInetAddressMatcher.java:100, e verifica come vengono confrontati gli array di byte degli indirizzi configurato e verificato. Aggiungi una copertura di regressione per famiglie IPv4 e IPv6 non corrispondenti, inclusi gli indirizzi che riproducono il problema. Il lavoro è completato quando matches() restituisce false invece di generare una ArrayIndexOutOfBoundsException.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
IpInetAddressMatcher.matches(InetAddress) (introduced in 7.1, backing IpAddressMatcher/InetAddressMatchers) can throw ArrayIndexOutOfBoundsException instead of returning false when the address being checked and the configured address are of different IP families (IPv4 vs. IPv6).
The class-level Javadoc on IpAddressMatcher states:
a matcher which is configured with an IPv4 address will never match a request which returns an IPv6 address, and vice-versa.
The current implementation doesn't enforce this at the byte-array level:
byte[] remAddr = toCheck.getAddress();
byte[] reqAddr = this.requiredAddress.getAddress();
int nMaskFullBytes = this.nMaskBits / 8;
byte finalByte = (byte) (0xFF00 >> (this.nMaskBits & 0x07));
for (int i = 0; i < nMaskFullBytes; i++) {
if (remAddr[i] != reqAddr[i]) {
return false;
}
}
There's no check that remAddr.length == reqAddr.length. If the configured CIDR mask requires more full bytes than the shorter of the two addresses has (e.g. an IPv6 /64 matcher checked against an IPv4 address), and the leading bytes happen to be equal up to the shorter array's length, the loop indexes past the end of the shorter array.
To Reproduce
IpAddressMatcher matcher = new IpAddressMatcher("2001:db8::/64");
// 32.1.13.184's bytes (0x20, 0x01, 0x0d, 0xb8) equal the first 4 bytes of 2001:0db8::,
// so the comparison loop doesn't short-circuit before running past the 4-byte array.
matcher.matches("32.1.13.184");
This throws:
java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
at org.springframework.security.util.matcher.IpInetAddressMatcher.matches(IpInetAddressMatcher.java:100)
instead of returning false.
Expected behavior
matches() should return false when the two addresses belong to different families, per the documented contract, instead of throwing.
Sample
I have a fix ready (add a length check on the two byte arrays before comparing them) plus regression tests, and will open a PR referencing this issue.
- Lingua principale
- Java
- Stelle
- 9.6k
- Fork
- 6.4k
- Merge medio
- 16h 53m
- PR unite (30g)
- 46
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di spring-projects/spring-security
-
status: waiting-for-triage type: enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
spring-projects/spring-security#19805 ·
I maintainer di solito rispondono entro 1 giorno
-
status: waiting-for-triage type: enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
spring-projects/spring-security#19783 ·
I maintainer di solito rispondono entro 1 giorno
-
status: waiting-for-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
spring-projects/spring-security#19781 ·
I maintainer di solito rispondono entro 1 giorno
-
[doc issue] filter orderingApertastatus: waiting-for-triage type: enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
spring-projects/spring-security#19730 ·
I maintainer di solito rispondono entro 1 giorno
-
status: waiting-for-triage type: bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
spring-projects/spring-security#19728 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di spring-projects/spring-security
Issue simili
-
area/frontend good first issue kind/cooldown
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
beehive-lab/TornadoVM#1151 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
(cbor) `maxStringLength` not consistently checked for chunked (indefinite-length) text valuesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
FasterXML/jackson-dataformats-binary#823 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno