【问题标题】:User can access internal yaws pages without authentication用户无需身份验证即可访问内部 yaws 页面
【发布时间】:2014-12-21 07:43:15
【问题描述】:

我正在使用带有 yaws cookie 会话的嵌入式 YAWS 网络服务器。 我首先使用用户名和密码对用户进行身份验证,以允许他进入网页。

我的问题是如果用户直接打开内部网页而不是登录页面,即使没有身份验证,他也可以查看它。如何限制用户必须拥有 cookie 才能查看任何内部网页。

【问题讨论】:

    标签: erlang yaws


    【解决方案1】:

    chapter 7 of the Yaws PDF documentation 中,有一个示例完全符合您的要求。它使用 arg 重写将未经身份验证的请求重定向到登录页面。

    首先我们在yaws.conf的服务器部分配置一个名为myapp的arg重写器模块:

    arg_rewrite_mod = myapp
    

    myapp:arg_rewrite/1 函数通过 #arg{} 记录检查传入请求以查找特定 cookie,如果未找到并且请求未尝试检索从 login_pages/0 函数返回的三个资源之一,它调用do_rewrite/1 来重写请求以提供login.yaws 页面:

    arg_rewrite(Arg) ->
        OurCookieName = "myapp_sid"
        case check_cookie(Arg, OurCookieName) of
            {error, _} ->
                do_rewrite(Arg);
            {ok, _Session} ->
                %% return Arg untouched
                Arg
    end.
    
    %% these pages must be shippable without a good cookie
    login_pages() ->
        ["/banner.gif", "/login.yaws", "/post_login.yaws"].
    
    do_rewrite(Arg) ->
        Req = Arg#arg.req,
        {abs_path, Path} = Req#http_request.path,
        case lists:member(Path, login_pages()) of
            true ->
                Arg;
            false ->
                Arg#arg{req = Req#http_request{path = {abs_path, "/login.yaws"}},
                        state = Path}
    end.
    

    请查看Yaws PDF documentation了解更多详情。

    【讨论】:

    • :) 我已经找到了相同的解决方案,但无论如何谢谢 :)
    猜你喜欢
    • 2021-10-15
    • 1970-01-01
    • 2011-07-24
    • 2021-07-27
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多