# Usage of hard-coded secret

## Overview

* **Rule ID**: `javascript_lang_hardcoded_secret`
* **Applicable Languages**: Javascript
* **Weakness ID**: CWE-798

## Description

Storing secrets directly in your code poses a security risk. Instead, use environment variables or a secret management system to protect your sensitive information.

## Remediation Guidelines

* **Do not** store plaintext secrets in your code. This exposes sensitive information to unnecessary risk.

  ```java
    passport.use(new OAuth2Strategy({
      authorizationURL: 'https://www.example.com/oauth2/authorize',
      tokenURL: 'https://www.example.com/oauth2/token',
      clientID: 'my-id-123',
      clientSecret: 'shh-my-secret',
      callbackURL: 'http://localhost:3000/auth/example/callback'
        },
    function(accessToken, refreshToken, profile, cb) {
      User.findOrCreate({ exampleId: profile.id }, function (err, user) {
        return cb(err, user);
      });
    }
  ));

  ```
* **Use environment variables to store sensitive information, such as secrets.** This approach keeps credentials out of your codebase and facilitates more secure management.
* **Consider implementing a key-management system to handle secrets and other sensitive data securely.** This method offers enhanced security features for managing and accessing credentials.

## References

* [**OWASP hardcoded passwords**](https://owasp.org/www-community/vulnerabilities/Use_of_hard-coded_password)
* [**Google Cloud Key Management Service**](https://cloud.google.com/kms/docs)
* [**AWS Key Management Service**](https://aws.amazon.com/kms/)
* [**CWE-798: Use of Hard-coded Credentials**](https://cwe.mitre.org/data/definitions/798.html)
* [**OWASP Top 10: A07:2021 - Identification and Authentication Failures**](https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/)

## Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our [**SAST TOOL**](https://scopy.sec1.io/login)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sec1.io/user-docs/4-sast/3-javascript/usage-of-hard-coded-secret-lang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
