File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 55from urllib .parse import quote_plus
66
77import discord
8+ import yarl
89from aiohttp import ClientResponseError
910from discord .ext .commands import Cog
1011
@@ -272,6 +273,16 @@ async def _parse_snippets(self, content: str) -> str:
272273
273274 for pattern , handler in self .pattern_handlers :
274275 for match in pattern .finditer (content ):
276+ # ensure that the matched URL meets url normalization rules.
277+ # parsing with yarl resolves all parent urls such as `/../`,
278+ # we then check the regex again to make sure our groups stay the same
279+ unsanitized = match .group (0 )
280+ normalized = str (yarl .URL (unsanitized ))
281+ if normalized != unsanitized :
282+ match = pattern .fullmatch (normalized )
283+ if not match :
284+ log .info ("Received code snippet url %s which attempted to circumvent url normalisation." , unsanitized )
285+ continue
275286 try :
276287 result = await handler (** match .groupdict ())
277288 except ClientResponseError as error :
You can’t perform that action at this time.
0 commit comments