Skip to content

Commit

Permalink
Sanitize artifact paths before downloading
Browse files Browse the repository at this point in the history
This can maybe replaced if pulp/pulpcore#2950 is solved.

closes #571

(cherry picked from commit ccf3f47)
  • Loading branch information
hstct authored and quba42 committed Jul 12, 2022
1 parent 7856886 commit ff3bc6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/571.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed handling of download URLs containing special characters in the path part.
8 changes: 4 additions & 4 deletions pulp_deb/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections import defaultdict
from tempfile import NamedTemporaryFile
from debian import deb822
from urllib.parse import urlparse, urlunparse
from urllib.parse import quote, urlparse, urlunparse
from django.conf import settings
from django.db.utils import IntegrityError

Expand Down Expand Up @@ -520,7 +520,7 @@ async def _create_unit(self, d_content):

def _to_d_artifact(self, relative_path, data=None):
artifact = Artifact(**_get_checksums(data or {}))
url_path = os.path.join(self.parsed_url.path, relative_path)
url_path = quote(os.path.join(self.parsed_url.path, relative_path), safe=":/")
return DeclarativeFailsafeArtifact(
artifact,
urlunparse(self.parsed_url._replace(path=url_path)),
Expand Down Expand Up @@ -857,7 +857,7 @@ async def _handle_package_index(
sha256=package_sha256,
**serializer.validated_data,
)
package_path = os.path.join(self.parsed_url.path, package_relpath)
package_path = quote(os.path.join(self.parsed_url.path, package_relpath), safe=":/")
package_da = DeclarativeArtifact(
artifact=Artifact(
size=int(package_paragraph["Size"]), **_get_checksums(package_paragraph)
Expand Down Expand Up @@ -977,7 +977,7 @@ async def _handle_installer_file_index(

for filename, digests in file_list.items():
relpath = os.path.join(installer_file_index.relative_path, filename)
urlpath = os.path.join(self.parsed_url.path, relpath)
urlpath = quote(os.path.join(self.parsed_url.path, relpath), safe=":/")
content_unit = GenericContent(sha256=digests["sha256"], relative_path=relpath)
d_artifact = DeclarativeArtifact(
artifact=Artifact(**digests),
Expand Down

0 comments on commit ff3bc6b

Please sign in to comment.