Skip to content

Commit

Permalink
[py-tx] Validate hash length (#1618)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryzle authored Sep 17, 2024
1 parent 48cedb9 commit e9d0fd0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import dacite
import requests
from requests.packages.urllib3.util.retry import Retry
from urllib3.util.retry import Retry
from threatexchange.exchanges.clients.utils.common import TimeoutHTTPAdapter


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
@see SignalExchangeAPI
"""

import logging

from abc import ABC, abstractmethod
import typing as t

Expand Down Expand Up @@ -332,6 +334,15 @@ def naive_convert_to_signal_type(
s_type = type_by_name.get(type_str)
if s_type is None or metadata is None:
continue
try:
s_type.validate_signal_str(signal_str)
except ValueError:
logging.warning(
"Invalid fingerprint (%s): %s",
s_type.get_name(),
signal_str if len(signal_str) < 100 else signal_str[:100] + "...",
)
continue
inner = ret.get(s_type)
if inner is None:
inner = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ def get_examples() -> t.List[str]:
"c186f9619659658c4b6916daf934496985f4259c72c39676ab9edb631c3c349c",
# Github octocat - https://github.com/logos
"62c9789627838f69f23cf98c29e37836d61c87c31c59587c4b49a783f496725c",
# https://github.com/facebook/ThreatExchange/issues/1609 - bad entry
# "00000000000000000000000000000000",
]

0 comments on commit e9d0fd0

Please sign in to comment.