Hardcoded credentials

Also known as: hard-coded secrets

On this page 8

Hardcoded credentials, also called hard-coded secrets, are passwords, API keys, tokens, connection strings or private keys embedded directly in source code, scripts, workflow definitions or configuration files instead of being retrieved at run time from a protected store. Anyone who can read the artifact, its version history or its exported copy can read the secret.

In automation security, hardcoded credentials are one of the most common and most damaging weaknesses, because automated workflows often run with broad, long-lived privileges and are copied, shared and exported far more freely than application code. The weakness is listed as CWE-798, use of hard-coded credentials.

Why hardcoded credentials appear in automation

Hardcoded credentials appear because embedding a secret is the fastest way to make a workflow run. A developer testing an RPA bot, a low-code flow or a scheduled script pastes a password into a variable, the job works, and the temporary shortcut becomes permanent once the automation reaches production.

Automation platforms add specific pressures. Citizen developers may not know that a connector supports managed connections, older tools may lack a credential vault integration, and teams copying a workflow between environments often duplicate the secret along with the logic. The table below lists typical hiding places.

LocationTypical exampleWhy it is risky
Script source codePassword assigned to a variable in a PowerShell or Python jobCopied into repositories and backups
Workflow definitionsAPI key typed into an HTTP action of a low-code flowExported with the flow and visible to editors
Configuration filesConnection string in an application settings fileOften committed or shared by email
RPA bot packagesLogin typed into a recorded screen stepBot packages are distributed to many machines
Container imagesToken baked into an image layerLayers persist even after a later deletion
CI/CD pipeline filesCloud key in a pipeline definitionVisible to every contributor with read access
Where hardcoded credentials are commonly found

How attackers exploit embedded secrets

Attackers exploit hardcoded credentials by searching artifacts that are easier to obtain than the target system itself. Public and internal code repositories, leaked backups, shared workflow exports and decompiled binaries are scanned automatically with pattern-matching tools that recognize key formats within minutes of exposure.

Version history is the hidden danger. Deleting a secret in a later commit does not remove it from earlier commits, forks or clones, so a credential that was ever committed must be treated as compromised. Because automation accounts frequently hold administrative or cross-system permissions, one leaked key can open many systems at once and support lateral movement.

Hardcoded secrets also defeat accountability. When the same embedded password is used by several workflows and people, logs cannot show who acted, and rotating the password breaks every copy simultaneously, which discourages rotation altogether.

Secure alternatives to hardcoding

The secure alternative is to retrieve secrets at run time from a system designed to protect them, or to remove static secrets entirely through identity-based authentication. The table compares the main options.

ApproachHow it worksMain trade-off
Credential vaultWorkflow fetches the secret from a protected store at run timeAdds a dependency on vault availability
Managed connectionsPlatform stores the credential and exposes only a connection referenceRequires careful sharing permissions
Workload identityCloud identity issues short-lived tokens with no stored secretLimited to supporting platforms
Environment variablesSecret injected into the process at startCan leak through logs and crash dumps
OAuth delegated tokensScoped tokens with refresh and revocationToken lifecycle must be managed
Alternatives to hardcoded credentials

Environment variables are better than literals but remain a weak control on their own, because they are readable by any process with the same privileges. Short-lived, scoped tokens issued to a non-human identity are generally the strongest option where the platform supports them.

Detecting hardcoded credentials

Detection relies on secret scanning, which combines regular expressions for known key formats, entropy analysis for random-looking strings and validation calls that test whether a found key is still active. Scanning works best at several points in the life cycle.

  • Pre-commit hooks stop secrets before they reach a shared repository.
  • Repository and pipeline scanning reviews every push and the full history.
  • Workflow export scanning inspects low-code and RPA packages that never enter a code repository.
  • Image and artifact scanning checks container layers and build outputs.
  • Automation inventory reviews pair each workflow with its owner and credential source.

Scanners produce false positives and false negatives. Test fixtures and sample values trigger alerts, while custom password formats may pass unnoticed, so findings need triage by someone who understands the workflow.

Responding to an exposed credential

When a hardcoded credential is found, the correct response is to revoke and rotate first, then clean up. Removing the string from the current file without rotating leaves the secret valid in history, backups and every copy already distributed.

StepActionPurpose
ContainRevoke or disable the credential immediatelyStops further misuse
InvestigateReview audit logs for use since the exposureIdentifies possible compromise
ReplaceIssue a new secret stored in a vault or managed connectionRestores service securely
RefactorChange the workflow to fetch the secret at run timePrevents recurrence
Clean historyPurge the value from repositories and exports where feasibleReduces residual exposure
Response steps for an exposed secret

Common misconceptions

  • A private repository is not a safe place for secrets, because access lists grow and repositories are cloned, mirrored and backed up.
  • Encoding is not encryption: Base64 or simple obfuscation is reversed instantly.
  • Compiled code still exposes strings, which decompilers and simple string extraction recover easily.
  • Test credentials matter when test systems share networks, data or identity providers with production.

Governance closes the gap that tools leave. An automation center of excellence can require credential vault usage in design standards, include secret checks in automation change control and verify credential sources during periodic automation access reviews.

Stripped to the essentials

A hardcoded credential is like writing your house key code on the front door. The program works, but anyone who sees the program also sees the password.

The safer habit is to keep passwords in a locked, managed store and let the program ask for them only when it needs them. Then the password can be changed in one place, access can be tracked, and a copied script reveals nothing useful.

Where it is applied

A regional insurer ran about two hundred scheduled scripts and low-code flows that moved claims data between a policy system, a document platform and a reporting database. During an automation inventory review, a secret scanner flagged thirty-four workflows containing literal passwords, including one database administrator account shared by eleven jobs.

The security team revoked the shared account, created separate service accounts with least-privilege roles and stored their secrets in a credential vault. Each workflow was refactored to request its secret at run time, and a pre-commit scanning hook was added to the automation repository.

Rotation, which had previously required a weekend outage, became a scheduled monthly task with no downtime, and audit logs could finally attribute each database action to a specific workflow.