Use of Hard-coded, Security-relevant Constants
The product uses hard-coded constants instead of symbolic names for security-critical values, which increases the likelihood of mistakes during code maintenance or security reviews.
Hard-coded values make code harder to understand and maintain. When security-relevant values are hard-coded, it increases the risk of errors when the code needs to be modified.
Cómo corregir esta vulnerabilidad
Estrategias de prevención para Hardcoded Security Constants basadas en 2 reglas de detección de Shoulder.
Use environment variables for URLs with localhost as a development fallback
- const API_URL = 'http://localhost:3000'; + const API_URL = process.env.API_URL || 'http://localhost:3000'; const response = await fetch(`${API_URL}/users`);
Load URLs from environment variables with localhost as the development fallback
- API_URL = "http://localhost:3000/api" - DB_HOST = "127.0.0.1" + import os + + API_URL = os.getenv('API_URL', 'http://localhost:3000/api') + DB_HOST = os.getenv('DB_HOST', 'localhost') def fetch_data(): response = requests.get(f'{API_URL}/data') return response.json()
Prácticas clave
- Use environment variables
- configurable via environment variables
Encuentra vulnerabilidades en tu código
Usa Shoulder para escanear tu código en busca de patrones Use of Hard-coded, Security-relevant Constants. 2 reglas.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=547 # Or scan entire project npx @shoulderdev/cli trust .
Reglas de Detección (2)
Qué buscar en las revisiones de código
Estos patrones indican vulnerabilidades potenciales de Use of Hard-coded, Security-relevant Constants. Búscalos durante las revisiones de código y auditorías de seguridad.
Escanea tu base de código para Use of Hard-coded, Security-relevant Constants
Shoulder CLI encuentra patrones vulnerables en toda tu base de código.