on master help sign in
preventing priority DOS attacks.
commit64577de65c34da4fff2da3db372775ad8d2ea8e9 authorKazu Yamamoto <kazu@iij.ad.jp> dateMon 16 Nov 2015, 12:29 (11 years ago) parent2d3106c
2 files changed+7−2
warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs+5−2 warp/Network/Wai/Handler/Warp/HTTP2/Types.hs+2
warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs+5−2
@@ -316,14 +316,17 @@ stream FrameRSTStream header bs _ _ strm = do
316316 closed strm cc
317317 return $ Closed cc -- will be written to streamState again
318318
319−stream FramePriority header bs Context{outputQ} s Stream{streamNumber,streamPrecedence} = do
319+stream FramePriority header bs Context{outputQ,priorityTreeSize} s Stream{streamNumber,streamPrecedence} = do
320320 PriorityFrame newpri <- guardIt $ decodePriorityFrame header bs
321321 checkPriority newpri streamNumber
322322 -- checkme: this should be tested
323323 oldpre <- readIORef streamPrecedence
324324 let !newpre = toPrecedence newpri
325325 writeIORef streamPrecedence newpre
326− if isIdle s then
326+ if isIdle s then do
327+ n <- atomicModifyIORef' priorityTreeSize (\x -> (x+1,x+1))
328+ -- fixme hard coding
329+ when (n >= 20) $ E.throwIO $ ConnectionError EnhanceYourCalm "too many idle priority frames"
327330 prepare outputQ streamNumber newpri
328331 else do
329332 mx <- delete outputQ streamNumber oldpre
warp/Network/Wai/Handler/Warp/HTTP2/Types.hs+2
@@ -130,6 +130,7 @@ data Context = Context {
130130 -- | Number of active streams initiated by the server; for respecting the
131131 -- client's max concurrency setting.
132132 , pushConcurrency :: IORef Int
133+ , priorityTreeSize :: IORef Int
133134 -- | RFC 7540 says "Other frames (from any stream) MUST NOT
134135 -- occur between the HEADERS frame and any CONTINUATION
135136 -- frames that might follow". This field is used to implement
@@ -153,6 +154,7 @@ newContext = Context <$> newIORef defaultSettings
153154 <*> initialize 10 -- fixme: hard coding: 10
154155 <*> newIORef 0
155156 <*> newIORef 0
157+ <*> newIORef 0
156158 <*> newIORef Nothing
157159 <*> newIORef 0
158160 <*> newIORef 2 -- first server push stream; 0 is reserved