rspec/rules/S5122/python/rule.adoc

83 lines
1.3 KiB
Plaintext
Raw Normal View History

2020-06-30 12:50:28 +02:00
include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
Django:
2020-06-30 12:50:28 +02:00
----
CORS_ORIGIN_ALLOW_ALL = True # Sensitive
----
Flask:
2020-06-30 12:50:28 +02:00
----
from flask import Flask
from flask_cors import CORS
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*", "send_wildcard": "True"}}) # Sensitive
----
User-controlled origin:
[source,python]
----
origin = request.headers['ORIGIN']
resp = Response()
resp.headers['Access-Control-Allow-Origin'] = origin # Sensitive
----
2020-06-30 12:50:28 +02:00
== Compliant Solution
Django:
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 12:50:28 +02:00
----
CORS_ORIGIN_ALLOW_ALL = False # Compliant
----
Flask:
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 12:50:28 +02:00
----
from flask import Flask
from flask_cors import CORS
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*", "send_wildcard": "False"}}) # Compliant
----
User-controlled origin validated with an allow-list:
[source,python]
----
origin = request.headers['ORIGIN']
resp = Response()
if origin in TRUSTED_ORIGINS:
resp.headers['Access-Control-Allow-Origin'] = origin
----
2020-06-30 12:50:28 +02:00
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]