rest - Security Attacks possible on TokenBased Authentication? -
i have designed web application uses simple implementation of jwt token's provide authentication/authorization.
my implementation :
- there 2 types of urls's public , secure.
- public urls generate token username/password.
i have added filter on secure url check authorization header , jwt token.
@bean public filterregistrationbean jwtfilter() { final filterregistrationbean registrationbean = new filterregistrationbean(); registrationbean.setfilter(new jwtfilter()); registrationbean.addurlpatterns("/secure/*"); return registrationbean;
}
filter validate token. haven't added expiration date yet.
final httpservletrequest request = (httpservletrequest) req; final httpservletresponse response = (httpservletresponse) res; final string authheader = request.getheader("authorization"); if ("options".equals(request.getmethod())) { response.setstatus(httpservletresponse.sc_ok); chain.dofilter(req, res); } else { if (authheader == null || !authheader.startswith("bearer ")) { throw new servletexception("missing or invalid authorization header"); } final string token = authheader.substring(7); try { final claims claims = jwts.parser().setsigningkey(secretkey.tostring).parseclaimsjws(token).getbody(); request.setattribute("claims", claims); } catch (final signatureexception e) { throw new servletexception("invalid token"); } chain.dofilter(req, res); }
this providing authentication , immune csrf.no 1 can create valid token without secret key.
are there other attacks possible on token base authentication service have missed?
Comments
Post a Comment