mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
fix/adjust web search to properly block domains (#19670)
Co-authored-by: Tim Baek <tim@openwebui.com>
This commit is contained in:
parent
562f22960c
commit
6e531679f4
2 changed files with 11 additions and 7 deletions
|
|
@ -33,7 +33,7 @@ def get_filtered_results(results, filter_list):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if any(is_string_allowed(hostname, filter_list) for hostname in hostnames):
|
if is_string_allowed(hostnames, filter_list):
|
||||||
filtered_results.append(result)
|
filtered_results.append(result)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import uuid
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional, Sequence, Union
|
||||||
import json
|
import json
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
|
@ -43,25 +43,29 @@ def get_allow_block_lists(filter_list):
|
||||||
return allow_list, block_list
|
return allow_list, block_list
|
||||||
|
|
||||||
|
|
||||||
def is_string_allowed(string: str, filter_list: Optional[list[str]] = None) -> bool:
|
def is_string_allowed(
|
||||||
|
string: Union[str, Sequence[str]], filter_list: Optional[list[str]] = None
|
||||||
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Checks if a string is allowed based on the provided filter list.
|
Checks if a string is allowed based on the provided filter list.
|
||||||
:param string: The string to check (e.g., domain or hostname).
|
:param string: The string or sequence of strings to check (e.g., domain or hostname).
|
||||||
:param filter_list: List of allowed/blocked strings. Strings starting with "!" are blocked.
|
:param filter_list: List of allowed/blocked strings. Strings starting with "!" are blocked.
|
||||||
:return: True if the string is allowed, False otherwise.
|
:return: True if the string or sequence of strings is allowed, False otherwise.
|
||||||
"""
|
"""
|
||||||
if not filter_list:
|
if not filter_list:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
allow_list, block_list = get_allow_block_lists(filter_list)
|
allow_list, block_list = get_allow_block_lists(filter_list)
|
||||||
|
print(string, allow_list, block_list)
|
||||||
|
strings = [string] if isinstance(string, str) else list(string)
|
||||||
|
|
||||||
# If allow list is non-empty, require domain to match one of them
|
# If allow list is non-empty, require domain to match one of them
|
||||||
if allow_list:
|
if allow_list:
|
||||||
if not any(string.endswith(allowed) for allowed in allow_list):
|
if not any(s.endswith(allowed) for s in strings for allowed in allow_list):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Block list always removes matches
|
# Block list always removes matches
|
||||||
if any(string.endswith(blocked) for blocked in block_list):
|
if any(s.endswith(blocked) for s in strings for blocked in block_list):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue