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 = `\