Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LSDV-5337: Pre-signed file proxy url clashing with already html encoded values causing errors in signature #4447

Merged
merged 7 commits into from
Jun 29, 2023
Next Next commit
fix: LSDV-5337: Pre-signed file proxy url clashing with already html …
…encoded values causing errors in signature
  • Loading branch information
bmartel committed Jun 26, 2023
commit f3b1424142e08204b62e1eedc16229ce9f4ac005
3 changes: 2 additions & 1 deletion label_studio/data_import/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
"""
import base64
import time
import requests
import logging
Expand Down Expand Up @@ -602,7 +603,7 @@ def get(self, request, *args, **kwargs):
if not project.has_permission(request.user):
return Response(status=status.HTTP_403_FORBIDDEN)

fileuri = unquote(fileuri)
fileuri = base64.urlsafe_b64decode(fileuri.encode()).decode()

try:
resolved = task.resolve_storage_uri(fileuri, project)
Expand Down
5 changes: 3 additions & 2 deletions label_studio/io_storages/base_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
"""
import base64
import rq
import json
import logging
Expand All @@ -9,7 +10,7 @@

from rq.job import Job
from django_rq import job
from urllib.parse import urljoin, quote
from urllib.parse import urljoin, quote, unquote

from django.utils import timezone
from django.db import models, transaction
Expand Down Expand Up @@ -285,7 +286,7 @@ def resolve_uri(self, uri, task=None):
reverse(
"data_import:storage-data-presign",
kwargs={"task_id": task.id}
) + f'?fileuri={quote(extracted_uri)}'
) + f"?fileuri={base64.urlsafe_b64encode(extracted_uri.encode()).decode()}"
)
return uri.replace(extracted_uri, proxy_url)
else:
Expand Down
Loading