added escape route to allow ios webapp homepage creation
This commit is contained in:
@@ -133,7 +133,21 @@ Administrators can create additional registration groups from `/groups`.
|
|||||||
|
|
||||||
### Login by password hash
|
### Login by password hash
|
||||||
|
|
||||||
Opening `/<hashedpassword>` signs in the user whose stored `password_hash` text
|
The optional `runtime.blank` setting in `instance/secrets.yaml` defaults to
|
||||||
|
`false`. Set it to `true` and restart the app to make the hash route display only
|
||||||
|
`thank you`, without checking the hash, logging in, or redirecting:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
runtime:
|
||||||
|
blank: true
|
||||||
|
# Keep your other existing runtime settings here.
|
||||||
|
```
|
||||||
|
|
||||||
|
The same blank behavior applies daily from 22:00:00 (inclusive) until 22:10:00
|
||||||
|
(exclusive), using the server's local timezone, even when `blank` is `false`.
|
||||||
|
Setting `blank` to `true` keeps this behavior enabled all day.
|
||||||
|
|
||||||
|
Outside blank mode, opening `/<hashedpassword>` signs in the user whose stored `password_hash` text
|
||||||
after the third colon exactly matches that URL segment, then redirects to the
|
after the third colon exactly matches that URL segment, then redirects to the
|
||||||
lists page. For example, `scrypt:32768:8:1$salt$digest` uses `/1$salt$digest`.
|
lists page. For example, `scrypt:32768:8:1$salt$digest` uses `/1$salt$digest`.
|
||||||
URL-encode the suffix when building the link. Full hashes are not accepted.
|
URL-encode the suffix when building the link. Full hashes are not accepted.
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from datetime import datetime, time
|
||||||
|
|
||||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, make_response, current_app
|
from flask import Blueprint, render_template, request, redirect, url_for, flash, make_response, current_app
|
||||||
from flask_login import login_user, logout_user, login_required, current_user
|
from flask_login import login_user, logout_user, login_required, current_user
|
||||||
from models import db
|
from models import db
|
||||||
@@ -13,6 +15,14 @@ AUTOLOGIN_SALT = "lapp-autologin"
|
|||||||
|
|
||||||
@auth_bp.route("/<hashedpassword>", methods=["GET"])
|
@auth_bp.route("/<hashedpassword>", methods=["GET"])
|
||||||
def login_by_password_hash(hashedpassword):
|
def login_by_password_hash(hashedpassword):
|
||||||
|
local_time = datetime.now().time()
|
||||||
|
if current_app.config.get("blank", False) or time(22, 0) <= local_time < time(22, 10):
|
||||||
|
response = make_response("thank you")
|
||||||
|
response.headers["Content-Type"] = "text/plain; charset=utf-8"
|
||||||
|
response.headers["Cache-Control"] = "no-store"
|
||||||
|
response.headers["Referrer-Policy"] = "no-referrer"
|
||||||
|
return response
|
||||||
|
|
||||||
# A hash in this URL is a bearer credential. Never log it here.
|
# A hash in this URL is a bearer credential. Never log it here.
|
||||||
candidates = User.query.filter(
|
candidates = User.query.filter(
|
||||||
User.password_hash.endswith(":" + hashedpassword, autoescape=True)
|
User.password_hash.endswith(":" + hashedpassword, autoescape=True)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ def create_app():
|
|||||||
app.config["SECRET_KEY"] = secret_values["runtime"]["secret_key"]
|
app.config["SECRET_KEY"] = secret_values["runtime"]["secret_key"]
|
||||||
app.config["APPLICATION_KEY"] = secret_values["runtime"]["application_key"]
|
app.config["APPLICATION_KEY"] = secret_values["runtime"]["application_key"]
|
||||||
app.config["SQLALCHEMY_DATABASE_URI"] = secret_values["runtime"]["database_uri"]
|
app.config["SQLALCHEMY_DATABASE_URI"] = secret_values["runtime"]["database_uri"]
|
||||||
|
app.config["blank"] = secret_values["runtime"].get("blank", False)
|
||||||
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
login_manager.init_app(app)
|
login_manager.init_app(app)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
from datetime import datetime
|
||||||
|
from unittest.mock import patch
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
from flask import Blueprint, Flask
|
from flask import Blueprint, Flask
|
||||||
@@ -10,6 +12,10 @@ from models import User, db
|
|||||||
|
|
||||||
class PasswordHashLoginTest(unittest.TestCase):
|
class PasswordHashLoginTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
clock = patch("auth.datetime")
|
||||||
|
self.clock = clock.start()
|
||||||
|
self.addCleanup(clock.stop)
|
||||||
|
self.clock.now.return_value = datetime(2026, 10, 15, 12)
|
||||||
self.app = Flask(__name__)
|
self.app = Flask(__name__)
|
||||||
self.app.config.update(
|
self.app.config.update(
|
||||||
TESTING=True, SECRET_KEY="test-only",
|
TESTING=True, SECRET_KEY="test-only",
|
||||||
@@ -57,6 +63,44 @@ class PasswordHashLoginTest(unittest.TestCase):
|
|||||||
def test_unknown_hash(self):
|
def test_unknown_hash(self):
|
||||||
self.assert_rejected(self.login("unknown"))
|
self.assert_rejected(self.login("unknown"))
|
||||||
|
|
||||||
|
def test_blank_displays_thank_you_without_login(self):
|
||||||
|
self.app.config["blank"] = True
|
||||||
|
for suffix in (self.user.password_hash.split(":", 3)[3], "unknown"):
|
||||||
|
with self.subTest(suffix=suffix):
|
||||||
|
response = self.login(suffix)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(response.get_data(as_text=True), "thank you")
|
||||||
|
self.assertEqual(response.mimetype, "text/plain")
|
||||||
|
self.assertNotIn("Location", response.headers)
|
||||||
|
with self.client.session_transaction() as session:
|
||||||
|
self.assertNotIn("_user_id", session)
|
||||||
|
|
||||||
|
def test_blank_false_preserves_login(self):
|
||||||
|
self.app.config["blank"] = False
|
||||||
|
self.test_valid_hash_logs_in_and_redirects()
|
||||||
|
|
||||||
|
def test_daily_blank_window(self):
|
||||||
|
self.app.config["blank"] = False
|
||||||
|
for hour, minute, second, expected_status in (
|
||||||
|
(21, 59, 59, 302),
|
||||||
|
(22, 0, 0, 200),
|
||||||
|
(22, 5, 0, 200),
|
||||||
|
(22, 9, 59, 200),
|
||||||
|
(22, 10, 0, 302),
|
||||||
|
):
|
||||||
|
with self.subTest(time=(hour, minute, second)):
|
||||||
|
self.client = self.app.test_client()
|
||||||
|
self.clock.now.return_value = datetime(
|
||||||
|
2026, 10, 15, hour, minute, second
|
||||||
|
)
|
||||||
|
response = self.login()
|
||||||
|
self.assertEqual(response.status_code, expected_status)
|
||||||
|
if expected_status == 200:
|
||||||
|
self.assertEqual(response.get_data(as_text=True), "thank you")
|
||||||
|
self.assertNotIn("Location", response.headers)
|
||||||
|
with self.client.session_transaction() as session:
|
||||||
|
self.assertNotIn("_user_id", session)
|
||||||
|
|
||||||
def test_full_hash_is_rejected(self):
|
def test_full_hash_is_rejected(self):
|
||||||
self.assert_rejected(self.login(self.user.password_hash))
|
self.assert_rejected(self.login(self.user.password_hash))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user