# Use of Hard-coded, Security-relevant Constants (CWE-547) 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. **Stack:** JavaScript - Prevalence: 聚焦 覆盖 2 种语言 - Impact: 中 建议审查 - Prevention: 已记录 2 个修复示例 **OWASP:** Security Misconfiguration (A05:2021-Security Misconfiguration) - #5 ## Description 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. ## Prevention 基于 1 条 Shoulder 检测规则的 Hardcoded Security Constants 预防策略。 ### Key Practices - Use environment variables ### JavaScript Use environment variables for URLs with localhost as a development fallback ## Warning Signs - [LOW] Hardcoded development URL found: ... Development URLs like localhost should be configured via environment variables. - [LOW] hardcoded development URLs (localhost, 127 ## Consequences - 修改应用程序数据 - 读取应用程序数据 ## Mitigations - 对安全相关的值使用命名常量或配置 - 记录所有安全常量的含义和用途 - 集中管理安全配置 ## Detection - Total rules: 2 - Languages: javascript, typescript, python ## Rules by Language ### Javascript (1 rules) - **Hardcoded Development URLs** [LOW]: Detects hardcoded development URLs (localhost, 127.0.0.1) in production code that should use environment variables. - Remediation: Replace hardcoded URLs with environment variables: Before: const API_URL = 'http://localhost:3000'; After: const API_URL = process.env.API_URL || 'http://localhost:3000'; For database connections: Before: host: 'localhost' After: host: process.env.DB_HOST || 'localhost' ### Typescript (1 rules) - **Hardcoded Development URLs** [LOW]: Detects hardcoded development URLs (localhost, 127.0.0.1) in production code that should use environment variables. - Remediation: Replace hardcoded URLs with environment variables: Before: const API_URL = 'http://localhost:3000'; After: const API_URL = process.env.API_URL || 'http://localhost:3000'; For database connections: Before: host: 'localhost' After: host: process.env.DB_HOST || 'localhost'