SMS verification in Decidim with your own gateway

Learn how SMS code verification fits a self-hosted Decidim platform, what a custom gateway class must do, and where provider, storage and cost decisions matter.

On this page

When SMS verification in Decidim fits your participation process

SMS verification fits when you need proof that a participant controls a phone number, and you can accept that a phone number is a weaker identity signal than a census or a document. A public body or organization running a self-hosted Decidim instance decides this in Decidim's authorization system, where each verification method is registered and then attached to the actions it protects, such as voting or signing. SMS is one route among several. The gateway that delivers the code is your own choice of provider, configured in your infrastructure, so the decision covers both the verification method and the vendor that sends the messages on your behalf.

SMS is usually proportionate when the participation process is open to a broad public, when you want a low-friction step for residents who have no census record, and when the consequence of a fake account is limited, for example a single supporter signature or a non-binding survey. It is a poor fit when the vote carries binding weight, when one person could easily hold several SIM cards or phone numbers, or when your users are unlikely to have a mobile phone in their own name. In those cases, a census authorization, document-based verification or postal code verification gives you a stronger link to a person or a place. Many organizations combine methods, using SMS for a broad first step and a stronger method for higher-stakes components, which you configure per component.

Before you commit, confirm three things with your legal and security teams and with the provider you are considering: whether your jurisdiction accepts phone-based verification for the decision you are taking, how the provider handles messages and sender identity in the countries your participants live in, and whether you can store phone numbers in hashed form and delete them on your retention schedule. Ask the provider for its delivery and sender terms in writing, and test a full flow with real devices in each country you serve before a process opens.

How SMS compares with other Decidim verification routes

When a process is open to anyone who wants to comment or suggest ideas, the main goal is to slow down bulk accounts and make it harder for one person to act many times. An SMS code gives a modest signal: the participant controls a phone number that has not been used on another account. It does not prove who the person is, and it does not prove they live in the area. For many open debates, that trade-off is reasonable, especially when paired with the email confirmation Decidim already performs.

  • Assurance level: A phone code shows possession of a number, not identity. It is weaker than an identity document check and usually weaker than a census match.
  • Duplicate control: Storing a hashed phone number lets you block a second account on the same number without keeping the number in readable form.
  • Cost per message: Every code sent is a billable message, so an open process with heavy traffic or repeated resends can grow your provider bill quickly.
  • Phone ownership: Some participants share numbers, use prepaid SIMs, or have none. Ask whether an alternative route is available for them.

Before you choose SMS for an open process, confirm with the process owner which actions need verification and whether comments or only votes must be restricted.

How the SMS code flow works inside Decidim

The SMS code flow has four steps: the participant enters a phone number, the platform generates a one-time code and hands it to your gateway class, the participant types the code back into the form, and the platform records a successful authorization against their account. The gateway is the only part that talks to a telephone network. Everything around it, including code generation, comparison and the record of the result, runs inside Decidim's authorization workflow. Confirm in the installed release how the verification form, the code check and the stored authorization are wired together, since the names of the form objects and the authorization record are implementation details that can change between minor versions. Check them against the code of the version you run, not against memory of an older one.

Sending the message is not guaranteed to happen during the web request. Production setups of Decidim configure background jobs through ActiveJob, and the delivery call to your provider is a good candidate for that path, so a slow or failed carrier response does not hold the participant's browser open. The consequence is that a participant can see a success message before any text arrives. Plan for the failure path explicitly: a job that errors, a provider that rejects the number, a message that never reaches the handset. Decide what the participant sees in each case, whether they can request another code, how many retries your provider allows, and where failed deliveries are logged so your support team can trace them. Verify how the installed release retries or surfaces a failed job before you promise participants a fixed behavior.

Because the code arrives on a separate channel, the record of success should only be written after the submitted code matches the one issued for that phone number and has not expired. Confirm in your release whether the code expires on a timer, and how long a pending code remains valid before a new one replaces it. Ask your provider how delivery receipts are returned, since a status callback is useful for support but does not replace the code check. Test the full path in a staging instance with a provider sandbox or a test number before the first live process opens, and record the results so you can show the sequence to your security reviewers.

Request flow from phone entry to recorded authorization

The flow starts when a participant enters a phone number in the Decidim web app, which stores only a hashed phone and an attempt counter in PostgreSQL. The web app queues a background job so the request does not wait on the network, and the job runs the custom SMS gateway class. That class is the only step that leaves the organization's infrastructure, sending a code request to the external SMS provider, which delivers the code to the phone. When the participant submits the code, check the attempt counter, the lock state and the recorded authorization in that order.

Request path from phone entry to recorded authorization, with the provider boundary marked.

Configuration choices for the gateway and storage

This table compares the main configuration choices for an SMS verification gateway in Decidim: provider model, where the gateway class lives, code lifetime, resend limits, phone storage and lockout thresholds. Read each row for the situation where it fits and the ongoing effort it adds, then settle the choices with your legal and security reviewers before writing code.

ChoiceOption and trade-offWhen it fitsOperational effort
Provider modelDirect carrier API: more contracts and sender registrations to manage, but fewer intermediaries in the message pathSingle country or a small number of carriers, with a team ready to handle carrier onboardingHigher: each carrier relationship needs its own credentials, delivery reporting and escalation path
Provider modelAggregator: one API across many carriers, with the aggregator passing on delivery rules and feesMulti-country audiences or uncertain carrier mix during a processLower integration work, but you must track the aggregator's terms, sender ID rules and incident contacts
Gateway class placementCustom module that implements the SMS gateway interface and is registered in the Decidim configurationAny production deployment, so upgrades and vendor changes stay outside core Decidim codeModerate: the module needs tests and must be reviewed at each Decidim upgrade
Code length and expiryShort numeric codes with a short validity window, which limits guessing but raises support requests if messages arrive lateProcesses with high traffic and a clear help path for participantsLow to set up; watch complaints about delayed messages and adjust with your provider's delivery data
Resend limitsStrict per-number and per-session resend caps reduce SMS spend and abuse, while stricter caps increase lockout ticketsPublic votes or signatures where message volume can be abusedLow to configure; requires monitoring so legitimate participants are not blocked for long
Phone storageSalted hash: you can check a number matches but cannot read it back, which fits a data minimization positionMost public participation platforms with strict data protection reviewModerate: you cannot recover a number for support, so the support process must rely on other evidence
Phone storageReversible form: you can display or export numbers and send support messages, but a breach exposes more personal dataCases where staff must contact participants directly and the legal basis is documentedHigher: encryption key management, rotation and access logging must be designed and tested
Lockout thresholdsFewer failed attempts before lock reduces brute-force risk, while more attempts reduce false lockouts for people who mistypeSensitive authorizations such as voting in a budgetModerate: needs an unlock path, administrator visibility and a written support script

Setting up SMS verification step by step

This sequence takes a Decidim instance from a confirmed version and toolchain to a tested SMS authorization that can be enabled on a live organization without exposing phone numbers or allowing unlimited code guessing.

  1. Confirm the Decidim version and toolchain

    Your team confirms which Decidim minor version the platform runs, then checks the Ruby and Node versions that version requires. Decidim v0.32 requires Ruby 3.4.7 and Node 22.14.x, while v0.31 uses Ruby 3.3.4 and Node 22.14.x, so the build environment must match the target branch. Confirm the PostgreSQL version against the installation guide for your operating system. The check is a clean run of the application's test suite and a successful local boot on the same versions as production.

  2. Create a custom module and gateway class

    A developer generates a custom Decidim module outside the core codebase and adds a gateway class that sends one-time codes through your chosen SMS provider. The class should accept a phone number and a code, return a clear success or failure result, and log errors without writing full phone numbers or codes to logs. Keep the provider SDK and its calls inside this class so the rest of the authorization flow stays provider-neutral. The check is a unit test that stubs the provider and confirms the class builds the expected request.

  3. Register the authorization workflow

    The developer registers a new authorization workflow in the custom module so Decidim offers SMS verification as a method on the authorization screens. The workflow defines the form fields, the phone step, the code entry step and the handler that marks the user as verified once the code matches. Confirm the registration against the module structure used by the Decidim version you run, since the authorization API changes between releases. The check is that the method appears in the admin authorization list after the module is loaded.

  4. Configure provider credentials through the environment

    Your platform team stores the provider account identifier, API key and sender details as environment variables or in the secrets manager your Rails deployment already reads, never in the repository or in the admin interface. Document which variables exist, who can rotate them and where they are set for staging and production. The check is that the application starts with the variables present, and that removing one causes the gateway to fail closed with a logged error rather than sending anything.

  5. Set hashed phone storage and failed-attempt locks

    The developer stores a keyed hash of each phone number and of each issued code, with expiry times and an attempt counter tied to the pending verification. After a set number of wrong codes, the workflow locks that attempt and requires a new request, and repeated requests from one identity are rate limited. Decide the thresholds with your security and privacy owners, because they depend on your risk model and the cost of each message. The check is a test that confirms the database holds no plain phone numbers or codes and that the lock triggers at the configured count.

  6. Enable the method on a test organization

    An administrator enables the SMS authorization on a test organization that mirrors production settings, then attaches it to a non-public test component so you can see exactly which actions require it. Confirm the wording of the verification screens and the messages participants see when a code is wrong, expired or locked. The check is a completed verification by a test account using a real handset that your team controls, followed by a visible verified badge on that account.

  7. Test delivery and lockout before a process opens

    Your QA team runs the full path with multiple test numbers: successful delivery, delayed delivery, an invalid number, an expired code, repeated wrong codes and a request after lockout. They also test the same phone number used by two accounts to confirm the conflict behavior, and they review logs for leaked personal data. Record the results and fix anything that fails before the process goes live. The check is a signed-off test record that covers every path, with the provider's delivery reports reviewed alongside the application logs.

Protecting phone numbers, codes and provider credentials

An SMS verification flow stores personal data, issues codes that can be guessed, and holds credentials that can be abused for billing fraud. The cards below cover the controls to design before launch, and each one has a concrete check you can run against your own Decidim instance.

Hash phone numbers and codes

Store phone numbers and one-time codes as keyed hashes rather than plain text, so a database leak does not expose a list of verified mobile numbers or live codes. Codes are short and easy to guess, so the hash alone is not enough; pair it with expiry and attempt limits. Check that the verification record keeps only what the matching step needs, and that the hashing key is stored outside the database.

Lock out brute force and SMS pumping

Two abuse patterns hit this flow: guessing a six-digit code by repeated attempts, and triggering many messages to premium or unwanted numbers to run up provider charges. Limit failed code attempts per record and per phone number, and cap send requests per IP address and per number over time. Test both limits in staging with your provider's sandbox before a vote opens, and confirm who is alerted when a threshold trips.

Keep provider keys out of code

Gateway credentials such as API keys, account identifiers and sender settings give anyone who holds them the ability to send messages on your account. Load them from environment variables or a secrets manager, never from files committed to the repository or from the admin interface. Restrict the key to sending only, rotate it on staff changes, and confirm which secrets are visible to administrators with the Decidim admin role.

Log events without numbers

Application logs, error trackers and background job records often capture full request parameters, which can include a phone number. Filter the phone field and the code from logs and exception reports, and log only an event type, a timestamp and a masked or hashed identifier. Check your Rails log filter settings and the output of a failed send, because provider error messages sometimes echo the destination number.

Set retention for phone records

Phone numbers used for verification are personal data, and the verification record may outlive the vote that needed it. Decide how long unverified attempts and verified phone records are kept, delete expired codes on a schedule, and document the period in your privacy notice. Confirm with your data protection officer whether the verified number must be kept to prevent the same number from verifying twice.

Report issues through the disclosure process

If you find a flaw in the verification code or the gateway integration that may affect other Decidim sites, report it privately rather than in a public issue. Decidim accepts security reports at security@decidim.org or through GitHub Security Advisories, and asks implementers to allow time to apply patches before details are disclosed. Keep your own contact details current so the project can reach your team during that window.

Standard patch window
2 months
Decidim security policy

Questions buyers ask before building SMS verification

What does building SMS verification in Decidim cost, and what drives it?

The cost is mostly labor, plus the provider's per-message charges that recur for as long as the verification runs. The labor covers writing the gateway class, hashed phone storage, failed-attempt locks, staging tests with real messages, and a review of how the sender and message text are handled. Cost rises with the number of countries you must reach, the number of message routes, how much of the verification flow must change from Decidim's defaults, and how many people must review the work before go-live. Ask for a fixed-scope quote that lists each of these items separately, so one-time build work and recurring message charges can be compared on their own. DeployOpen does not publish prices, and the quote follows from the written scope.

How long does it take to write and test an SMS gateway class?

The duration depends on the provider's API, the number of code paths and the test coverage your organization expects, so confirm it against a written scope rather than a generic estimate. The gateway class itself is usually the smaller part. Most of the time goes into error handling for delivery failures and timeouts, testing against the provider's sandbox or a low-volume test account, and checking that codes expire and cannot be reused. Ask whether the plan includes a staged rollout in a non-production Decidim instance and a retest after any change to the provider or to Decidim itself.

What must the organization provide before SMS codes can be sent?

The organization must supply the commercial and legal inputs that DeployOpen cannot provide on its behalf. These usually include:

  • An account with an SMS provider, with credentials that the platform can use from its production environment.
  • Sender registration or sender ID approval for each country where codes will be sent, as the provider and local rules require.
  • A legal review of how phone numbers are collected, stored and used for verification, aligned with your data protection rules.

Also confirm who receives the provider invoices and who holds the credentials. These items often take longer to resolve than the code, so start them early and ask your provider to confirm current requirements in writing.

Can our internal team build the SMS gateway without a partner?

Yes, if your team already maintains Ruby on Rails applications and can handle secrets, background jobs and production logging. The work needs someone who understands Decidim's authorization handler structure, can test failure paths, and can document how to rotate provider credentials. Internal teams often underestimate the operational work: monitoring delivery rates, responding to provider outages, and keeping the code working through Decidim upgrades. Ask yourself whether that work will have an owner after launch. If the answer is uncertain, a partner can build the gateway and hand over documentation and tests, or stay on a retainer for support.

How does per-message cost grow with participants and resends?

Per-message cost scales with the number of codes sent, not the number of participants, so every resend, failed attempt and retry adds to the bill. A participant who requests codes several times, or a bot that triggers repeated sends, can multiply the charges. Each country and route may also carry a different rate. To control this, ask for rate limits per phone number and per session, a cap on resends within a time window, and a dashboard or report of sent, delivered and failed messages. Request the provider's current price sheet for each target country in writing, because prices change and are set by the provider, not by DeployOpen.

How do Decidim upgrades affect a custom SMS gateway?

Upgrades can change the code that the gateway depends on, so a custom gateway needs to be retested with every Decidim minor version. Decidim's update guide asks you to move one minor version at a time and to follow each release's upgrade instructions, because some releases change database structures. Decidim v0.32.0 requires Ruby 3.4.7, while v0.31 uses Ruby 3.3.4, so the runtime may also change. Keep the gateway in its own module with tests, record which Decidim version it was built against, and include a staging upgrade with a live test message in every upgrade plan. Confirm with your partner how security patches on the 0.31 and 0.32 branches will be applied to the gateway.

Does SMS verification protect against fraud on its own?

No. SMS codes confirm that someone controls a phone number at a given moment, but they do not prove identity, and they can be intercepted or rented. Treat SMS as one signal and combine it with the other methods your organization uses, such as document checks or census lists, when votes or signatures carry weight. Ask for hashed phone storage so the platform never keeps raw numbers in readable form, and for lockouts after repeated failures. Confirm with your security reviewers which residual risks remain acceptable for each process.

Limits to confirm in your environment

An SMS gateway is only as good as the provider, the release and the countries it serves. The cards below list the limits that most often surprise teams, and who to ask about each one before the build is scoped.

Provider coverage in target countries

Not every SMS provider delivers to every country, and routes into some countries depend on local carrier agreements. Ask the provider in writing which destination countries and mobile networks your participants use, and whether delivery is direct or through a third-party aggregator. Ask whether sender registration is required in any of those countries, since an unregistered route can be blocked without notice. Confirm this with your procurement team and the provider's sales or compliance contact before you choose the gateway class.

Sender ID rules

Many countries restrict the alphanumeric sender name that appears on a text message, and some require a fixed number or a pre-approved identifier. A code that arrives from an unexpected sender may be filtered by the participant's phone or ignored by them. Ask your provider which sender IDs are allowed for each country, how long approval takes, and whether the text template must match an approved wording. Your communications or legal team should review the message text before launch.

Hooks in your installed Decidim release

The gateway class you write depends on the authorization and verification hooks in the exact Decidim version you run, and those interfaces change between minor releases. Check the release notes and the upgrade guide for your version, and confirm with your Decidim developer that the authorization workflow you plan to extend is present and unchanged. Versions outside the supported branches receive no security updates, so this check also affects your patch plan.

Decidim releases

Delivery latency

A verification code is only useful if it arrives while the participant is still on the page, and code expiry must allow for the delay. Ask the provider for its delivery reporting, typical delivery times per country, and what the callback or status data contains. Your team should test with real handsets on each main carrier, and decide how long the code stays valid so that slow deliveries do not look like failed verifications.

Fraud exposure from SMS pumping

Attackers can trigger large volumes of codes to premium-rate numbers and collect revenue from the traffic, and public-facing forms are common targets. Rate limits per IP address, per phone number and per session reduce that exposure. Ask your provider whether it offers country-level blocks, anomaly alerts and spend caps, and ask your security team to test the endpoint with automated requests before the process opens. Your own gateway configuration determines how much of this protection you carry.

Access for participants without mobile phones

Some residents have no mobile phone, share a number with a family member, or use a prepaid line that does not receive messages from certain senders. An SMS-only flow excludes them from any action that requires verification. Decide with your governance team which alternative methods remain available, such as document review or postal codes, and confirm with them that the chosen fallback meets your participation rules. Check that the flow works with screen readers and in the languages your participants use.

Running SMS verification after launch

Once the gateway class is live, the work shifts to watching it. Treat delivery failures and lockouts as operational signals, not user complaints. Log provider responses for each send (accepted, rejected, timed out) without writing full phone numbers or codes into logs, and set alerts on sustained rises in failed sends and on the failed-attempt lock counts your gateway class records. A spike in locks often means either a provider delivery problem or an attack on a process that opens to many participants, so the on-call team needs a runbook that tells them which of the two they are looking at before they change any settings. Confirm with your provider which delivery receipts it can return, since that determines how much of the failure picture you can see from your side.

SMS providers change their APIs, retire endpoints, alter authentication schemes and adjust sender registration rules. Assign one owner to track provider change notices and to test the gateway against the provider's sandbox or a low-volume test account whenever those notices arrive. Rotate the provider credentials on a schedule your security team approves, and store the new values in your secrets manager rather than in the repository, updating the configuration in each environment in a planned window. Check that the old credentials are revoked after the switch, and record who approved each rotation so that the audit trail covers the gateway as well as the application.

The upgrade path matters most here. Decidim's update guidance says to move one minor version at a time, for example 0.29 to 0.30 before 0.31, to follow each release's upgrade instructions because some changes alter database structures, and to back up the database first. Your custom gateway depends on Decidim's authorization hooks, so treat each minor step as a reason to retest the full SMS flow in staging: request a code, enter it, hit the lock after repeated failures, and confirm hashed phone storage still works on migrated data. Keep the Decidim update documentation with your runbook, and do not schedule a production upgrade until the gateway passes those checks on a restored backup.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.