Portal Community

What Atlas Forms Does Automatically

LayerWhat It DoesWhere Applied
Type coercionCoerces numeric fields to numbers, dates to ISO strings — prevents type confusion attacksAll input controls
Whitespace trimmingTrims leading/trailing whitespace from text values before validationtext, email, url
HTML sanitisationDOMPurify sanitises HTML content in html and article display controlsDisplay controls only
maxLength enforcementEnforces maxLength at the input level (HTML attribute) and in validationtext, textarea, password
Number boundsEnforces min/max on number inputs — rejects out-of-range valuesnumber control
File type/size checkValidates MIME type and file size before uploadfile-upload control

What You Must Do on the Server

Client-side validation is trivially bypassable. Every submitted value must be re-validated server-side before use:

OWASP Input Validation Alignment

OWASP ThreatClient-Side MitigationServer-Side Requirement
SQL InjectionPattern validation blocks common SQL characters; advisory onlyParameterised queries (mandatory)
XSS via form inputDOMPurify on display controls; inputs stored as data not rendered HTMLHTML-encode on output; Content-Security-Policy header
Path TraversalPattern rule blocks ../ sequences in filenamesServer normalises and validates all file paths
Mass AssignmentForm schema defines exactly which fields are submittedAllowlist permitted fields in the API layer
Oversized Input (DoS)maxLength and maxFileSizeMb limitsServer enforces identical limits
Integer Overflowmin/max validation on number fieldsServer validates numeric ranges before use

Security-Aware Pattern Examples

// Block common SQL injection patterns
{
  "id": "search-term",
  "type": "text",
  "label": "Search",
  "validation": {
    "maxLength": 200,
    "pattern": "^[^;'\"\\\\<>]*$",
    "patternMessage": "Search term contains disallowed characters"
  }
}

// File name — no path traversal
{
  "id": "filename",
  "type": "text",
  "label": "File Name",
  "validation": {
    "required": true,
    "maxLength": 255,
    "pattern": "^[A-Za-z0-9_\\-\\.]+$",
    "patternMessage": "Only letters, numbers, underscores, hyphens and dots allowed in file names"
  }
}

// Strict numeric ID — no injection possible
{
  "id": "record-id",
  "type": "number",
  "label": "Record ID",
  "settings": { "precision": 0 },
  "validation": {
    "required": true,
    "min": 1,
    "max": 2147483647
  }
}

Registering Security Validators

import { registerValidator } from '@atlas-forms/validation-js';

// Reject values that contain HTML tags
registerValidator('noHtmlContent', (value) => {
  const hasHtml = /<[^>]+>/.test(String(value ?? ''));
  return {
    valid: !hasHtml,
    message: 'HTML markup is not allowed in this field'
  };
});

// Reject common SQL injection patterns
registerValidator('noSqlInjection', (value) => {
  const sqlPattern = /('|--|;|\/\*|\*\/|xp_|EXEC|DROP|INSERT|UPDATE|DELETE|SELECT\s+\*)/i;
  const hasSql = sqlPattern.test(String(value ?? ''));
  return {
    valid: !hasSql,
    message: 'Input contains disallowed characters or keywords'
  };
});
Never Rely on Client-Side Validation for Security Any user with browser DevTools can bypass all client-side validation. Security-critical rules (ownership checks, rate limits, authorisation) must always be enforced on the server. Use client-side validation to improve user experience, not to enforce security boundaries.