Saltar al contenido
uencoder

Implementar CORS safely

CORS (Cross-Origin Resource Sharing) allows controlled cross-origin requests. Aprender a configure origins, métodos, headers, y credenciales safely.

  1. 1

    CORS allows a browser on one origin to request resources from another. The server responds with Access-Control-Allow-Origin (allowed origins), Access-Control-Allow-Methods (allowed HTTP methods), Access-Control-Allow-Headers (allowed request headers), and Access-Control-Allow-Credentials (whether cookies are allowed). Preflight requests (OPTIONS) check permissions before the actual request.

  2. 2
    Analizador de URL →

    Analizar the Origin header to validate the requesting origin. Compare against a whitelist of allowed origins. Never use Access-Control-Allow-Origin: * with Access-Control-Allow-Credentials: true — this is invalid and browsers will reject it. Echo the specific origin back: Access-Control-Allow-Origin: https://example.com.

  3. 3
    Calculadora de hash →

    For dynamic origin validation, hash the origin and compare against a set of allowed origin hashes. This avoids storing raw origins in configuration and allows O(1) lookup. Use SHA-256 for the hash. Alternatively, use a regex or prefix match for wildcard subdomains (*.example.com).

Preguntas frecuentes

Should I use CORS * (wildcard)?
Only for public APIs without credentials. With Access-Control-Allow-Origin: *, cookies are not sent (Access-Control-Allow-Credentials must be false), and all origins can access the API. For APIs with authentication or sensitive data, specify allowed origins explicitly. Never use * with credentials — browsers reject it.
What is a CORS preflight?
For "non-simple" requests (custom headers, methods other than GET/POST/HEAD, content type other than form/text), the browser sends an OPTIONS request first (preflight). The server responds with allowed methods, headers, and origin. If the preflight passes, the actual request is sent. Simple requests (GET with no custom headers) do not require preflight.

Flujos que resuelven esta tarea

Hash contenido y codificar como Base64
Calcular un hash de la entrada y codificar el resumen como Base64 para transporte compacto.
CANALIZACIÓN
Hash texto y verificar integridad
Calcular un hash del texto de entrada y compararlo con un hash esperado para verificar la integridad.
CANALIZACIÓN
Hash texto y verificar con suma CRC32
Calcular tanto un hash criptográfico SHA-256 como una suma de verificación CRC32 para verificación de integridad de datos.
CANALIZACIÓN
Hash MD5 y luego codificar en Base58
Calcular hash MD5 y luego codificar como Base58 para representación compacta.
CANALIZACIÓN
Comparación de velocidad multi-hash
Hash la entrada y comparar múltiples algoritmos de hash para comparar su velocidad y salida.
CANALIZACIÓN
Generar contraseña y hash
Generar una contraseña aleatoria y luego hash para almacenamiento seguro.
CANALIZACIÓN
Decodificar Punycode y analizar URL
Decodificar un dominio Punycode y luego analizar la URL completa.
CANALIZACIÓN
Hash SHA3-256 con suma CRC32
Calcular hash SHA3-256 y luego suma CRC32 para verificación dual de integridad.
CANALIZACIÓN
Hash SHA-512 y luego Hex
Calcular hash SHA-512 y luego codificar como Hex para legibilidad.
CANALIZACIÓN
Invertir texto y hash
Invertir texto y luego calcular el hash SHA-256 del resultado invertido.
CANALIZACIÓN
Mezclar texto y hash
Mezclar texto y luego hash del resultado mezclado.
CANALIZACIÓN
Decodificar URL y analizar
Decodificar URL y luego analizar la URL en componentes.
CANALIZACIÓN

Herramientas relacionadas