diff --git a/files/classes/user.py b/files/classes/user.py index b4c4eb554..edfccfb1b 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -57,8 +57,8 @@ class User(Base): verifiedcolor = Column(String) winnings = Column(Integer, default=0, nullable=False) email = deferred(Column(String)) - css = deferred(Column(String)) - profilecss = deferred(Column(String)) + css = deferred(Column(String(CSS_LENGTH_MAXIMUM))) + profilecss = deferred(Column(String(CSS_LENGTH_MAXIMUM))) passhash = deferred(Column(String, nullable=False)) post_count = Column(Integer, default=0, nullable=False) comment_count = Column(Integer, default=0, nullable=False) diff --git a/files/helpers/const.py b/files/helpers/const.py index 55ce80c00..09a38af34 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -62,6 +62,7 @@ COLORS = {'ff66ac','805ad5','62ca56','38a169','80ffff','2a96f3','eb4963','ff0000 SUBMISSION_BODY_LENGTH_MAXIMUM: Final[int] = 20000 COMMENT_BODY_LENGTH_MAXIMUM: Final[int] = 10000 MESSAGE_BODY_LENGTH_MAXIMUM: Final[int] = 10000 +CSS_LENGTH_MAXIMUM: Final[int] = 4000 ERROR_MESSAGES = { 400: "That request was bad and you should feel bad", diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index e05124677..ce427f2d0 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -91,6 +91,7 @@ def inject_constants(): "RENDER_DEPTH_LIMIT":RENDER_DEPTH_LIMIT, "SORTS_COMMENTS":SORTS_COMMENTS, "SORTS_POSTS":SORTS_POSTS, + "CSS_LENGTH_MAXIMUM":CSS_LENGTH_MAXIMUM, } diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 17fee71db..8b6035a9f 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -369,3 +369,12 @@ def filter_emojis_only(title, edit=False, graceful=False): if len(title) > 1500 and not graceful: abort(400) else: return title + +def validate_css(css:str) -> tuple[bool, str]: + ''' + Validates that the provided CSS is allowed. It looks somewhat ugly but + this prevents users from XSSing themselves (not really too much of a + practical concern) or causing styling issues with the rest of the page. + ''' + if '/css") -def get_css(username): - user = get_user(username) - resp=make_response(user.css or "") - resp.headers.add("Content-Type", "text/css") - return resp - @app.get("/@/profilecss") def get_profilecss(username): user = get_user(username) diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 975f39571..1b191e548 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -20,7 +20,7 @@ {% if v.css %} - + {% endif %} {% else %} diff --git a/files/templates/chat.html b/files/templates/chat.html index abf8785bc..1930226b7 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -19,7 +19,7 @@ {% if v.css %} - + {% endif %} {% endif %} {% else %} diff --git a/files/templates/log.html b/files/templates/log.html index 4e83fff10..5d4cbc7f9 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -9,7 +9,7 @@ {% if v.css %} - + {% endif %} {% else %} diff --git a/files/templates/settings.html b/files/templates/settings.html index 800a4b001..6bde7aeed 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -39,7 +39,7 @@ {% if v.css and not request.path.startswith('/settings/css') %} - + {% endif %} diff --git a/files/templates/settings_css.html b/files/templates/settings_css.html index 79410ef31..5e7189ce5 100644 --- a/files/templates/settings_css.html +++ b/files/templates/settings_css.html @@ -3,39 +3,27 @@ {% block pagetitle %}Custom CSS - {{SITE_TITLE}}{% endblock %} {% block content %} -
-
-
-
-

Edit your custom CSS for the site.

-
-
- - Limit of 4000 characters + + Limit of {{CSS_LENGTH_MAXIMUM}} characters
-
-
-
-
- {% endblock %} diff --git a/files/templates/settings_profilecss.html b/files/templates/settings_profilecss.html index 0738dfb81..b78496eaf 100644 --- a/files/templates/settings_profilecss.html +++ b/files/templates/settings_profilecss.html @@ -5,37 +5,26 @@ {% block content %}
-
-
-
-

Edit your profile css.

-
-
- - Limit of 4000 characters + + Limit of {{CSS_LENGTH_MAXIMUM}} characters
-
-
-
-
- {% endblock %} diff --git a/files/templates/submit.html b/files/templates/submit.html index ed77313fe..dc28fe5af 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -25,7 +25,7 @@ {% if v.css %} - + {% endif %} {% else %}