You are on page 1of 6

Json Web Token: the new invention for the user

authentication and authorization mechanism

ALEXANDRU TRIFU
IT&C Security Master
Department of Economic Informatics and Cybernetics
The Bucharest University of Economic Studies
Calea Dorobanti, no. 15-17, Sector 1,
Bucharest, 010552
ROMANIA
alexandru.trifu7@gmail.com

Abstract: In recent years, the development of web based applications increased significantly.
Because of this high demand for developing web applications, a lot of security leaks appeared,
mostly of these targeting the mechanism for access management. In this world of Internet, there are
many ways to secure the authentication process and one of the most popular standard used is called
Json Web Token (JWT). These methods for authentication and authorization prevent unauthorized
users from accessing data from a specific application. Since everybody wants to have a secured
process for authentication and authorization of users within an application, in this paper, we are
aiming to evaluate the integration of JWT with a web based application. This study shows the way of
granting permissions authorities between two parties since Json Web Token can provide default and
custom claims for this approach. By using this method, we concluded that the confidence level is
significantly increased when we are talking about authentication security and manageability. We will
discover how it is to have a powerful authentication mechanism using JWT and in addition we’ll see
what are the advantages and disadvantages of this standard.

Key-Words: security, web applications, access management, privacy, confidentiality,


authenticity
Jánoky described a few methods for token
1 Introduction revocation, comparing the characteristics in
different behaviors with the classic
The objective of JSON Web Token (JWT) is solutions. Considering the fact that the
to provide a secure mechanism for revocation of tokens is part of the
authentication and authorization between authentication process, we can say that it’s
two parties. more important to know how to create and
There are multiple implementations of JWT verify a secured token than revoking one.
as an entry level for access control. This As Mestre et al said in [2], JWT is a suitable
paper presents the analysis of security mechanism for stateless communication
breaches and also the overview of how to between server and client which nowadays
create and use a secured JSON Web it’s used almost all the time. To confirm this
Token. Furthermore, we investigated the assumption, we studied the way in which a
way a hacker can steal or use an already JWT is stored on the client side and also on
created JWT and also the things that should the server side.
be made in order to prevent this kind of To form a better view of this topic, we
actions from untrusted persons. developed a web-based application in order
The main topic of this article is the analysis to present the functionalities of a JSON
of how a JWT can be secured while in [1] Web Token. The application is divided into
2 parts: the client side where the token is be sent as JSON objects that are used as
stored and used for requesting resources, payload structure from Signature JSON
and the server side where the token is Web (JWS) or plaintext structure from
generated and verified for granting access JSON Web Encryption (JWE), enabling
to requested resources. claims to be digitally signed/protected with
This paper clarifies the role of JWT in the Message Authentication Code (MAC).
development process of a secured
authentication mechanism. 3 Problem Solution

2 Problem formulation To summarize the whole process, the end-


user which would like to access a specific
As we already know, each system or resource opens the application and the first
application requires an authentication and thing that should be made is to register in
authorization mechanism that proves that order to have the possibility to get a
the user really is who they claim and resource. During the registration process,
recognize the user rights and privileges. the user has to provide his name, a
Traditionally, the process of authentication username and a password. After the
consists of providing a username and a account is successfully created, the user
password that is verified by the system. needs to be authenticated in order to have
Recent evidence suggests that this access to specific resources. In the
mechanism can be compromised by using authentication process, the credentials
tools for brute force and guessing the provided by the user are validated by the
passwords [3]. server and if there is a match, a JSON Web
However, there are a lot of username and Token with that user details is created and
passwords known attacks and this topic will assigned to the user. Each request made by
always be an open gate for attackers. Many the user will contain the JWT because the
studies show the weaknesses of this type of user should be authenticated in order to
authentication and also the tricks for access any resource. These requests are
creating a strong password [4]. In the send over Secure Socket Layer (SSL) using
purpose of securing the above method, we REST. After the validation of the JWT is
chose the concept of token-based made, if the token is still valid, the user
authentication that allows a user to provide receives access to the requested resource.
his credentials (username and password) in If the token is not validated, the user is
order to get a token which ensures them the redirected to the login page to obtain
access into the system. Once the user is another JWT because the one that was
successfully authenticated, the token is used in the previous request is expired or
obtained and the user can send that token was tempered during the process.
in order to get access to different resources.
The received token has been created on the
server side with a particular algorithm and
specific claims that shows the privileges of
the user.
As M.Jones et al present in [5], JSON Web
Token (JWT) is a representation of the
claim format which is intended for space
such as HTTP Authorization headers and
URI query parameters. JWTs encodes the Figure 1. System Architecture
claim to 3.1 Proposed System Design
to be validated on the server side. On each
We developed a Java web-based request, the token is validated against many
application with Spring MVC and Spring criteria to see if the user that is making the
Security on the back-end side and we used call has authority to get that resource and
Thymeleaf on the front-end side. The also to see if the token is still valid and is
communication is made via REST calls over having the claims that were created in the
SSL in order to have a secure way of authentication process.
transporting the information. Firstly, we
need to create a database in which the
users and tokens will be stored. This
database will contain two tables, one for the
users and the other one for the revoked
tokens. The administrator of the application
has authority to revoke tokens if someone
intercept, modify or is trying to access the
application with an unauthorized token. In
this way, we secure the application and
prevent some malicious attacks.
We used MySQL for database together with
Apache Server because is easy to use and
is coming with a high-security level. The
user must navigate to a specific URL in Figure 2. JWT as Authorization header
order to access the Home page of the
application. 3.2 Implementation
We focused on the authentication and
authorization processes because we For the development of the web-based
wanted to show how to secure these two application, we’ve used IntelliJ IDEA 2018
mechanisms with JWT. When the user and Spring Suite tools.
clicks on the Registration button, a new On the server side, technologies like Spring
window is opened and the registration MVC, Spring Boot and JAX-RS were used
process starts. The end user should provide to create the functionalities of the
the requested information from the application.
registration form like the last name, first For the client side HTML5, CSS3, JQuery,
name, username, and password. After the JavaScript and Thymeleaf were used to
form is fulfilled, the account for that user is create the design of the application and also
successfully created and saved into the for creating the communication between the
database. client and server side. The connection with
The most important part is the the database was made using Spring Data
authentication of a user because, in this JPA with Hibernate.
point, we create a specific JSON Web Regarding the security of the application,
Token for that user. After the user is Spring Security was used to secure the
successfully authenticated, one token with a exposed endpoints and the communication
specific validity is created and assigned to was encrypted between the server and the
the user. This token is stored on the browser using SSL.
sessionStorage of the browser from where
the user was connected to the application
and each request will contain the value of
the token as authorization header in order
3.2.1 Create JWT

One of the two methods used in the


application is to create the token. After
successfully authenticating a user, the
process by which a user receives a unique Figure 4 Add user context in token
token starts. NONE hashing algorithm,
Token sidejacking, Token explicit revocation Regarding the token information disclosure,
by the user and Token information we saw that can occur when a token or a
disclosure [6] are the issues that we cared set of tokens are intercepted or stolen by an
about when we developed the application. attacker. In most cases, the attacker wants
The first issue occurs when someone sends to get access to a token in order to extract
a token with the “none” keyword as an the information stored into it. In the first
algorithm of signing. Some of the JWT place, the JWT is created and then the info
libraries accept and validate tokens with the is Base64 encoded and it’s easy to access
keyword mentioned above. To avoid this them.
potential security breach, during the Usually, information about the system,
validation process of the token, we explicitly security roles, and user details are stored
request that the signing algorithm should be inside the token. Since this information
the same with the algorithm used in the should be protected against untrusted
creation phase. persons, we used the algorithm AES-GCM
for ciphering the token and the
encapsulated data and also to protect the
data against cryptanalysis attacks. This
algorithm is using Authenticated Encryption
with Associated Data that provides the
functionality of symmetric authenticated
Figure 3 JWT algorithm verifier encryption. Implementations of this primitive
are secure against adaptive chosen
ciphertext attacks. When encrypting a
The second concern is about intercepted or plaintext one can optionally provide
stolen tokens. An attacker can use an associated data that should be
intercepted token to gain access to the authenticated but not encrypted.
application by using the identity of the user
which belongs to that token. A way to verify
that the token is not stolen is to add user
context in the token. The first part of the
context contains a randomly generated
string during the authentication process that
will be included in the token and also
attached to a cookie that will be sent to the
client. The second one it’s a SHA256 hash
of the random string that will be stored in
the token in order to prevent any XSS Figure 5 Encrypt JWT
attacks.
That is, the encryption with associated data
ensures authenticity (ie. who the sender is)
and integrity (ie. data has not been
tampered with) of that data, but not its secured and should have the JWT included
secrecy. [7] an Authorization header. For each request,
The ciphering process is mainly used to if the token is present the validation process
hide internal information but the first and the starts and if the token is expired, tempered
most important protection against tampering or doesn’t exists the user is redirected to
of the JWT is the signature. the login page to authenticate again and get
The last things that should be taken into a new token. In this way, we are making
consideration are about the storage of the sure that the person that is trying to access
token on the client side. In some situations, the resources of our application is
the token is stored into a cookie and is sent authorized and has rights for that.
automatically by the browser, stored on the Each request is going firstly through
localStorage of the browser and could be JwtAuthorizationTokenFilter. This filter
retrieved even If the browser is restarted extends the OncePerRequestFilter filter
and sometimes the token could be retrieved where each request is caught before hits
using XSS attacks using JavaScript in order the controller. In this phase, we validate the
to gain access to the token. To minimize the token against all the above-presented
possibilities of encounter one of the above- concerns in order to see if the user has a
mentioned situations, we stored the token valid token and if is authenticated. First of
using the browser sessionStorage all, the token is taken from the Authorization
container, send the token as a Bearer header and is checked to see if is revoked
header using JavaScript for each request or not. After that, the user fingerprint is
and add the fingerprint inside the token. Of taken from the __Secure-Fgp cookie which
course, we’ll have a problem in case we should be present on the request. We
add the token to the sessionStorage validate the fingerprint and token
because the token will be exposed to XSS parameters content to avoid malicious input
attacks but, because of the added and after that, we compute the hash of the
fingerprint, the risk for a token to be stolen fingerprint using the SHA-256 algorithm.
decreases significantly.

Figure 7 Compute hash of the fingerprint

As we already explained in the


authentication phase, we created a
fingerprint that contains user context and
was added as a claim into the JWT. In the
Figure 6 Add JWT as Bearer validation phase, using the computed hash
of the fingerprint, we checked that both
3.2.2 Validate JWT hash results are the same. In this way, we
know for sure that the token was not
The second most important method tempered between the time of creation and
developed is the validation of the token. validation. In this point, our token is half
This method is used in the authorization validated because we still have to validate
process in order to validate the token that the algorithm used for the signature, the
was created in the authentication phase. As time of creation and expiration and the
we mentioned above, each request is token claims If all the validation steps from
above are successfully passed. At the end using Multiple JSON Web Tokens,"
of the validation process, the authentication Proceedings, vol. I, pp. 1-2, 2017.
token is created and is assigned to the [3] M. S. Farash and M. A. Attari, "An
Security Context of the application. In this efficientclient–client password-based
way, Spring Security knows that the user authenticationscheme with provable
has rights and is authenticated. security,"
The Journalof Supercomputing, vol. 70,
4 Conclusion pp.
1002-1022, 2014.
In this paper, the usage of JWT was [4] A. Adams, M. A. Sasse and P. Lunt,
examined in its support for creating a "Making Passwords Secure and Usable,"
secure process of authentication and People and Computers, vol. XII, pp. 1-19,
authorization. The main concerns about the 1977.
vulnerabilities of a token were identified, the
[5] M. Jones, J. Bradley and N. Sakimura,
rules that should be followed in order to
"JSON Web Token (JWT)," 2015.
have a secure token were explained and
[Online]. Available: https://www.rfc-
the best-practice implementation templates
editor.org/info/rfc7519.
were provided. This implementation and the
methodology can be used as a starting [6] J. Manico, D. Righetto and P. Ionescu,
point for other projects that are designed to "JSON_Web_Token_Cheat_Sheet_for_Ja
use the advantages of JSON Web Token. va, "[Online].
The proposed solution minimizes the risks Available: https://github.com/OWASP/
of getting hacked by protecting the CheatSheetSeries/blob/master/cheatsheets/
application against malicious attacks and JSON_Web_Token_Cheat_Sheet_for_Jav
unauthorized people who want to obtain a.md.
information about the user or the content. [7] "Tink Primitives," [Online]. Available:
Additionally, even if a hacker seizes the https://github.com/google/tink/blob/master
JWT, the implementation presented above /docs/
has proved secure against attacks by PRIMITIVES.md#deterministic-
preventing untrusted persons from changing authenticated-encryption-with-associated-
tokens by signing the token using a secret data.
key, adding a user context inside the claims
of the token and also by ciphering the token
in order to decrease the chances of the
token being stolen.

References
[1] L. V. Jánoky, J. Levendovszky and P.
Ekler1,"An analysis on the revoking
mechanisms for JSON Web
Tokens," International Journal of
Distributed
Sensor Networks, vol. 14(9), pp. 2-4, 2018.
[2] P. Mestre, P. M.-P. Rui Madureira and
C.Serodio, "Securing RESTful Web
Services

You might also like