Skip to content

Commit

Permalink
for now whitelist citations to only the DRKZ server (#474)
Browse files Browse the repository at this point in the history
* for now whitelist citations to only the DRKZ server

* fix isort, test code

* fix assert
  • Loading branch information
sashakames committed Sep 23, 2022
1 parent dd2f7c2 commit 8bb7aa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/metagrid/api_proxy/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ def test_citation(self):

response = self.client.post(url, jo, format="json")
assert response.status_code == status.HTTP_200_OK

jo = {
"citurl": "https://aims4.llnl.gov/WDCC/meta/CMIP6/CMIP6.CMIP.IPSL.IPSL-CM6A-LR.abrupt-4xCO2.r12i1p1f1.Amon.n2oglobal.gr.v20191003.json"
}

response = self.client.post(url, jo, format="json")
assert response.status_code != status.HTTP_200_OK
7 changes: 7 additions & 0 deletions backend/metagrid/api_proxy/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from urllib.parse import urlparse

import requests
from django.http import HttpResponse, HttpResponseBadRequest
Expand Down Expand Up @@ -27,6 +28,12 @@ def do_citation(request):
return HttpResponseBadRequest()

url = jo["citurl"]

parsed_url = urlparse(url)

if not parsed_url.hostname == "cera-www.dkrz.de":
return HttpResponseBadRequest()

try:
resp = requests.get(url)
except Exception: # pragma: no cover
Expand Down

0 comments on commit 8bb7aa9

Please sign in to comment.