Skip to content

Commit cefcadf

Browse files
QYuFongQiuYuFong
andauthored
Add ssl verification and ban 0.0.0.0 sever ip (#1180)
Co-authored-by: qiuyufeng <[email protected]>
1 parent 27b9ce5 commit cefcadf

File tree

14 files changed

+84
-60
lines changed

14 files changed

+84
-60
lines changed

examples/moviegen/tools/download_convert_st.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
from safetensors.torch import _find_shared_tensors, _is_complete, load_file, save_file
1515

1616

17-
def backend_factory() -> requests.Session:
18-
session = requests.Session()
19-
session.verify = False
20-
return session
21-
22-
2317
def _remove_duplicate_names(
2418
state_dict: Dict[str, torch.Tensor],
2519
*,
@@ -332,6 +326,18 @@ def convert(
332326

333327
args = parser.parse_args()
334328
if args.disable_ssl_verify:
329+
print(
330+
"Warning: The --disable-ssl-verify flag is deprecated and has no effect. "
331+
"SSL verification is enforced for security reasons."
332+
)
333+
334+
def backend_factory() -> requests.Session:
335+
session = requests.Session()
336+
# For security reasons, this repository code does not provide a function to disable SSL.
337+
# If necessary, please disable SSL verification yourself.
338+
# session.verify = False
339+
return session
340+
335341
configure_http_backend(backend_factory=backend_factory)
336342

337343
path = convert(

examples/opensora_hpcai/tools/download_convert_st.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
from safetensors.torch import _find_shared_tensors, _is_complete, load_file, save_file
1515

1616

17-
def backend_factory() -> requests.Session:
18-
session = requests.Session()
19-
session.verify = False
20-
return session
21-
22-
2317
def _remove_duplicate_names(
2418
state_dict: Dict[str, torch.Tensor],
2519
*,
@@ -332,6 +326,18 @@ def convert(
332326

333327
args = parser.parse_args()
334328
if args.disable_ssl_verify:
329+
print(
330+
"Warning: The --disable-ssl-verify flag is deprecated and has no effect. "
331+
"SSL verification is enforced for security reasons."
332+
)
333+
334+
def backend_factory() -> requests.Session:
335+
session = requests.Session()
336+
# For security reasons, this repository code does not provide a function to disable SSL.
337+
# If necessary, please disable SSL verification yourself.
338+
# session.verify = False
339+
return session
340+
335341
configure_http_backend(backend_factory=backend_factory)
336342

337343
path = convert(

examples/pixart_sigma/gradio_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def main():
348348
)
349349

350350
# Launch the web interface
351-
demo.launch(server_name="0.0.0.0", server_port=args.port)
351+
demo.launch(server_name="127.0.0.1", server_port=args.port)
352352

353353

354354
if __name__ == "__main__":

examples/stable_diffusion_v2/tools/eval/fid/utils.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,11 @@ def extract_archive(self, from_path: str, to_path: str = None) -> str:
187187
def download_file(self, url: str, file_path: str, chunk_size: int = 1024):
188188
"""Download a file."""
189189

190-
# no check certificate
190+
# For security reasons, this repository code does not provide a function to disable SSL.
191+
# If necessary, please disable SSL verification yourself.
191192
ctx = ssl.create_default_context()
192-
ctx.check_hostname = False
193-
ctx.verify_mode = ssl.CERT_NONE
193+
# ctx.check_hostname = False
194+
# ctx.verify_mode = ssl.CERT_NONE
194195

195196
# Define request headers.
196197
headers = {"User-Agent": self.USER_AGENT}
@@ -230,20 +231,22 @@ def download_url(
230231
return file_path
231232

232233
# Download the file.
234+
# For security reasons, this repository code does not provide a function to disable SSL.
235+
# If necessary, please disable SSL verification yourself.
233236
try:
234237
self.download_file(url, file_path)
235238
except (urllib.error.URLError, IOError) as e:
236-
if url.startswith("https"):
237-
url = url.replace("https", "http")
238-
try:
239-
self.download_file(url, file_path)
240-
except (urllib.error.URLError, IOError):
241-
# pylint: disable=protected-access
242-
ssl._create_default_https_context = ssl._create_unverified_context
243-
self.download_file(url, file_path)
244-
ssl._create_default_https_context = ssl.create_default_context
245-
else:
246-
raise e
239+
# if url.startswith("https"):
240+
# url = url.replace("https", "http")
241+
# try:
242+
# self.download_file(url, file_path)
243+
# except (urllib.error.URLError, IOError):
244+
# # pylint: disable=protected-access
245+
# ssl._create_default_https_context = ssl._create_unverified_context
246+
# self.download_file(url, file_path)
247+
# ssl._create_default_https_context = ssl.create_default_context
248+
# else:
249+
raise e
247250

248251
return file_path
249252

examples/stable_diffusion_v2/tools/safety_checker/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ def locate_model(model_name="nsfw", backend="ms"):
6161
file_name = url.split("/")[-1]
6262
file_path = os.path.join(path, file_name)
6363

64-
# no check certificate
64+
# For security reasons, this repository code does not provide a function to disable SSL.
65+
# If necessary, please disable SSL verification yourself.
6566
ctx = ssl.create_default_context()
66-
ctx.check_hostname = False
67-
ctx.verify_mode = ssl.CERT_NONE
67+
# ctx.check_hostname = False
68+
# ctx.verify_mode = ssl.CERT_NONE
6869

6970
# Define request headers.
7071
headers = {

examples/stable_diffusion_v2/utils/download.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ def extract_archive(self, from_path: str, to_path: str = None) -> str:
135135
def download_file(self, url: str, file_path: str, chunk_size: int = 1024):
136136
"""Download a file."""
137137

138-
# no check certificate
138+
# For security reasons, this repository code does not provide a function to disable SSL.
139+
# If necessary, please disable SSL verification yourself.
139140
ctx = ssl.create_default_context()
140-
ctx.check_hostname = False
141-
ctx.verify_mode = ssl.CERT_NONE
141+
# ctx.check_hostname = False
142+
# ctx.verify_mode = ssl.CERT_NONE
142143

143144
# Define request headers.
144145
headers = {"User-Agent": self.USER_AGENT}

examples/step_video_t2v/api/call_remote_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def __init__(self, args) -> None:
207207
resource_class_args=[self.caption_pipeline],
208208
)
209209

210-
def run(self, host="0.0.0.0", port=8080):
210+
def run(self, host="127.0.0.1", port=8080):
211211
if self.enable_vae:
212212
port = 5001
213213
print(f"enable vae, port setting to {port}")
@@ -233,4 +233,4 @@ def run(self, host="0.0.0.0", port=8080):
233233
)
234234

235235
flask_server = RemoteServer(args)
236-
flask_server.run(host="0.0.0.0", port=args.port)
236+
flask_server.run(host="127.0.0.1", port=args.port)

examples/story_diffusion/gradio_app_sdxl_specific_id_low_vram.py.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,4 +1288,4 @@ def array2string(arr):
12881288
gr.Markdown(article)
12891289

12901290

1291-
demo.launch(server_name="0.0.0.0", share=True)
1291+
demo.launch(server_name="127.0.0.1", share=True)

examples/t2v_turbo/utils/download.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ def extract_archive(self, from_path: str, to_path: str = None) -> str:
135135
def download_file(self, url: str, file_path: str, chunk_size: int = 1024):
136136
"""Download a file."""
137137

138-
# no check certificate
138+
# For security reasons, this repository code does not provide a function to disable SSL.
139+
# If necessary, please disable SSL verification yourself.
139140
ctx = ssl.create_default_context()
140-
ctx.check_hostname = False
141-
ctx.verify_mode = ssl.CERT_NONE
141+
# ctx.check_hostname = False
142+
# ctx.verify_mode = ssl.CERT_NONE
142143

143144
# Define request headers.
144145
headers = {"User-Agent": self.USER_AGENT}
@@ -178,20 +179,22 @@ def download_url(
178179
return file_path
179180

180181
# Download the file.
182+
# For security reasons, this repository code does not provide a function to disable SSL.
183+
# If necessary, please disable SSL verification yourself.
181184
try:
182185
self.download_file(url, file_path)
183186
except (urllib.error.URLError, IOError) as e:
184-
if url.startswith("https"):
185-
url = url.replace("https", "http")
186-
try:
187-
self.download_file(url, file_path)
188-
except (urllib.error.URLError, IOError):
189-
# pylint: disable=protected-access
190-
ssl._create_default_https_context = ssl._create_unverified_context
191-
self.download_file(url, file_path)
192-
ssl._create_default_https_context = ssl.create_default_context
193-
else:
194-
raise e
187+
# if url.startswith("https"):
188+
# url = url.replace("https", "http")
189+
# try:
190+
# self.download_file(url, file_path)
191+
# except (urllib.error.URLError, IOError):
192+
# # pylint: disable=protected-access
193+
# ssl._create_default_https_context = ssl._create_unverified_context
194+
# self.download_file(url, file_path)
195+
# ssl._create_default_https_context = ssl.create_default_context
196+
# else:
197+
raise e
195198

196199
return file_path
197200

examples/transformers/kimi_vl/generate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import ssl
32
import urllib.request
43

54
from kimi_vl import KimiVLConfig, KimiVLForConditionalGeneration
@@ -31,7 +30,9 @@ def main():
3130

3231
image_path = "demo.png"
3332
if not os.path.isfile(image_path):
34-
ssl._create_default_https_context = ssl._create_unverified_context # disable ssl verify
33+
# For security reasons, this repository code does not provide a function to disable SSL.
34+
# If necessary, please disable SSL verification yourself.
35+
# ssl._create_default_https_context = ssl._create_unverified_context # disable ssl verify
3536
urllib.request.urlretrieve(
3637
"https://huggingface.co/moonshotai/Kimi-VL-A3B-Instruct/resolve/main/figures/demo.png", image_path
3738
)

0 commit comments

Comments
 (0)