diff --git a/anonstream/chat.py b/anonstream/chat.py index c30ce69..91e282c 100644 --- a/anonstream/chat.py +++ b/anonstream/chat.py @@ -62,14 +62,21 @@ def add_chat_message(user, nonce, comment, ignore_empty=False): raise Rejected('Message was empty') if len(comment.strip()) == 0: raise Rejected('Message was practically empty') - if len(comment) > 512: - raise Rejected('Message exceeded 512 chars') - if comment.count('\n') + 1 > 12: - raise Rejected('Message exceeded 12 lines') + if len(comment) > CONFIG['CHAT_COMMENT_MAX_LENGTH']: + raise Rejected( + f'Message exceeded {CONFIG["CHAT_COMMENT_MAX_LENGTH"]} chars' + ) + if comment.count('\n') + 1 > CONFIG['CHAT_COMMENT_MAX_LINES']: + raise Rejected( + f'Message exceeded {CONFIG["CHAT_COMMENT_MAX_LINES"]} lines' + ) linespan = get_approx_linespan(comment) - if linespan > 12: - raise Rejected('Message would span too many lines') + if linespan > CONFIG['CHAT_COMMENT_MAX_LINES']: + raise Rejected( + f'Message would span {CONFIG["CHAT_COMMENT_MAX_LINES"]} ' + f'or more lines' + ) # Record linespan linespan_tuple = (timestamp, linespan) diff --git a/anonstream/config.py b/anonstream/config.py index 4223ad2..376505d 100644 --- a/anonstream/config.py +++ b/anonstream/config.py @@ -117,9 +117,11 @@ def toml_to_flask_section_chat(config): cfg = config['chat'] return { 'CHAT_COMMENT_MAX_LENGTH': cfg['max_comment_length'], + 'CHAT_COMMENT_MAX_LINES': cfg['max_comment_lines'], 'CHAT_NAME_MAX_LENGTH': cfg['max_name_length'], 'CHAT_NAME_MIN_CONTRAST': cfg['min_name_contrast'], 'CHAT_BACKGROUND_COLOUR': color_to_colour(cfg['background_color']), + 'CHAT_TRIPCODE_PASSWORD_MAX_LENGTH': cfg['max_tripcode_password_length'], 'CHAT_LEGACY_TRIPCODE_ALGORITHM': cfg['legacy_tripcode_algorithm'], } diff --git a/anonstream/routes/nojs.py b/anonstream/routes/nojs.py index a40565d..772fbe3 100644 --- a/anonstream/routes/nojs.py +++ b/anonstream/routes/nojs.py @@ -92,6 +92,9 @@ async def nojs_chat_form(user): nonce=generate_nonce(), digest=get_random_captcha_digest_for(user), default_name=get_default_name(user), + max_comment_length=CONFIG['CHAT_COMMENT_MAX_LENGTH'], + max_name_length=CONFIG['CHAT_NAME_MAX_LENGTH'], + max_password_length=CONFIG['CHAT_TRIPCODE_PASSWORD_MAX_LENGTH'], ) @current_app.post('/chat/form') diff --git a/anonstream/static/anonstream.js b/anonstream/static/anonstream.js index 2392443..1c68be4 100644 --- a/anonstream/static/anonstream.js +++ b/anonstream/static/anonstream.js @@ -33,7 +33,7 @@ const jsmarkup_chat_users = `\ const jsmarkup_chat_form = `\
- +
@@ -55,10 +55,10 @@ const jsmarkup_chat_form = `\
Name: - + Tripcode: - +
diff --git a/anonstream/templates/nojs_chat_form.html b/anonstream/templates/nojs_chat_form.html index 67f8bf2..c759b0d 100644 --- a/anonstream/templates/nojs_chat_form.html +++ b/anonstream/templates/nojs_chat_form.html @@ -220,7 +220,7 @@ {% endif %} - +
{% if digest %} @@ -231,7 +231,7 @@
- + @@ -247,7 +247,7 @@ {% endif %}
- +
diff --git a/anonstream/user.py b/anonstream/user.py index 0edfa56..914f48f 100644 --- a/anonstream/user.py +++ b/anonstream/user.py @@ -93,8 +93,10 @@ def change_name(user, name, dry_run=False): if name is not None: if len(name) == 0: raise BadAppearance('Name was empty') - if len(name) > 24: - raise BadAppearance('Name exceeded 24 chars') + if len(name) > CONFIG['CHAT_NAME_MAX_LENGTH']: + raise BadAppearance( + f'Name exceeded {CONFIG["CHAT_NAME_MAX_LENGTH"]} chars' + ) else: user['name'] = name @@ -119,8 +121,11 @@ def change_color(user, color, dry_run=False): def change_tripcode(user, password, dry_run=False): if dry_run: - if len(password) > 1024: - raise BadAppearance('Password exceeded 1024 chars') + if len(password) > CONFIG['CHAT_TRIPCODE_PASSWORD_MAX_LENGTH']: + raise BadAppearance( + f'Password exceeded ' + f'{CONFIG["CHAT_TRIPCODE_PASSWORD_MAX_LENGTH"]} chars' + ) else: user['tripcode'] = generate_tripcode(password) diff --git a/config.toml b/config.toml index f9402dc..ff4b3ea 100644 --- a/config.toml +++ b/config.toml @@ -53,9 +53,11 @@ anonymous = "Anonymous" [chat] max_comment_length = 512 +max_comment_lines = 12 max_name_length = 24 min_name_contrast = 3.0 background_color = "#232327" +max_tripcode_password_length = 1024 legacy_tripcode_algorithm = false [flood.messages]