Skip to content

Commit 8105541

Browse files
authored
Merge pull request #377 from MerginMaps/release-2025.2.0
Release 2025.2.0
2 parents 566158a + bcb81cf commit 8105541

40 files changed

+1415
-685
lines changed

.prod.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ SECRET_KEY=fixme
6161

6262
#BEARER_TOKEN_EXPIRATION=3600 * 12 # in seconds
6363

64+
#SECURITY_BEARER_SALT=NODEFAULT
65+
SECURITY_BEARER_SALT=fixme
66+
67+
#SECURITY_EMAIL_SALT=NODEFAULT
68+
SECURITY_EMAIL_SALT=fixme
69+
6470
#SECURITY_PASSWORD_SALT=NODEFAULT
6571
SECURITY_PASSWORD_SALT=fixme
6672

server/.test.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ GLOBAL_WORKSPACE='mergin'
2020
GLOBAL_STORAGE=104857600
2121
COLLECT_STATISTICS=0
2222
GEODIFF_WORKING_DIR=/tmp/geodiff
23+
SECURITY_BEARER_SALT='bearer'
24+
SECURITY_EMAIL_SALT='email'
25+
SECURITY_PASSWORD_SALT='password'

server/Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ urllib3 = "==2.2.2"
3939
shapely = "==2.0.6"
4040
psycogreen = "==1.0.2"
4141
importlib-metadata = "==8.4.0" # https://github.com/pallets/flask/issues/4502
42-
typing_extensions= "==4.12.2"
42+
typing_extensions = "==4.12.2"
4343
# requirements for development on windows
4444
colorama = "==0.4.5"
4545

server/Pipfile.lock

Lines changed: 492 additions & 473 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/application.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from mergin.sync.tasks import remove_temp_files, remove_projects_backups
2727
from mergin.celery import celery, configure_celery
2828
from mergin.stats.config import Configuration
29-
from mergin.stats.tasks import send_statistics
29+
from mergin.stats.tasks import save_statistics, send_statistics
3030
from mergin.stats.app import register as register_stats
3131

3232
Configuration.SERVER_TYPE = "ce"
@@ -65,14 +65,14 @@ def setup_periodic_tasks(sender, **kwargs):
6565
remove_projects_backups,
6666
name="remove old project backups",
6767
)
68+
sender.add_periodic_task(
69+
crontab(hour="*/12", minute=0),
70+
save_statistics,
71+
name="Save usage statistics to database",
72+
)
6873
if Configuration.COLLECT_STATISTICS:
6974
sender.add_periodic_task(
7075
crontab(hour=randint(0, 5), minute=randint(0, 60)),
7176
send_statistics,
7277
name="send usage statistics",
7378
)
74-
75-
76-
# send report after start
77-
if Configuration.COLLECT_STATISTICS:
78-
send_statistics.delay()

server/mergin/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
GEODIFF_LOGGER_LEVEL="2"
22
# only for dev - should be overwritten in production
33
SECRET_KEY='top-secret'
4+
SECURITY_BEARER_SALT='top-secret'
5+
SECURITY_EMAIL_SALT='top-secret'
46
SECURITY_PASSWORD_SALT='top-secret'
57
MAIL_DEFAULT_SENDER=''
68
FLASK_DEBUG=0

server/mergin/app.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,6 @@ def create_simple_app() -> Flask:
139139
if Configuration.GEVENT_WORKER:
140140
flask_app.wsgi_app = GeventTimeoutMiddleware(flask_app.wsgi_app)
141141

142-
@flask_app.cli.command()
143-
def init_db():
144-
"""Re-creates application database"""
145-
print("Database initialization ...")
146-
db.drop_all(bind=None)
147-
db.create_all(bind=None)
148-
db.session.commit()
149-
print("Done. Tables created.")
150-
151142
add_commands(flask_app)
152143

153144
return flask_app
@@ -211,6 +202,7 @@ def load_user_from_header(header_val): # pylint: disable=W0613,W0612
211202
try:
212203
data = decode_token(
213204
app.app.config["SECRET_KEY"],
205+
app.app.config["SECURITY_BEARER_SALT"],
214206
header_val,
215207
app.app.config["BEARER_TOKEN_EXPIRATION"],
216208
)

server/mergin/auth/app.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,15 @@ def authenticate(login, password):
8080
return user
8181

8282

83-
def generate_confirmation_token(app, email):
83+
def generate_confirmation_token(app, email, salt):
8484
serializer = URLSafeTimedSerializer(app.config["SECRET_KEY"])
85-
return serializer.dumps(email, salt=app.config["SECURITY_PASSWORD_SALT"])
85+
return serializer.dumps(email, salt=salt)
8686

8787

88-
def confirm_token(token, expiration=3600 * 24 * 3):
88+
def confirm_token(token, salt, expiration=3600):
8989
serializer = URLSafeTimedSerializer(current_app.config["SECRET_KEY"])
9090
try:
91-
email = serializer.loads(
92-
token, salt=current_app.config["SECURITY_PASSWORD_SALT"], max_age=expiration
93-
)
91+
email = serializer.loads(token, salt=salt, max_age=expiration)
9492
except:
9593
return
9694
return email
@@ -103,7 +101,12 @@ def send_confirmation_email(app, user, url, template, header, **kwargs):
103101
"""
104102
from ..celery import send_email_async
105103

106-
token = generate_confirmation_token(app, user.email)
104+
salt = (
105+
app.config["SECURITY_EMAIL_SALT"]
106+
if url == "confirm-email"
107+
else app.config["SECURITY_PASSWORD_SALT"]
108+
)
109+
token = generate_confirmation_token(app, user.email, salt)
107110
confirm_url = f"{url}/{token}"
108111
html = render_template(
109112
template, subject=header, confirm_url=confirm_url, user=user, **kwargs

server/mergin/auth/bearer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from flask.sessions import TaggedJSONSerializer
88

99

10-
def decode_token(secret_key, token, max_age=None):
11-
salt = "bearer-session"
10+
def decode_token(secret_key, salt, token, max_age=None):
1211
serializer = TaggedJSONSerializer()
1312
signer_kwargs = {"key_derivation": "hmac", "digest_method": hashlib.sha1}
1413
s = URLSafeTimedSerializer(
@@ -17,8 +16,7 @@ def decode_token(secret_key, token, max_age=None):
1716
return s.loads(token, max_age=max_age)
1817

1918

20-
def encode_token(secret_key, data):
21-
salt = "bearer-session"
19+
def encode_token(secret_key, salt, data):
2220
serializer = TaggedJSONSerializer()
2321
signer_kwargs = {"key_derivation": "hmac", "digest_method": hashlib.sha1}
2422
s = URLSafeTimedSerializer(

server/mergin/auth/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77

88
class Configuration(object):
9+
SECURITY_BEARER_SALT = config("SECURITY_BEARER_SALT")
10+
SECURITY_EMAIL_SALT = config("SECURITY_EMAIL_SALT")
911
SECURITY_PASSWORD_SALT = config("SECURITY_PASSWORD_SALT")
1012
BEARER_TOKEN_EXPIRATION = config(
1113
"BEARER_TOKEN_EXPIRATION", default=3600 * 12, cast=int

0 commit comments

Comments
 (0)