zorn

zorn

Any best practice to limiting an Ecto `:text` database column for security/performance reasons?

I have a simple User-like Ecto schema backed up by a PostgreSQL database. There is a :bio field that is of type :text. I have other fields for things like :first_name of type :string and I’ve started adding validations like

validate_length(:first_name, max: 255)

to make sure any changesets are more honest about expectations. I’m considering something similar for the :bio field but wanted to ask for guidance.

Any thoughts? Is it a good idea to put some cap on the content length to help with abuse, security or performance concerns?

Most Liked

harmon25

harmon25

Probably not if it was just a performance concern, as it likely won’t actually be…

However,
If your threat model includes malicious actors trying to run you out of disk via that ‘bio’ field, a length check in the changeset would be reasonable. It’s important to communicate that up front when a user starts filling it in so they don’t get cut off early.

The security of the field/contents is also more of a frontend concern, does the bio contain HTML or some encoding that may introduce XSS or other code exec vulnerabilities? If so, some form of sanitization is required for sure…

Depending on the front end tech in place, and if it is sanitizing strings before writing to DOM (eex,react) by default AND the field is just text, could rely on the rendering engine to sanitize the bio field of potentially malicious HTML/JS…

A layered defense is always the best approach though. And performing some sort of threat model to understand whom you are defending against is important when making these kinds of decisions…

Good luck!

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

We're in Beta

About us Mission Statement