Skip to content

Commit d2b0f9f

Browse files
committed
jwt issue example: require input data, lowercase roles
If content-type is not supplied, input data will not be parsed. As a result the JWT has the user's assigned roles. Prevent this. Also lowercase all roles supplied in the input payload so "User", "user" and "useR" all match the case insensitive "user" role.
1 parent 5b67ace commit d2b0f9f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/rest.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,8 @@ only been tested with python3)::
18571857
@Routing.route("/jwt/issue", 'POST')
18581858
@_data_decorator
18591859
def generate_jwt(self, input):
1860+
"""Create a JSON Web Token (jwt)
1861+
"""
18601862
import jwt
18611863
import datetime
18621864
from roundup.anypy.strings import b2s
@@ -1879,6 +1881,11 @@ only been tested with python3)::
18791881
else:
18801882
raise Unauthorised(denialmsg)
18811883

1884+
# verify we have input data.
1885+
if not input:
1886+
raise UsageError("Missing data payload. "
1887+
"Verify Content-Type is sent")
1888+
18821889
# If we reach this point we have validated that the user has
18831890
# logged in with a password using basic auth.
18841891
all_roles = list(self.db.security.role.items())
@@ -1910,7 +1917,7 @@ only been tested with python3)::
19101917

19111918
newroles = []
19121919
if 'roles' in input:
1913-
for role in input['roles'].value:
1920+
for role in [ r.lower() for r in input['roles'].value ]:
19141921
if role not in rolenames:
19151922
raise UsageError("Role %s is not valid."%role)
19161923
if role in user_roles:

0 commit comments

Comments
 (0)