@@ -143,7 +143,26 @@ sendResponse :: ByteString -- ^ default server value
143143 -> IO ByteString -- ^ source from client, for raw response
144144 -> Response -- ^ HTTP response including status code and response header.
145145 -> IO Bool -- ^ Returing True if the connection is persistent.
146−sendResponse defServer conn ii req reqidxhdr src response = do
146+sendResponse defServer conn ii req reqidxhdr src response =
147+ sendResponse' defServer conn ii req reqidxhdr src response'
148+ where
149+ doesContainCRLF :: [ByteString] -> Bool
150+ doesContainCRLF = or . map (S.any (\w -> w == 10 || w == 13))
151+ hsv = map snd $ responseHeaders response
152+ response'
153+ | doesContainCRLF hsv = response400
154+ | otherwise = response
155+ response400 = responseLBS H.badRequest400 [(H.hContentType, "text/plain; charset=utf-8")] "Bad Request"
156+
157+sendResponse' :: ByteString -- ^ default server value
158+ -> Connection
159+ -> InternalInfo
160+ -> Request -- ^ HTTP request.
161+ -> IndexedHeader -- ^ Indexed header of HTTP request.
162+ -> IO ByteString -- ^ source from client, for raw response
163+ -> Response -- ^ HTTP response including status code and response header.
164+ -> IO Bool -- ^ Returing True if the connection is persistent.
165+sendResponse' defServer conn ii req reqidxhdr src response = do
147166 hs <- addServerAndDate hs0
148167 if hasBody s then do
149168 -- HEAD comes here even if it does not have body.