hardbyte / hardbyte/python-can

A ReDoS vulnerability exists in ./can/util.py

Aberta
#1,507 2 comentários 0 reações 0 responsáveis Ver no GitHub
bug
Linguagem predominante
Python
Estrelas
1.6k
Forks
697
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

The affected code is located in [util.py-line292](https://github.com/hardbyte/python-can/blob/5c523ec9cc5ab3badbb6def6fb3750d228c7c7c0/can/util.py#L292). It uses the vulnerable regular expression `.*?(\d+)$`. When the match fails, it will cause catastrophic backtracking.
I trigger the vulnerability using the python script below

```python
import asyncio
from typing import List

import can
from can.notifier import MessageRecipient

def print_message(msg: can.Message) -> None:
"""Regular callback function. Can also be a coroutine."""
print(msg)

async def main() -> None:
"""The main function that runs in the loop."""

with can.Bus(
interface="virtual", channel='0'*300000 + '\n0',receive_own_messages=True
) as bus:
reader = can.AsyncBufferedReader()
logger = can.Logger("logfile.asc")

listeners: List[MessageRecipient] = [
print_message, # Callback function
reader, # AsyncBufferedReader() listener
logger, # Regular Listener object
]
# Create Notifier with an explicit loop to use for scheduling of callbacks
loop = asyncio.get_running_loop()
notifier = can.Notifier(bus, listeners, loop=loop)
# Start sending first message
bus.send(can.Message(arbitration_id=0))

print("Bouncing 10 messages...")
for _ in range(10):
# Wait for next message from AsyncBufferedReader
msg = await reader.get_message()
# Delay response
await asyncio.sleep(0.5)
msg.arbitration_id += 1
bus.send(msg)

# Wait for last message to arrive
await reader.get_message()
print("Done!")

# Clean-up
notifier.stop()

if __name__ == "__main__":
asyncio.run(main())
```

I know this is usually used client side,but when run server side there has possible DOS. It is my pleasure to provide a patch to repair the ReDoS vulnerability.

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Comece na linha 292 de can/util.py e inspecione como a expressão regular .*?(\d+)$ processa o valor de channel. Use a reprodução fornecida de asyncio com o channel longo e malformado para confirmar o modo de falha e, em seguida, verifique se a vulnerabilidade não é mais acionada e se o parsing existente de channel continua funcionando.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
security
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.