2020-06-30 12:50:28 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
Flask
|
2020-06-30 14:49:38 +02:00
|
|
|
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
from flask import request, redirect
|
|
|
|
|
|
|
|
@app.route('move')
|
|
|
|
def move():
|
|
|
|
url = request.args["next"]
|
|
|
|
return redirect(url) # Noncompliant
|
|
|
|
----
|
|
|
|
|
|
|
|
Django
|
2020-06-30 14:49:38 +02:00
|
|
|
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
|
|
|
|
def move(request):
|
|
|
|
url = request.GET.get("next", "/")
|
|
|
|
return HttpResponseRedirect(url) # Noncompliant
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
Flask
|
2020-06-30 14:49:38 +02:00
|
|
|
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
from flask import request, redirect, url_for
|
|
|
|
|
|
|
|
@app.route('move')
|
|
|
|
def move():
|
|
|
|
endpoint = request.args["next"]
|
|
|
|
return redirect(url_for(endpoint)) # Compliant
|
|
|
|
----
|
|
|
|
|
|
|
|
Django
|
2020-06-30 14:49:38 +02:00
|
|
|
|
2020-06-30 12:50:28 +02:00
|
|
|
----
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
DOMAINS_WHITELIST = ['www.example.com', 'example.com']
|
|
|
|
|
|
|
|
def move(request):
|
|
|
|
url = request.GET.get("next", "/")
|
|
|
|
parsed_uri = urlparse(url)
|
|
|
|
if parsed_uri.netloc in DOMAINS_WHITELIST:
|
|
|
|
return HttpResponseRedirect(url) # Compliant
|
|
|
|
return HttpResponseRedirect("/")
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2021-09-20 15:38:42 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|