Scan your whole stack
From OX Research Newsroom
Are you using mocha-aws-secrets-manager?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v1.0.2
mocha-aws-secrets-manager was last scanned on 30 Nov 2026 at version 1.0.2. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 1.0.2 LATEST | 30 Nov 2026 | No rules fired |
| 1.0.1 | 30 Nov 2026 | No rules fired |
| 1.0.0 | 30 Nov 2026 | No rules fired |
| 0.0.0-stage | 30 Nov 2026 | Not shown |
Findings for v1.0.2. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 1.0.2; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
Load your test secrets from AWS Secrets Manager into process.env, before Mocha loads your test files.
Log in to AWS once a day, then run Mocha as usual: each run reads the latest version of the secret. No
file on disk holds the secrets, and nobody needs to see them.
The same secret also works with Cypress and
Playwright. Every package uses the same
engine, aws-secrets-manager-core.
aws sso login --profile my-sso-profile. The session stays on your
machine, and every terminal uses it..mocharc.js reads the latest version of the secret,
before Mocha loads a test file, and puts each key in process.env.process.env.MY_KEY, also at the top level of a file. The logs print the key names,
never a value.npm install --save-dev mocha-aws-secrets-manager
You need:
aws configure sso of the
AWS CLI v2 creates,
or one of the other login strategies.CI runs the end-to-end test on Mocha 12. Before the 1.0.0 release, it also passed on Mocha 10.0.0 and 11.8.0.
1. Describe the secret. Create aws-secrets.config.js at the root of your project:
// aws-secrets.config.js
module.exports = {
secretName: 'my-team/e2e', // the name or the full ARN
region: 'eu-west-1',
profile: 'my-sso-profile'
}
2. Load it. Put this line at the top of .mocharc.js:
// .mocharc.js
require('mocha-aws-secrets-manager/register')
module.exports = {
// your Mocha options
}
In a package with "type": "module", a .js file is an ES module, which has no require. There, name
the file .mocharc.cjs, or pass the register on the command line:
mocha --require mocha-aws-secrets-manager/register.
3. Log in to AWS:
aws sso login --profile my-sso-profile
4. Run Mocha as usual: npx mocha.
Each key of the secret is in process.env, as text:
// test/api.spec.js
const assert = require('node:assert')
const apiKey = process.env.API_KEY // the top level of a file works too
describe('the API', function () {
it('answers with the key', async function () {
const response = await fetch('https://api.example.com/me', { headers: { 'x-api-key': apiKey } })
assert.equal(response.status, 200)
})
})
getSecrets() returns the secret with its original types: a number stays a number, an object stays an
object.
const { getSecrets } = require('mocha-aws-secrets-manager')
it('reads the limits', function () {
const { apiKey, limits } = getSecrets()
})
getSecrets() reads the memory of the process that loaded the secret, else the AWS_SECRETS_JSON
variable that it inherited. It throws when the register did not run.
| Option | Required | Default | Meaning |
|---|---|---|---|
secretName |
Yes | The secret name, or its full ARN. | |
region |
Yes | The AWS region of the secret. | |
strategy |
No | multi |
How to get AWS credentials. See Login strategies. |
profile |
No | The AWS SSO profile of the profile strategy. |
|
pathToCredentials |
No | The file of the credentials strategy. See Credentials file. |
|
kmsKeyId |
No | The KMS key that updateSecret sends with the new value. Needed for a secret of another AWS account. |
|
localDir |
No | The folder of the local copy. See Work offline with a local copy. | |
baseDir |
No | process.cwd() |
Where the search for the configuration file starts. |
silent |
No | false |
Hides the progress lines. The status line, the warnings and the errors still print. |
logger |
No | stderr | An object with info, warn and error that gets the progress and status lines. With the register, set it in the configuration file: the warnings about skipped keys still go to stderr. |
override |
No | false |
Replaces a variable that already holds another value. See How the secret reaches process.env. |
allowUnsafeKeys |
No | [] |
The keys that make programs run code, to put in process.env all the same, such as ['NODE_OPTIONS']. |
Three sources. A later source wins over an earlier one:
aws-secrets.config.js, aws-secrets.config.cjs,
aws-secrets.config.mjs or aws-secrets.config.json.| Variable | Option |
|---|---|
AWS_SECRETS_NAME |
secretName |
AWS_SECRETS_REGION |
region |
AWS_SECRETS_PROFILE |
profile |
AWS_SSO_STRATEGY |
strategy |
AWS_SECRETS_LOCAL_DIR |
localDir |
ENV_LOG_MODE=silent |
silent: true |
For example: AWS_SSO_STRATEGY=unset npx mocha.
About the configuration file:
.git. Outside a repository, the search stops at the nearest folder with package.json.
The nearest folder wins. In one folder, the first file in the order above wins..js, .cjs or .mjs file exports the options, or a function, sync or async, that returns them.localDir or pathToCredentials starts from the folder of the file.// aws-secrets.config.js
module.exports = {
secretName: 'my-team/e2e', // required
region: 'eu-west-1', // required
strategy: 'multi', // profile | default | unset | credentials | multi
profile: 'my-sso-profile',
pathToCredentials: 'aws-credentials.json',
localDir: '.secrets',
silent: false,
override: false,
allowUnsafeKeys: []
}
A missing secretName or region, or an unknown strategy, stops the run with an error that names the
key and where to set it. A blank string counts as missing:
"secretName" is missing. Set it in one of: aws-secrets.config.js, aws-secrets.config.cjs, aws-secrets.config.mjs, aws-secrets.config.json in the base folder or a parent folder; the options passed to loadSecrets(); the environment variable AWS_SECRETS_NAME.
| Strategy | Where the credentials come from |
|---|---|
profile |
The AWS SSO profile in profile. |
default |
The AWS SSO profile named default. |
unset |
The default credential chain of the AWS SDK: the profile in AWS_PROFILE when it is set, else the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN variables, then the shared AWS files, then a container or instance role. It reads every profile type. Use it on CI. |
credentials |
The file in pathToCredentials. |
multi (default) |
Tries profile, default, unset, then credentials, and stops at the first that works. When all fail, the error gives the reason of each one. |
profile and default read AWS SSO profiles only. For a profile with keys, a role or a
credential_process, use unset and set AWS_PROFILE to the profile name.multi moves on after any error, also when the login works and the secret does not exist. A later
attempt can then read the secret with other credentials. Set the strategy to see the AWS error of one
login.The credentials strategy reads a JSON or JavaScript file:
{
"accessKeyId": "AKIA...",
"secretAccessKey": "...",
"sessionToken": "..."
}
sessionToken is needed for temporary credentials only. A long-term IAM user key has none..js or .cjs file exports the object with module.exports, an .mjs file with
export default..gitignore.The package never logs you in. It uses the login that the AWS CLI keeps.
aws configure sso # one time: creates the profile
aws sso login --profile my-sso-profile # once a day
~/.aws/sso/cache, so one login serves every terminal and every runner on
the machine: Mocha, Playwright, Cypress and the AWS CLI.aws sso login --profile my-sso-profile.aws-secrets-manager-core, which this package installs, ships two login scripts. Each one logs you in
only when needed, then runs your command:
| Method | Copy this file | What it runs |
|---|---|---|
| AWS SSO | node_modules/aws-secrets-manager-core/sh/sso/aws_authenticate.sh |
aws_sso.sh: logs you in when your SSO session has ended. |
| Assume role | node_modules/aws-secrets-manager-core/sh/assume_role/aws_authenticate.sh |
aws_assume_role.sh: assumes the role of the environment, and logs you in when needed. |
Copy the file into your project once:
cp node_modules/aws-secrets-manager-core/sh/sso/aws_authenticate.sh .
With pnpm, run pnpm add -D aws-secrets-manager-core first: pnpm puts only your direct
dependencies at the top of node_modules.
Fill in your settings in the copy, AWS_PROFILE_<ENV> and ACCOUNT_ID_<ENV> for each
environment, and commit it.
Start Mocha through it:
{
"scripts": {
"test": "bash aws_authenticate.sh test \"npx mocha\""
}
}
The first argument names the environment: test picks AWS_PROFILE_TEST and ACCOUNT_ID_TEST. Use
letters, digits and _ only. The second argument is the command, as one argument. The script splits it
on spaces and runs the words without a shell: quotes inside the command, && and VAR=value do not
work, and a * expands to the names of the files in the current folder. Put such a command in an npm
script, and pass "npm run <script>".
npm update brings its fixes. Nothing is downloaded at run time.sh aws_authenticate.sh works too: the copy starts again with bash..gitattributes: *.sh text eol=lf.The core README gives all the details: the assume-role settings, the tools that the scripts install, and WSL.
The register loads the secret synchronously: the next line of .mocharc.js, every --require module
and every test file can read process.env.MY_KEY, also at the top level of a file or in a describe
body.
Put it first, and before dotenv:
// .mocharc.js
require('mocha-aws-secrets-manager/register')
require('dotenv').config() // optional, and after the register
module.exports = {
// your Mocha options
} Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.