Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
fb164298
Commit
fb164298
authored
May 04, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Randomize flask secret_key
parent
36a984ce
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
__init__.py
cps/__init__.py
+1
-1
config_sql.py
cps/config_sql.py
+20
-2
No files found.
cps/__init__.py
View file @
fb164298
...
...
@@ -88,7 +88,7 @@ def create_app():
log
.
info
(
'Starting Calibre Web...'
)
Principal
(
app
)
lm
.
init_app
(
app
)
app
.
secret_key
=
os
.
getenv
(
'SECRET_KEY'
,
'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
)
app
.
secret_key
=
os
.
getenv
(
'SECRET_KEY'
,
config_sql
.
get_flask_session_key
(
ub
.
session
)
)
web_server
.
init_app
(
app
,
config
)
db
.
setup_db
(
config
)
...
...
cps/config_sql.py
View file @
fb164298
...
...
@@ -22,7 +22,7 @@ import os
import
json
import
sys
from
sqlalchemy
import
exc
,
Column
,
String
,
Integer
,
SmallInteger
,
Boolean
from
sqlalchemy
import
exc
,
Column
,
String
,
Integer
,
SmallInteger
,
Boolean
,
BLOB
from
sqlalchemy.ext.declarative
import
declarative_base
from
.
import
constants
,
cli
,
logger
,
ub
...
...
@@ -31,6 +31,15 @@ from . import constants, cli, logger, ub
log
=
logger
.
create
()
_Base
=
declarative_base
()
class
_Flask_Settings
(
_Base
):
__tablename__
=
'flask_settings'
id
=
Column
(
Integer
,
primary_key
=
True
)
flask_session_key
=
Column
(
BLOB
,
default
=
""
)
def
__init__
(
self
,
key
):
self
.
flask_session_key
=
key
# Baseclass for representing settings in app.db with email server settings and Calibre database settings
# (application settings)
...
...
@@ -301,7 +310,7 @@ def _migrate_table(session, orm_class):
log
.
debug
(
"
%
s:
%
s"
,
column_name
,
err
.
args
[
0
])
if
column
.
default
is
not
None
:
if
sys
.
version_info
<
(
3
,
0
):
if
isinstance
(
column
.
default
.
arg
,
unicode
):
if
isinstance
(
column
.
default
.
arg
,
unicode
):
column
.
default
.
arg
=
column
.
default
.
arg
.
encode
(
'utf-8'
)
if
column
.
default
is
None
:
column_default
=
""
...
...
@@ -337,6 +346,7 @@ def _migrate_database(session):
# make sure the table is created, if it does not exist
_Base
.
metadata
.
create_all
(
session
.
bind
)
_migrate_table
(
session
,
_Settings
)
_migrate_table
(
session
,
_Flask_Settings
)
def
load_configuration
(
session
):
...
...
@@ -354,3 +364,11 @@ def load_configuration(session):
update
({
"denied_tags"
:
conf
.
config_mature_content_tags
},
synchronize_session
=
False
)
session
.
commit
()
return
conf
def
get_flask_session_key
(
session
):
flask_settings
=
session
.
query
(
_Flask_Settings
)
.
one_or_none
()
if
flask_settings
==
None
:
flask_settings
=
_Flask_Settings
(
os
.
urandom
(
32
))
session
.
add
(
flask_settings
)
session
.
commit
()
return
flask_settings
.
flask_session_key
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment