Skip to content

Commit fdaad81

Browse files
committed
HOTFIX: Fix and OpenRedirect vulnerability
1 parent a9de033 commit fdaad81

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

mobsf/MobSF/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
logger = logging.getLogger(__name__)
1212

13-
VERSION = '4.0.4'
13+
VERSION = '4.0.5'
1414
BANNER = """
1515
__ __ _ ____ _____ _ _ ___
1616
| \/ | ___ | |__/ ___|| ___|_ _| || | / _ \

mobsf/MobSF/security.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,13 @@ def wrap_function(oldfunction, newfunction):
195195
def run(*args, **kwargs):
196196
return newfunction(oldfunction, *args, **kwargs)
197197
return run
198+
199+
200+
def sanitize_redirect(url):
201+
"""Sanitize Redirect URL."""
202+
root = '/'
203+
if url.startswith('//'):
204+
return root
205+
elif url.startswith('/'):
206+
return url
207+
return root

mobsf/MobSF/views/authentication.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
from django.contrib import messages
1919
from django.contrib.auth.decorators import login_required as lg
2020

21+
from mobsf.MobSF.security import (
22+
sanitize_redirect,
23+
)
24+
2125
from brake.decorators import ratelimit
2226

2327

@@ -57,7 +61,7 @@ def login_view(request):
5761
else:
5862
allow_pwd = False
5963
nextp = request.GET.get('next', '')
60-
redirect_url = nextp if nextp.startswith('/') else '/'
64+
redirect_url = sanitize_redirect(nextp)
6165
if request.user.is_authenticated:
6266
return redirect(redirect_url)
6367
if request.method == 'POST':

mobsf/MobSF/views/saml2.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
from mobsf.MobSF.utils import (
2727
print_n_send_error_response,
2828
)
29+
from mobsf.MobSF.security import (
30+
sanitize_redirect,
31+
)
2932

3033
logger = logging.getLogger(__name__)
3134
ASSERTION_IDS = set()
@@ -117,8 +120,8 @@ def get_redirect_url(req):
117120
return redirect_url
118121
relay_state = req['post_data']['RelayState']
119122
# Allow only relative URLs
120-
if (relay_state and relay_state.startswith('/')):
121-
redirect_url = relay_state
123+
if relay_state:
124+
redirect_url = sanitize_redirect(relay_state)
122125
return redirect_url
123126

124127

@@ -139,7 +142,7 @@ def saml_login(request):
139142
req = prepare_django_request(request)
140143
auth = init_saml_auth(req)
141144
nextp = request.GET.get('next', '')
142-
redirect_url = nextp if nextp.startswith('/') else '/'
145+
redirect_url = sanitize_redirect(nextp)
143146
return redirect(auth.login(return_to=redirect_url))
144147
except Exception as exp:
145148
return print_n_send_error_response(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "mobsf"
3-
version = "4.0.4"
3+
version = "4.0.5"
44
description = "Mobile Security Framework (MobSF) is an automated, all-in-one mobile application (Android/iOS/Windows) pen-testing, malware analysis and security assessment framework capable of performing static and dynamic analysis."
55
keywords = ["mobsf", "mobile security framework", "mobile security", "security tool", "static analysis", "dynamic analysis", "malware analysis"]
66
authors = ["Ajin Abraham <[email protected]>"]

0 commit comments

Comments
 (0)