]> littlesong.place Git - littlesongplace.git/commitdiff
Add input limits
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 12 Jan 2025 21:05:49 +0000 (16:05 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 12 Jan 2025 21:05:49 +0000 (16:05 -0500)
main.py
templates/edit-song.html
templates/login.html
templates/profile.html
templates/signup.html

diff --git a/main.py b/main.py
index b3d0ba67a009e0fd2fa4c3ae2888461120258f8a..f1ac7da684202c0fcb57e4e33222e91c8f33b38d 100644 (file)
--- a/main.py
+++ b/main.py
@@ -26,6 +26,7 @@ DATA_DIR = Path(".")
 
 app = Flask(__name__)
 app.secret_key = "dev"
+app.config["MAX_CONTENT_LENGTH"] = 50 * 1024 * 1024
 
 @app.route("/")
 def index():
@@ -49,6 +50,9 @@ def signup_post():
     elif len(username) < 3:
         flash("Username must be at least 3 characters", "error")
         error = True
+    elif len(username) > 30:
+        flash("Username cannot be more than 30 characters", "error")
+        error = True
 
     elif password != password_confirm:
         flash("Passwords do not match", "error")
@@ -69,7 +73,9 @@ def signup_post():
     query_db("insert into users (username, password, created) values (?, ?, ?)", [username, password, timestamp])
     get_db().commit()
 
-    return render_template("login.html", note="User created.  Sign in to continue")
+    flash("User created.  Please sign in to continue.", "success")
+
+    return redirect("/login")
 
 @app.get("/login")
 def login_get():
@@ -218,17 +224,23 @@ def validate_song_form():
     if not title.isprintable():
         flash(f"'{title}' is not a valid song title", "error")
         error = True
+    elif len(title) > 80:
+        flash(f"Title cannot be more than 80 characters", "error")
+        error = True
 
     # Check if description is valid
     if not description.isprintable():
         flash(f"Description contains invalid characters", "error")
         error = True
+    elif len(description) > 10_000:
+        flash(f"Description cannot be more than 10k characters", "error")
+        error = True
 
     # Check if tags are valid
     tags = request.form["tags"]
     tags = [t.strip() for t in tags.split(",")]
     for tag in tags:
-        if not tag.isprintable():
+        if not tag.isprintable() or len(tag) > 30:
             flash(f"'{tag}' is not a valid tag name", "error")
             error = True
 
@@ -236,7 +248,7 @@ def validate_song_form():
     collaborators = request.form["collabs"]
     collaborators = [c.strip() for c in collaborators.split(",")]
     for collab in collaborators:
-        if not collab.isprintable():
+        if not collab.isprintable() or len(collab) > 31:
             flash(f"'{collab}' is not a valid collaborator name", "error")
             error = True
 
index d43068b6270c3967f3dda8a6d6f3fd964b6817ea..e935e629f5b0db5c57a380ebecf1b899b6f0b6ed 100644 (file)
     </div>
     <div class="upload-form">
         <label for="title">Title</label>
-        <input type="text" name="title" id="song-title" value="{{ song.title }}" required>
+        <input type="text" name="title" id="song-title" value="{{ song.title }}" maxlength="80" required>
     </div>
     <div class="upload-form">
         <label for="description">Description</label>
-        <textarea name="description">{{ song.description }}</textarea>
+        <textarea name="description" maxlength="10000">{{ song.description }}</textarea>
     </div>
     <div class="upload-form">
         <label for="tags">Tags</label>
-        <input type="text" name="tags" placeholder="country, extratone, vocals, ..." value="{{ ", ".join(song.tags) }}">
+        <input type="text" name="tags" placeholder="country, extratone, vocals, ..." value="{{ ", ".join(song.tags) }}" maxlength="350">
     </div>
     <div class="upload-form">
         <label for="collabs">Collaborators</label>
-        <input type="text" name="collabs" placeholder="@fren_user, John Doe, ..." value="{{ ", ".join(song.collaborators) }}">
+        <input type="text" name="collabs" placeholder="@fren_user, John Doe, ..." value="{{ ", ".join(song.collaborators) }}" maxlength="350">
     </div>
     <div class="upload-form">
         <input type="submit" value="Upload">
index 5d72bc8de5ccd8556755aa3ba6f6110b2810f85e..9f65f99545be0fed0d1ee93e21a29c6047bbf2b0 100644 (file)
 <form method="post" action="/login">
     <div class="login-form">
         <label for="username">Username</label>
-        <input type="text" name="username" required></input>
+        <input type="text" name="username" maxlength="30" required></input>
     </div>
 
     <div class="login-form">
         <label for="password">Password</label>
-        <input type="password" name="password" required></input>
+        <input type="password" name="password" maxlength="100" required></input>
     </div>
 
     <div class="login-form">
index 07fae6d17b8568df1d000caba6148f9773a1d88d..f80ca3b914c08a6e88e2d250530563e42eaef9fc 100644 (file)
@@ -18,7 +18,7 @@
     <h2> Edit Bio </h2>
     <p>Common HTML tags (&lt;a&gt;, &lt;b&gt;, &lt;i&gt;, &lt;img&gt;, etc.) are allowed.</p>
     <div class="profile-edit">
-        <textarea name="bio">{{ bio }}</textarea>
+        <textarea name="bio" maxlength="10000">{{ bio }}</textarea>
     </div>
     <div class="profile-edit">
         <a href="javascript:hideEditForm();">Cancel</a>
index ed7fc0eacf95973b398d163b6077ab2b7108471e..62bb675130f879216ef3719d2442d598ac33db98 100644 (file)
 <form method="post">
     <div class="signup-form">
         <label for="username">Username</label>
-        <input type="text" name="username" required></input>
+        <input type="text" name="username" maxlength="30"required></input>
     </div>
 
     <div class="signup-form">
         <label for="password">Password</label>
-        <input type="password" name="password" required></input>
+        <input type="password" name="password" maxlength="100" required></input>
     </div>
 
     <div class="signup-form">
         <label for="password_confirm">Confirm Password</label>
-        <input type="password" name="password_confirm" required></input>
+        <input type="password" name="password_confirm" maxlength="100" required></input>
     </div>
 
     <div class="signup-form">