Cap request bodies, close a hole in the gate, fix to_dict and two settings pages
Six fixes that were ours regardless of what the sister site does. Four came out of our own reviews; two you reported from the settings pages. MAX_CONTENT_LENGTH was set nowhere. Every upload route caps its own payload, but each of those checks runs after the body has arrived: the first touch of request.form or request.files makes Werkzeug parse the whole multipart and spool the file to a temp file, so a route can reject the content and still have paid for the transfer and the disk. Three separate reviews found that shape in three different routes, which makes it a property of the app rather than of any handler. 128 MB, clearing the 64 MB agent binary with room for the envelope. The naming gate excluded devnotes with --exclude-dir, which matches a directory of that NAME at any depth - so a force-added plugins/<plugin>/devnotes/ was invisible to every check in the file, ADR-015 included. Replaced with a path anchored post-filter. Verified by planting the same site literal in root devnotes/ AND in plugins/endpoints/devnotes/: the gate now reports exactly one, the nested one. Before, it reported none. BaseModel.to_dict walked __table__.columns and published every one, so a model without an override published whatever it carried - including columns added later by someone not thinking about this method. User has no override, so User.to_dict() returned its bcrypt hash. Nothing calls it in a response path today, which is luck rather than design. A blanket allowlist would empty the output of all 34 models relying on the default, so this pins a floor instead: named secret-bearing columns are never emitted, and a model may extend the set. Eight tests, including a sweep over every mapped model. ActionPicker's Esc handlers had .prevent but not .stop, so the event bubbled to the wrapper and closed the whole picker instead of returning to the monitor list. The branding page reported "error loading image" on the site and badge logos. Two bugs stacked. The load failure was real: the preview used the stored value as a raw src, and that value is root-relative, so under /shopdb or /ops it resolved against the SERVER root and 404d - siteSettings.js wraps every logo in withBase() and this page was the one place that did not. With that fixed two of three were still invisible, because the shipped GE mark is fill="white" for the dark sidebar and was rendering white-on-white. The preview tile now sits on a mid-tone checker so artwork of any colour reads against it. The floor-map levels table ran off the right with its cells crushed - nine columns of inputs, no scroll wrapper, and .data-table is styled nowhere. My first attempt reached for the global .table-container and made it WORSE: that class also sets white-space: nowrap, and a full sentence of hint text lives in one of the cells, so nowrap forced the table wider still. It now scrolls in a local wrapper, the hint wraps, and the name input has a width instead of collapsing to one character. Suite 2377, frontend 324, gate green. Scope: product
This commit is contained in:
69
tests/test_core/test_to_dict_floor.py
Normal file
69
tests/test_core/test_to_dict_floor.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""BaseModel.to_dict never publishes a secret-bearing column.
|
||||
|
||||
The default serialiser walks __table__.columns and emits every one, so a model
|
||||
that does not override it publishes whatever it happens to carry - including
|
||||
columns added later by someone not thinking about this method. User is the live
|
||||
example: it has no override, so User.to_dict() returned its bcrypt hash. Nothing
|
||||
called it in a response path, which was luck.
|
||||
|
||||
A blanket allowlist is the stronger rule and would empty the output of every
|
||||
model relying on the default, so this pins the floor instead: named columns are
|
||||
never emitted, and a model may extend the set.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from shopdb.core.models import User
|
||||
from shopdb.core.models.base import BaseModel
|
||||
|
||||
|
||||
def test_the_default_serialiser_hides_a_password_hash(app):
|
||||
with app.app_context():
|
||||
user = User(username='floor', email='floor@example.invalid',
|
||||
passwordhash='$2b$12$notarealhashbutlookslikeone')
|
||||
data = user.to_dict()
|
||||
assert 'passwordhash' not in data
|
||||
# Still a useful dict - this is a filter, not a mute button.
|
||||
assert data['username'] == 'floor'
|
||||
assert data['email'] == 'floor@example.invalid'
|
||||
|
||||
|
||||
def test_every_hidden_name_is_actually_dropped(app):
|
||||
"""Each entry earns its place: drop one and the column comes back."""
|
||||
with app.app_context():
|
||||
user = User(username='floor2', email='f2@example.invalid',
|
||||
passwordhash='x')
|
||||
assert 'passwordhash' in {c.name for c in User.__table__.columns}
|
||||
assert 'passwordhash' in BaseModel.HIDDEN_COLUMNS
|
||||
assert 'passwordhash' not in user.to_dict()
|
||||
|
||||
|
||||
def test_a_model_can_extend_the_hidden_set(app):
|
||||
"""A model with its own secret adds to the floor rather than replacing
|
||||
to_dict wholesale."""
|
||||
with app.app_context():
|
||||
class Extended(User):
|
||||
__abstract__ = True
|
||||
HIDDEN_COLUMNS = BaseModel.HIDDEN_COLUMNS | {'email'}
|
||||
|
||||
assert 'passwordhash' in Extended.HIDDEN_COLUMNS
|
||||
assert 'email' in Extended.HIDDEN_COLUMNS
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', sorted(BaseModel.HIDDEN_COLUMNS))
|
||||
def test_no_model_publishes_a_hidden_column_through_the_default(name, app):
|
||||
"""Sweep every mapped model: if it carries a hidden column AND relies on the
|
||||
default to_dict, the column must not come out."""
|
||||
with app.app_context():
|
||||
from shopdb.extensions import db
|
||||
|
||||
for mapper in db.Model.registry.mappers:
|
||||
model = mapper.class_
|
||||
table = getattr(model, '__table__', None)
|
||||
if table is None or name not in table.columns:
|
||||
continue
|
||||
if 'to_dict' in vars(model):
|
||||
continue # overrides the default; its own business
|
||||
assert name in getattr(model, 'HIDDEN_COLUMNS', frozenset()), (
|
||||
'%s carries %s and uses the default to_dict, so it would be '
|
||||
'published' % (model.__name__, name))
|
||||
Reference in New Issue
Block a user