myagent-ai 1.20.6 → 1.20.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/web_control.py +12 -10
- package/package.json +1 -1
package/core/web_control.py
CHANGED
|
@@ -601,13 +601,16 @@ class WebControlManager:
|
|
|
601
601
|
# 仅改写 HTML 属性中的 URL (不影响内联脚本)
|
|
602
602
|
def rewrite_attr(match):
|
|
603
603
|
attr_name = match.group(1).lower()
|
|
604
|
-
|
|
605
|
-
|
|
604
|
+
eq = match.group(2) # "=" (可能带空格)
|
|
605
|
+
q_open = match.group(3) # 开引号 " 或 '
|
|
606
|
+
url_val = match.group(4) # URL 值
|
|
607
|
+
q_close = match.group(5) # 闭引号 (同 q_open)
|
|
606
608
|
|
|
607
|
-
|
|
609
|
+
# 跳过特殊协议
|
|
610
|
+
if not url_val or url_val.startswith('data:') or url_val.startswith('blob:') or url_val.startswith('#') or url_val.startswith('javascript:') or url_val.startswith('mailto:') or url_val.startswith('tel:'):
|
|
608
611
|
return match.group(0)
|
|
609
612
|
|
|
610
|
-
# 已经是代理 URL
|
|
613
|
+
# 已经是代理 URL — 跳过
|
|
611
614
|
if '/api/web_control/proxy' in url_val:
|
|
612
615
|
return match.group(0)
|
|
613
616
|
|
|
@@ -619,23 +622,22 @@ class WebControlManager:
|
|
|
619
622
|
elif not url_val.startswith('http://') and not url_val.startswith('https://'):
|
|
620
623
|
url_val = urljoin(original_url, url_val)
|
|
621
624
|
|
|
622
|
-
# 非同源资源:
|
|
625
|
+
# 非同源资源: CDN 图片/脚本/样式直接访问, 不走代理
|
|
623
626
|
url_parsed = urlparse(url_val)
|
|
624
627
|
if url_parsed.netloc and url_parsed.netloc != parsed.netloc:
|
|
625
|
-
# 对于 src 属性的资源 (图片/脚本/样式/字体), 直接访问即可
|
|
626
628
|
if attr_name in ('src', 'data-src', 'data-original'):
|
|
627
629
|
return match.group(0)
|
|
628
|
-
|
|
629
|
-
if attr_name == 'href' and any(url_val.endswith(ext) for ext in ('.css', '.woff', '.woff2', '.ttf', '.eot', '.svg')):
|
|
630
|
+
if attr_name == 'href' and any(url_val.lower().endswith(ext) for ext in ('.css', '.woff', '.woff2', '.ttf', '.eot', '.svg', '.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico')):
|
|
630
631
|
return match.group(0)
|
|
631
632
|
# 其他外链 (导航链接) 走代理
|
|
632
633
|
if attr_name == 'href':
|
|
633
|
-
return f'{attr_name}
|
|
634
|
+
return f'{attr_name}{eq}{q_open}{proxy_base}{url_quote(url_val)}{q_close}'
|
|
634
635
|
|
|
635
636
|
# 同源资源走代理
|
|
636
|
-
return f'{attr_name}
|
|
637
|
+
return f'{attr_name}{eq}{q_open}{proxy_base}{url_quote(url_val)}{q_close}'
|
|
637
638
|
|
|
638
639
|
# 匹配常见 URL 属性
|
|
640
|
+
# group1=属性名, group2="=", group3=开引号, group4=URL值, group5=闭引号
|
|
639
641
|
url_pattern = re.compile(
|
|
640
642
|
r'((?:src|href|action|data-src|data-original|poster|formaction|content|cite|background))'
|
|
641
643
|
r'(\s*=\s*)'
|