Skip to content

Commit

Permalink
Merge pull request #4 from jathanism/api_xsrf
Browse files Browse the repository at this point in the history
Add setting to toggle for checking XSRF cookies on API calls.
  • Loading branch information
gmjosack committed Jan 20, 2015
2 parents c670276 + bdf3de8 commit d51c77f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ nosetests.xml
.pydevproject

docs/_build
.*sw?
4 changes: 4 additions & 0 deletions config/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ cdnjs_prefix: "//cdnjs.cloudflare.com"
# specified in CIDR notation.
# Type: str or list
restrict_networks: "127.0.0.1"

# Specifies whether to use XSRF headers/cookies for API calls. Default: true
# Type: bool
api_xsrf_enabled: false
6 changes: 5 additions & 1 deletion nsot/handlers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def write_error(self, status_code, **kwargs):
self.render("error.html", code=status_code, message=message)



class ApiHandler(BaseHandler):
def initialize(self):
BaseHandler.initialize(self)
Expand All @@ -102,6 +101,11 @@ def jbody(self):
self._jbody = {}
return self._jbody

def check_xsrf_cookie(self):
"""Optionally check XSRF cookies on API calls."""
if settings.api_xsrf_enabled:
super(ApiHandler, self).check_xsrf_cookie()

def get_pagination_values(self, max_limit=None):
offset = int(self.get_argument("offset", 0))
limit = self.get_argument("limit", None)
Expand Down
1 change: 1 addition & 0 deletions nsot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ def override_restrict_networks(self, values):
"cdnjs_prefix": "//cdnjs.cloudflare.com",
"restrict_networks": [],
"bind_address": None,
"api_xsrf_enabled": True,
})
2 changes: 1 addition & 1 deletion nsot/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "0.0.2"

0 comments on commit d51c77f

Please sign in to comment.