Skip to content

Commit afe276a

Browse files
committed
Catch 500 error for external request
Move them to 400 and log internally
1 parent 91f5ec3 commit afe276a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

changes/9201.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not respond with a 500 error to external requests

ckan/views/util.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# encoding: utf-8
22

3+
import logging
34
from flask import Blueprint
5+
from werkzeug.routing import BuildError as FlaskRouteBuildError
46

57
import ckan.lib.base as base
68
from ckan.lib.helpers import helper_functions as h
79
from ckan.common import _, request
810
from ckan.types import Response
911

12+
13+
log = logging.getLogger(__name__)
1014
util = Blueprint(u'util', __name__)
1115

1216

@@ -20,7 +24,13 @@ def internal_redirect() -> Response:
2024

2125
url = url.replace('\r', ' ').replace('\n', ' ').replace('\0', ' ')
2226
if h.url_is_local(url):
23-
return h.redirect_to(url)
27+
try:
28+
response = h.redirect_to(url)
29+
except FlaskRouteBuildError:
30+
log.error(f'Error building redirect URL: {url}')
31+
base.abort(400, _('Invalid URL'))
32+
return response
33+
2434
else:
2535
base.abort(403, _(u'Redirecting to external site is not allowed.'))
2636

0 commit comments

Comments
 (0)