Files
ServerKit/backend/tests/test_git_webhook_token.py
Juan Denis 752fb83919 Compare legacy deploy webhook tokens safely
The token was compared with != (timing leak), and an app with no
webhook_token accepted a request that sent none, since None != None is
false. Require both tokens and use hmac.compare_digest.
2026-10-10 09:32:03 -04:00

21 lines
694 B
Python

"""The legacy deploy webhook token must match exactly, in constant time,
and a missing token must never match a missing token."""
import pytest
from app.services.git_service import GitService
@pytest.mark.parametrize('configured,sent,ok', [
('tok-123', 'tok-123', True),
('tok-123', 'tok-124', False),
('tok-123', '', False),
('tok-123', None, False),
(None, None, False),
('', '', False),
(None, '', False),
])
def test_token_check(monkeypatch, configured, sent, ok):
monkeypatch.setattr(GitService, 'get_app_config',
classmethod(lambda cls, app_id: {'webhook_token': configured}))
assert GitService.verify_webhook(1, sent) is ok