web2py 2.23.0 is giving a 403 error when I try to package my applications

145 views
Skip to first unread message

Davidiam

unread,
Jan 5, 2023, 3:54:07 AM1/5/23
to web2py-users
Good Morning,

We are using IIS 10 with web2py 2.23.0.

When I try to pack the welcome application (or any other), using pack_all I get a 403 error.
When I try to pack the welcome application (or any other), using pack_custom, it first displays the file selector and when I click on download as .w2p I get a 403 error.

This seems to be related to the open_redirect changes.  I tried putting the 403 error related code from the admin\default.py controller in comment, but it still is giving the error.  

Kind Regards,
David

Davidiam

unread,
Jan 9, 2023, 3:10:12 AM1/9/23
to web2py-users
I just did a test on my own PC with web2py out of the box and I got a 403 error when packing the application.  Now that I know that it has nothing to do with the webserver, I will try to debug the issue.
I will debug the issue to determine where in the code it is occurring.

Davidiam

unread,
Jan 9, 2023, 4:37:57 AM1/9/23
to web2py-users
I found where this is occurring (out of the box run, no mods):

C:\Users\u30591\web2py_2.23.0\web2py\applications\admin\controllers\default.py:
def safe_open(a, b):
    if (DEMO_MODE or is_gae) and ('w' in b or 'a' in b):
        class tmp:

            def write(self, data):
                pass

            def close(self):
                pass
        return tmp()

    a_for_check = os.path.abspath(os.path.normpath(a))
    web2py_apps_root = os.path.abspath(up(request.folder))

    if not a_for_check.startswith(web2py_apps_root):
        raise HTTP(403) 

Because:
web2py_apps_root = 'C:\\Users\\myuser\\web2py_2.23.0\\web2py\\applications'
a_for_check =  'C:\\Users\\myuser\\web2py_2.23.0\\web2py\\deposit\\web2py.app.403_test.w2p'


On Thursday, January 5, 2023 at 9:54:07 AM UTC+1 Davidiam wrote:

Davidiam

unread,
Jan 9, 2023, 4:55:21 AM1/9/23
to web2py-users
Which is in turn caused by:

def app_pack(app, request, raise_ex=False, filenames=None):
    """Builds a w2p package for the application

    Args:
        app(str): application name
        request: the global request object
    Returns:
        filename of the w2p file or None on error

    """
    try:
        if filenames is None:
            app_cleanup(app, request)
        filename = apath('../deposit/web2py.app.%s.w2p' % app, request)
        w2p_pack(filename, apath(app, request), filenames=filenames)
        return filename
    except Exception as e:
        if raise_ex:
            raise
        return False

Clemens

unread,
Jan 9, 2023, 5:00:22 AM1/9/23
to web2py-users
Just a guess: What python version are you using? If you're still using python 2, it could be the reason.

Davidiam

unread,
Jan 9, 2023, 5:44:16 AM1/9/23
to web2py-users
I am using python 3.9.15

pcg...@gmail.com

unread,
Feb 12, 2023, 4:21:20 PM2/12/23
to web2py-users
Have the same issue (python 3.10)  i've tried the latest web2py 2.23.1, and it's th same.   I'm kind of lost on this one.

Davidiam

unread,
Feb 13, 2023, 2:28:40 AM2/13/23
to web2py-users
Hi pcg,

I also created a bug report for this one and got a message from Massimo that it would be fixed in a new release.  A work-around I used was to simply put the code below in the admin default.py into comment:
    #if not a_for_check.startswith(web2py_apps_root):
    #    raise HTTP(403) 
But I don't know what the final solution will be in the official fix.

Kind Regards,
David

pcwalden

unread,
Feb 26, 2023, 8:51:30 AM2/26/23
to web2py-users
I submitted an issue #2457 a month ago. Please leverage that one.

Massimo Di Pierro

unread,
Mar 23, 2023, 1:13:07 AM3/23/23
to web2py-users
This has been fixed and 2.24.1 released. My apologies for overlooking the issue.
Reply all
Reply to author
Forward
0 new messages