This repository was archived by the owner on Apr 30, 2024. It is now read-only.
File tree 4 files changed +34
-3
lines changed
4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
#
16
+
17
+ import logging
18
+
19
+ import webapp2
20
+
21
+
22
+ def csrf_check (request ):
23
+ """
24
+ Throws an HTTP 403 error if a CSRF attack is detected, same logic as the deferred module.
25
+
26
+ https://cloud.google.com/appengine/docs/standard/python/refdocs/modules/google/appengine/ext/deferred/deferred
27
+ """
28
+ in_prod = (
29
+ not request .environ .get ("SERVER_SOFTWARE" ).startswith ("Devel" ))
30
+ if in_prod and request .environ .get ("REMOTE_ADDR" ) != "0.1.0.2" :
31
+ logging .error ("Detected an attempted CSRF attack from {}. This request did "
32
+ "not originate from Task Queue." .format (request .environ .get ("REMOTE_ADDR" )))
33
+ webapp2 .abort (403 )
Original file line number Diff line number Diff line change 1
- version_info = (1 , 6 , 3 )
1
+ version_info = (1 , 6 , 4 )
2
2
version = '.' .join (map (str , version_info ))
Original file line number Diff line number Diff line change @@ -71,6 +71,15 @@ def get_completion_cleanup_delay():
71
71
return config .get ('cleanupdelay' )
72
72
73
73
74
+ def get_csrf_check ():
75
+ """Get the CSRF check function, which takes one arg (webapp2.Reqeust)
76
+ and returns None, throwing an exception if a CSRF attack is detected.
77
+ """
78
+ from furious .job_utils import path_to_reference
79
+
80
+ return path_to_reference (get_config ().get ('csrf_check' ))
81
+
82
+
74
83
def _get_configured_module (option_name , known_modules = None ):
75
84
"""Get the module specified by the value of option_name. The value of the
76
85
configuration option will be used to load the module by name from the known
@@ -155,7 +164,8 @@ def default_config():
155
164
'cleanupqueue' : 'default' ,
156
165
'cleanupdelay' : 7600 ,
157
166
'defaultqueue' : 'default' ,
158
- 'task_system' : 'appengine_taskqueue' }
167
+ 'task_system' : 'appengine_taskqueue' ,
168
+ 'csrf_check' : 'furious.csrf_check' }
159
169
160
170
161
171
def _load_yaml_config (path = None ):
Original file line number Diff line number Diff line change 17
17
18
18
from furious .handlers import process_async_task
19
19
from furious .errors import AbortAndRestart
20
-
20
+ from furious . config import get_csrf_check
21
21
22
22
class AsyncJobHandler (webapp2 .RequestHandler ):
23
23
"""Handles requests for the webapp framework."""
@@ -29,6 +29,9 @@ def post(self):
29
29
30
30
def _handle_task (self ):
31
31
"""Pass request info to the async framework."""
32
+ # Check for CSRF
33
+ get_csrf_check ()(self .request )
34
+
32
35
headers = self .request .headers
33
36
34
37
message = None
You can’t perform that action at this time.
0 commit comments