Pārlūkot izejas kodu

Merge pull request #1341 from yubiuser/prevent/CRLF

Prevent CRLF injection attempts
bel2125 5 dienas atpakaļ
vecāks
revīzija
a990042604
1 mainītis faili ar 13 papildinājumiem un 0 dzēšanām
  1. 13 0
      src/civetweb.c

+ 13 - 0
src/civetweb.c

@@ -18880,6 +18880,19 @@ get_uri_type(const char *uri)
 	 * and % encoded symbols.
 	 */
 	for (i = 0; uri[i] != 0; i++) {
+		/* Check for CRLF injection attempts */
+		if (uri[i] == '%') {
+			if (uri[i+1] == '0' && (uri[i+2] == 'd' || uri[i+2] == 'D')) {
+				/* Found %0d (CR) */
+				DEBUG_TRACE("CRLF injection attempt detected: %s\r\n", uri);
+				return 0;
+			}
+			if (uri[i+1] == '0' && (uri[i+2] == 'a' || uri[i+2] == 'A')) {
+				/* Found %0a (LF) */
+				DEBUG_TRACE("CRLF injection attempt detected: %s\r\n", uri);
+				return 0;
+			}
+		}
 		if ((unsigned char)uri[i] < 33) {
 			/* control characters and spaces are invalid */
 			return 0;