luckyframework / luckyframework/lucky
CSRF input randomly disappears
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 2.7k
- Forks
- 172
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I have a lucky app running in a docker container on Digital Ocean.
Every once in awhile the csrf input field disappears. The result is a 403 error if you try to submit the form.
This has happened multiple times, and each time it is easily resolved by restarting the container.
To Reproduce
Steps to reproduce the behavior: unknown
I'm collecting a bunch of telemetry using DataDog and have a test that tries to log into the website every hour from three different regions within the U.S on chrome and firefox. This is currently how I am monitoring the problem so I can restarted the sever before it impacts users.
Versions (please complete the following information):
- Lucky version (check in shard.lock): 0.25.0
- Crystal version (
crystal --version): 0.35.1 - Docker Image: alpine
- OS: Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-65-generic x86_64)
Additional context
I don't know if the two csrf meta tags are also missing, because I didn't know they existed in the first place.
The error might occur within a few days to a couple of weeks after the last deployment.
- This last incident occurred on March 15th, 16 days after the last deployment.
- The previous incident occurred Feb 18th, 2 days after the last deployment.
System metrics
The docker image is deployed on Digital Ocean with 2GB memory and 25 GB disk on Ubuntu 20.04.2
On the host: memory remains at a constant 60%, CPU hangs out at below 5%, and disk I/O is in the kB/s range. The only anomaly at the time of failure is a small spike in network traffic (300kB vs the usual 122 kB).

I assume the spike in CPU is related to the increased network traffic.

The actual docker container has no anomalies in CPU, memory, disk I/O, or network I/O.
Dockerfile
Because the error occurs randomly it's possible it is related to some service or package on the container or host that is out of date. Here's my docker file for context. Compilation all happens in docker containers so result is reproducible.
# STAGE 1: Use node env to build node dependencies
FROM node:alpine as node_build
WORKDIR /tmp_build
# Install node packages in image
COPY package.json .
COPY yarn.lock .
RUN yarn install --no-progress --frozen-lockfile
# Compile assets with webpack
COPY public ./public
COPY webpack.mix.js .
COPY src ./src
RUN yarn prod
# STAGE 2: Use crystal env to build crystal dependencies
FROM crystallang/crystal:0.35.1-alpine as lucky_build
ENV SKIP_LUCKY_TASK_PRECOMPILATION="1"
WORKDIR /tmp_build
COPY shard.* ./
RUN shards install --production
COPY . .
COPY --from=node_build /tmp_build/public/mix-manifest.json public/mix-manifest.json
RUN crystal build --static src/start_server.cr
RUN crystal build --static tasks.cr -o run_task
# FINAL: actual image with app binary and static assets
FROM alpine
RUN addgroup -g 1000 -S lucky && \
adduser -u 1000 -S lucky -G lucky
WORKDIR /home/lucky/app
COPY --chown=lucky:lucky --from=node_build /tmp_build/public public
COPY --chown=lucky:lucky --from=lucky_build /tmp_build/start_server start_server
COPY --chown=lucky:lucky --from=lucky_build /tmp_build/run_task run_task
RUN chown -R lucky /home/lucky
USER lucky
CMD ["/home/lucky/app/start_server"]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked src/lucky/tags/forgery_protection_helpers.cr code and the reported Dockerfile, then inspect how the CSRF input is rendered in the deployed application. Reproduce the missing field if possible using the listed Lucky and Crystal versions, and consider the issue resolved when the cause is identified and the input no longer disappears under the reported deployment conditions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal, docker
- Domain
- backend, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100