diff --git a/digid_eherkenning/metadata_urls.py b/digid_eherkenning/metadata_urls.py index 6728958..7260716 100644 --- a/digid_eherkenning/metadata_urls.py +++ b/digid_eherkenning/metadata_urls.py @@ -16,6 +16,7 @@ MetadataView.as_view( config_model=DigidConfiguration, metadata_generator=generate_digid_metadata, + filename="digid-metadata.xml", ), name="digid", ), @@ -24,6 +25,7 @@ MetadataView.as_view( config_model=EherkenningConfiguration, metadata_generator=generate_eherkenning_metadata, + filename="eh-metadata.xml", ), name="eherkenning", ), @@ -32,6 +34,7 @@ MetadataView.as_view( config_model=EherkenningConfiguration, metadata_generator=generate_dienst_catalogus_metadata, + filename="dienstcatalogus.xml", ), name="eh-dienstcatalogus", ), diff --git a/digid_eherkenning/saml2/digid.py b/digid_eherkenning/saml2/digid.py index d9c9ce7..6636acb 100644 --- a/digid_eherkenning/saml2/digid.py +++ b/digid_eherkenning/saml2/digid.py @@ -12,7 +12,7 @@ def generate_digid_metadata() -> bytes: client.saml2_setting_kwargs = {"sp_validation_only": True} metadata = client.create_metadata() return ( - b"" + metadata + b'\n' + metadata if not metadata.startswith(b"' + metadata + b'\n' + metadata if not metadata.startswith(b" HttpResponseBase: config = self.config_model.get_solo() @@ -43,7 +44,15 @@ def get(self, request: HttpRequest) -> HttpResponseBase: }, ) return self._get_generic_error_response() - return HttpResponse(metadata, content_type="text/xml") + # RFC 6266, 4.1, and RFC 2616 Section 2.2 + sanitized_filename = self.filename.replace('"', r"\"") + return HttpResponse( + metadata, + content_type="text/xml", + headers={ + "Content-Disposition": f'attachment; filename="{sanitized_filename}"', + }, + ) @staticmethod def _get_generic_error_response() -> HttpResponseBadRequest: