HTML5¼¼Êõ

»ùÓÚTokenµÄWEBºǫ́ÈÏÖ¤»úÖÆ - ºìÐÄÀî(3)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£º²©¿ÍÔ° 2016-06-25 17:00 ÎÒÒªÆÀÂÛ( )

·þÎñ¶Ë def set_current_user_from_jwt_token # Ç°ÃæµÄ²½Öè²Î¿¼ÉÏÃæ payload = JWT.decode(request.authorization, nil, false) @current_user = User.find(payload[user_id]) JWT.decode(request.authorization, c

·þÎñ¶Ë

def set_current_user_from_jwt_token # Ç°ÃæµÄ²½Öè²Î¿¼ÉÏÃæ payload = JWT.decode(request.authorization, nil, false) @current_user = User.find(payload['user_id']) JWT.decode(request.authorization, current_user.api_secret) now = Time.now.to_i if payload['iat'] > now || payload['exp'] < now # ·µ»Ø401 end # ÏÂÃ潫¼ì²éÈ·±£Õâ¸öJWT֮ǰûÓб»Ê¹Óùý # ʹÓÃRedisµÄÔ­×Ó²Ù×÷ # The redis µÄ¼ü: <user id>:<one-time use token> key = "#{payload['user_id']}:#{payload['jti']}" # ¿´¼üÖµÊÇ·ñÔÚredisÖÐÒѾ­´æÔÚ. Èç¹û²»´æÔÚÔò·µ»Ønil. Èç¹û´æÔÚÔò·µ»Ø¡°1¡±. . if redis.getset(key, "1") # ·µ»Ø401 # end # ½øÐмüÖµ¹ýÆÚ¼ì²é redis.expireat(key, payload['exp'] + 2) end ÈçºÎ·À·¶MITM £¨Man-In-The-Middle£©Attacks

ËùνMITM¹¥»÷£¬¾ÍÊÇÔÚ¿Í»§¶ËºÍ·þÎñÆ÷¶ËµÄ½»»¥¹ý³Ì±»¼àÌý£¬±ÈÈçÏñ¿ÉÒÔÉÏÍøµÄ¿§·È¹ÝµÄWIFI±»¼àÌý»òÕß±»ºÚµÄ´úÀí·þÎñÆ÷µÈ£»
Õë¶ÔÕâÀ๥»÷µÄ°ì·¨Ê¹ÓÃHTTPS£¬°üÀ¨Õë¶Ô·Ö²¼Ê½Ó¦Óã¬ÔÚ·þÎñ¼ä´«ÊäÏñcookieÕâÀàÃô¸ÐÐÅϢʱҲ²ÉÓÃHTTPS£»ËùÒÔÔƼÆËãÔÚ±¾ÖÊÉÏÊDz»°²È«µÄ¡£

²Î¿¼Ä¿Â¼£º
https://stormpath.com/blog/build-secure-user-interfaces-using-jwts
https://auth0.com/blog/2014/01/27/ten-things-you-should-know-about-tokens-and-cookies/
https://www.quora.com/Is-JWT-JSON-Web-Token-insecure-by-design
https://github.com/auth0/node-jsonwebtoken/issues/36

posted @

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ËæÓ¦³±Á÷-»ùÓÚABP+AngularjsÏÖ´ú»¯Ó¦ÓÃÈí¼þ¿ª·¢¿ò¼Ü(1)-×ÜÌå½éÉÜ - ÔÚ·ÔÚµÄÕÅ

    ËæÓ¦³±Á÷-»ùÓÚABP+AngularjsÏÖ´ú»¯Ó¦ÓÃÈí¼þ¿ª·¢¿ò¼Ü(1)-×ÜÌå½éÉÜ -

    2017-04-22 08:04

  • »ùÓÚCSSµÄ¸öÈËÍøÒ³ - ÉÇ´ó-Îâ¹ãÁÖ

    »ùÓÚCSSµÄ¸öÈËÍøÒ³ - ÉÇ´ó-Îâ¹ãÁÖ

    2017-04-21 12:00

  • PixiJS - »ùÓÚ WebGL µÄ³¬¿ì HTML5 2D äÖȾÒýÇæ - ÃÎÏëÌì¿Õ£¨É½±ßСϪ£©

    PixiJS - »ùÓÚ WebGL µÄ³¬¿ì HTML5 2D äÖȾÒýÇæ - ÃÎÏëÌì¿Õ£¨É½±ßС

    2017-04-12 08:02

  • ÈÎÎñµ÷¶ÈÖ®³Ö¾Ã»¯£¨»ùÓÚQuartz.net£© - À¶½¨ÈÙ

    ÈÎÎñµ÷¶ÈÖ®³Ö¾Ã»¯£¨»ùÓÚQuartz.net£© - À¶½¨ÈÙ

    2017-03-28 12:03

ÍøÓѵãÆÀ
®