fail on >100 input lengths
This is already limited by <input> on frontend so it only happens if the user deliberately crafts a malicious request
This commit is contained in:
parent
a84c096968
commit
69d5795eed
2 changed files with 15 additions and 2 deletions
|
|
@ -13,3 +13,6 @@ badPollId = throwError . withReason err400 . T.append "not a valid id: " . T.pac
|
|||
|
||||
noPollFound :: P.PollId -> AppM a
|
||||
noPollFound = throwError . withReason err404 . T.append "invalid id, no poll with id: " . T.pack . show
|
||||
|
||||
nameTooLong :: AppM a
|
||||
nameTooLong = throwError . withReason err400 $ "poll field was too long"
|
||||
|
|
|
|||
14
src/Main.hs
14
src/Main.hs
|
|
@ -34,6 +34,11 @@ import qualified Network.HTTP.Types.Status as TS
|
|||
import LucidUtils
|
||||
import qualified Data.Text.Lazy as TL
|
||||
|
||||
checkLength :: T.Text -> AppM ()
|
||||
checkLength txt
|
||||
| (T.length txt) <= 100 = pure ()
|
||||
| otherwise = Er.nameTooLong
|
||||
|
||||
throwOrLift :: AppM a -> Maybe a -> AppM a
|
||||
throwOrLift err = My.maybe err pure
|
||||
|
||||
|
|
@ -86,9 +91,9 @@ nthPlaces =
|
|||
with span_ [classes_ ["third-place", "badge"]] "3rd"]
|
||||
++ map (\n -> with span_ [class_ "badge"] . toHtml $ T.append (T.pack . show $ n) "th") [4 :: Int ..]
|
||||
|
||||
|
||||
makePoll :: P.CreatePollInfo -> AppM (L.Html ())
|
||||
makePoll pollReq = do
|
||||
checkTextLengths
|
||||
db <- Rd.asks db
|
||||
gen <- Rd.asks gen
|
||||
pollId <- P.PollId <$> R.uniformWord64 gen
|
||||
|
|
@ -97,13 +102,18 @@ makePoll pollReq = do
|
|||
pure . div_ $ do
|
||||
"done! people can fill out your poll at "
|
||||
with a_ [href_ fillOutLink] (toHtml fillOutLink)
|
||||
|
||||
where
|
||||
checkTextLengths = do
|
||||
M.mapM_ checkLength . LN.toList . P.options $ pollReq
|
||||
checkLength . P.question $ pollReq
|
||||
maybe (pure ()) checkLength . P.title $ pollReq
|
||||
|
||||
toPollIdLink :: P.PollId -> T.Text
|
||||
toPollIdLink (P.PollId pollId) = T.append "https://rankedchoice.net/poll/" (T.pack . show $ pollId)
|
||||
|
||||
vote :: P.PollId -> B.Ballot -> AppM (L.Html ())
|
||||
vote pollId ballot = do
|
||||
M.mapM_ checkLength . B.options $ ballot
|
||||
db <- Rd.asks db
|
||||
liftIO $ Ac.update db (DB.PostBallot pollId ballot')
|
||||
pure $ with div_ [id_ "resultLink"] $ do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue