Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ dotenvx set -f .env.ci --plain -- RHQCR_BOT_USERNAME andreijiroh-dev+buildops
| `key` | | Value of `DOTENV_PRIVATE_KEY_CI` from your `.env.keys` file (or another). |
| `inject-env-vars` | `false` | Injects decrypted secrets as env vars if set to `true` for subsequent jobs |

### Known limitations

> [!WARNING]
> GitHub Actions secret masking (`::add-mask::`, used via `@actions/core#setSecret`) can be unreliable for some multiline values in debug mode (`ACTIONS_STEP_DEBUG`/`RUNNER_DEBUG`), especially for private keys.
>
> This action applies additional masking for multiline values (full value, escaped value, and per-line entries), but GitHub runner redaction still has edge cases.
>
> Recommended mitigations:
>
> - Disable debug logging in workflows handling sensitive multiline secrets.
> - Avoid printing sensitive values in logs, even for troubleshooting.
> - Rotate any secret immediately if it is ever exposed in workflow logs.

### Outputs

Alongside any parsed secrets (whether decrypted or not), the following outputs/variables are adapted from
Expand Down
39 changes: 36 additions & 3 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ import * as core from "@actions/core";
import dotenv from "dotenv";
import dotenvx from "@dotenvx/dotenvx";

function maskSecretValue(secretValue) {
if (typeof secretValue !== "string" || secretValue.length === 0) return;

const normalized = secretValue.replace(/\r\n/g, "\n");
const candidates = new Set([
secretValue,
normalized,
normalized.replace(/\n/g, "\\n"),
]);

if (normalized.includes("\n")) {
normalized
.split("\n")
.filter((line) => line.length > 0)
.forEach((line) => candidates.add(line));
}

candidates.forEach((candidate) => {
core.setSecret(candidate);
});
}

function getBoolInputEnv() {
const bool = process.env["INPUT_INJECT_ENV_VARS"];
const trueValue = ["true", "True", "TRUE"];
Expand Down Expand Up @@ -31,8 +53,19 @@ const opts = {
injectVars: getBoolInputEnv(),
};

maskSecretValue(opts.key);

await core.group("options debug", async () => {
core.debug(JSON.stringify(opts, null, 2));
core.debug(
JSON.stringify(
{
...opts,
key: opts.key ? "[REDACTED]" : "",
},
null,
2,
),
);
});

/* Placeholder object for parsed secrets after decryption */
Expand All @@ -56,7 +89,7 @@ dotenv.config({
dotenvx.config({
path: opts.path,
processEnv: secretsTmp,
debug: core.isDebug(),
debug: false,
});

Object.keys(secretsTmp).forEach((key) => {
Expand All @@ -78,7 +111,7 @@ Object.keys(secretsTmp).forEach((key) => {

// Automatically mask decrypted secrets when prefixed with "encrypted:" using plain old dotenv package
if (isEncryptedPlainValue && !isEncryptedValue) {
core.setSecret(value);
maskSecretValue(value);
Comment thread
ajhalili2006 marked this conversation as resolved.
Resolved
}

core.setOutput(key, value);
Expand Down
39 changes: 36 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42493,6 +42493,28 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen



function maskSecretValue(secretValue) {
if (typeof secretValue !== "string" || secretValue.length === 0) return;

const normalized = secretValue.replace(/\r\n/g, "\n");
const candidates = new Set([
secretValue,
normalized,
normalized.replace(/\n/g, "\\n"),
]);

if (normalized.includes("\n")) {
normalized
.split("\n")
.filter((line) => line.length > 0)
.forEach((line) => candidates.add(line));
}

candidates.forEach((candidate) => {
_actions_core__WEBPACK_IMPORTED_MODULE_0__/* .setSecret */ .Pq(candidate);
});
}

function getBoolInputEnv() {
const bool = process.env["INPUT_INJECT_ENV_VARS"];
const trueValue = ["true", "True", "TRUE"];
Expand Down Expand Up @@ -42522,8 +42544,19 @@ const opts = {
injectVars: getBoolInputEnv(),
};

maskSecretValue(opts.key);

await _actions_core__WEBPACK_IMPORTED_MODULE_0__/* .group */ .Os("options debug", async () => {
_actions_core__WEBPACK_IMPORTED_MODULE_0__/* .debug */ .Yz(JSON.stringify(opts, null, 2));
_actions_core__WEBPACK_IMPORTED_MODULE_0__/* .debug */ .Yz(
JSON.stringify(
{
...opts,
key: opts.key ? "[REDACTED]" : "",
},
null,
2,
),
);
});

/* Placeholder object for parsed secrets after decryption */
Expand All @@ -42547,7 +42580,7 @@ dotenv__WEBPACK_IMPORTED_MODULE_1__.config({
_dotenvx_dotenvx__WEBPACK_IMPORTED_MODULE_2__.config({
path: opts.path,
processEnv: secretsTmp,
debug: _actions_core__WEBPACK_IMPORTED_MODULE_0__/* .isDebug */ ._o(),
debug: false,
});

Object.keys(secretsTmp).forEach((key) => {
Expand All @@ -42569,7 +42602,7 @@ Object.keys(secretsTmp).forEach((key) => {

// Automatically mask decrypted secrets when prefixed with "encrypted:" using plain old dotenv package
if (isEncryptedPlainValue && !isEncryptedValue) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__/* .setSecret */ .Pq(value);
maskSecretValue(value);
}

_actions_core__WEBPACK_IMPORTED_MODULE_0__/* .setOutput */ .uH(key, value);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading