wgwz / flask-cookie-decode Goto Github PK
View Code? Open in Web Editor NEWFlask extension with tools for decoding the session cookie
License: MIT License
Flask extension with tools for decoding the session cookie
License: MIT License
It seems on recent flask/python setups the total_seconds is missing from flask.helpers
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/theapp/run.py", line 1, in <module>
from theapp import create_app
File "/theapp/theapp/__init__.py", line 42, in <module>
from flask_cookie_decode import CookieDecode
File "/usr/local/lib/python3.10/site-packages/flask_cookie_decode/__init__.py", line 19, in <module>
from .cookie_decode import CookieDecode
File "/usr/local/lib/python3.10/site-packages/flask_cookie_decode/cookie_decode.py", line 8, in <module>
from flask.helpers import total_seconds
ImportError: cannot import name 'total_seconds' from 'flask.helpers' (/usr/local/lib/python3.10/site-packages/flask/helpers.py)
one feature that would be kind of interesting is if the fcd
CLI could automatically read cookies from the browser. as it stands the only way to use this tool is to manually go into the browser tools and copy the cookie from the storage tab by hand. this is somewhat of a tricky problem to solve because of the usual fact that browsers do things differently. but also after digging into this a little bit it looks like firefox has some complex set of rules for when they update there cookies database.
so this is a tracking issue where the hope is to build a command like:
$ fcd firefox
$ fcd chrome
$ fcd edge
the assumption is that this is run during local development, on a system that has a browser. each of those commands will do it's best to search for the cookie set by the flask application on the users filesystem, read it and then send the decoded results back to command-line.
so far i've gathered some resources about how this implemented in firefox.
one noteworthy thing is that when you try to access your cookies sqlite db while firefox is running, there is a lock placed on the database which prevents access from any other sqlite3
clients. as mentioned in those resources above you can bypass that by creating a copy of the .sqlite
file. but that is problematic because the copied version does have the results, which are yet to be committed by the firefox process locking the db.
that puts a major damper on this approach as figuring out how to get firefox to commit changes to the cookies db probably would involve manual work or an extension.
i thought i had tested this but forgot that i never did!
here's the test for uncompressed cookies (notice how i forgot the compressed case): https://github.com/wgwz/flask-cookie-decode/blob/master/tests/test_flask_cookie_decode.py#L26-L30
the only CLI that is available at the moment is made available through the flask
command. this is valuable in situations where you would like to validate the session cookie (verify it's signature) in addition to reading the content of the cookie. but it has a down-side of needing to be configured with the flask application you are looking to read cookies for.
in some situations you might just want to run a cli script without having to attach to any flask applications, in order to just read the cookie. so for this case, i want to add CLI that allows just that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.