feat(security): default follow_redirects to "safe" for SSRF protection
curl_cffi v0.15.0 introduced CurlFollow.SAFE, which follows redirects but rejects those targeting internal/private IPs (loopback, private networks, link-local). This is now the default for all HTTP fetchers, the MCP server, and the shell curl converter. Added FollowRedirects type alias supporting all curl_cffi redirect modes: bool, "safe", "all", "obeycode", "firstonly".
This commit is contained in:
@@ -8,6 +8,7 @@ from scrapling.core._types import (
|
||||
Optional,
|
||||
SetCookieParam,
|
||||
SelectorWaitStates,
|
||||
FollowRedirects,
|
||||
)
|
||||
|
||||
# Parameter definitions for shell function signatures (defined once at module level)
|
||||
@@ -26,7 +27,7 @@ _REQUESTS_PARAMS = {
|
||||
"headers": Any,
|
||||
"retries": Optional[int],
|
||||
"retry_delay": Optional[int],
|
||||
"follow_redirects": Optional[bool],
|
||||
"follow_redirects": Optional[FollowRedirects],
|
||||
"max_redirects": Optional[int],
|
||||
"verify": Optional[bool],
|
||||
"cert": Optional[str | Tuple[str, str]],
|
||||
|
||||
@@ -40,6 +40,7 @@ SelectorWaitStates = Literal["attached", "detached", "hidden", "visible"]
|
||||
PageLoadStates = Literal["commit", "domcontentloaded", "load", "networkidle"]
|
||||
extraction_types = Literal["text", "html", "markdown"]
|
||||
StrOrBytes = Union[str, bytes]
|
||||
FollowRedirects = Union[bool, Literal["safe", "all", "obeycode", "firstonly"]]
|
||||
|
||||
|
||||
# Copied from `playwright._impl._api_structures.SetCookieParam`
|
||||
|
||||
@@ -27,6 +27,7 @@ from scrapling.core._types import (
|
||||
SetCookieParam,
|
||||
extraction_types,
|
||||
SelectorWaitStates,
|
||||
FollowRedirects,
|
||||
)
|
||||
|
||||
SessionType = Literal["dynamic", "stealthy"]
|
||||
@@ -262,7 +263,7 @@ class ScraplingMCPServer:
|
||||
headers: Optional[Mapping[str, Optional[str]]] = None,
|
||||
cookies: Optional[Dict[str, str]] = None,
|
||||
timeout: Optional[int | float] = 30,
|
||||
follow_redirects: bool = True,
|
||||
follow_redirects: FollowRedirects = "safe",
|
||||
max_redirects: int = 30,
|
||||
retries: Optional[int] = 3,
|
||||
retry_delay: Optional[int] = 1,
|
||||
@@ -289,7 +290,7 @@ class ScraplingMCPServer:
|
||||
:param headers: Headers to include in the request.
|
||||
:param cookies: Cookies to use in the request.
|
||||
:param timeout: Number of seconds to wait before timing out.
|
||||
:param follow_redirects: Whether to follow redirects. Defaults to True.
|
||||
:param follow_redirects: Whether to follow redirects. Defaults to "safe", which follows redirects but rejects those targeting internal/private IPs (SSRF protection). Pass True to follow all redirects without restriction.
|
||||
:param max_redirects: Maximum number of redirects. Default 30, use -1 for unlimited.
|
||||
:param retries: Number of retry attempts. Defaults to 3.
|
||||
:param retry_delay: Number of seconds to wait between retry attempts. Defaults to 1 second.
|
||||
@@ -335,7 +336,7 @@ class ScraplingMCPServer:
|
||||
headers: Optional[Mapping[str, Optional[str]]] = None,
|
||||
cookies: Optional[Dict[str, str]] = None,
|
||||
timeout: Optional[int | float] = 30,
|
||||
follow_redirects: bool = True,
|
||||
follow_redirects: FollowRedirects = "safe",
|
||||
max_redirects: int = 30,
|
||||
retries: Optional[int] = 3,
|
||||
retry_delay: Optional[int] = 1,
|
||||
@@ -362,7 +363,7 @@ class ScraplingMCPServer:
|
||||
:param headers: Headers to include in the request.
|
||||
:param cookies: Cookies to use in the request.
|
||||
:param timeout: Number of seconds to wait before timing out.
|
||||
:param follow_redirects: Whether to follow redirects. Defaults to True.
|
||||
:param follow_redirects: Whether to follow redirects. Defaults to "safe", which follows redirects but rejects those targeting internal/private IPs (SSRF protection). Pass True to follow all redirects without restriction.
|
||||
:param max_redirects: Maximum number of redirects. Default 30, use -1 for unlimited.
|
||||
:param retries: Number of retry attempts. Defaults to 3.
|
||||
:param retry_delay: Number of seconds to wait between retry attempts. Defaults to 1 second.
|
||||
|
||||
@@ -294,7 +294,7 @@ class CurlParser:
|
||||
headers=headers,
|
||||
cookies=cookies,
|
||||
proxy=proxies,
|
||||
follow_redirects=True, # Scrapling default is True
|
||||
follow_redirects="safe", # Follows redirects but rejects those to internal/private IPs
|
||||
)
|
||||
|
||||
def convert2fetcher(self, curl_command: Request | str) -> Optional[Response]:
|
||||
|
||||
Reference in New Issue
Block a user