userauth icon indicating copy to clipboard operation
userauth copied to clipboard

有循环重定向的可能

Open huqingliang opened this issue 8 years ago • 3 comments

if (!this.session) {
      debug('this.session not exists');
      // ignore not match path
      if (!loginRequired) {
        debug('not match needLogin path, %j', this.path);
        return yield next;
      }
      debug('relogin again');
      return yield loginHandler.call(this, next);
    }

    // get login path
    if (this.path === options.loginPath) {
      debug('match login path');
      return yield loginHandler.call(this, next);
    }

场景: 当 loginPath=/login loginHost=demo.xxx.com 浏览器中输入demo.xxx.com/login (带有部分cookie),这是就能跳过第一个判断if (!this.session) 而 if (this.path === options.loginPath) 符合条件! 最终就会执行到loginHandler 的 redirect(this, loginURL); @fengmk2

huqingliang avatar Dec 11 '15 09:12 huqingliang

这种 userauth 无法解决的。

fengmk2 avatar Dec 11 '15 09:12 fengmk2

if (!loginRequired) {
        debug('not match needLogin path, %j', this.path);
        return yield next;
      }

这段拎出来呢?/login加入白名单,让他直接跳到下一个中间件

huqingliang avatar Dec 11 '15 09:12 huqingliang

或者这样?

if (!this.session) 
to
if (!this.session || !this.session[options.userField])

huqingliang avatar Dec 11 '15 09:12 huqingliang