Skip to content

Commit 494adcc

Browse files
fix: handle control characters in secrets during env substitution (#29)
1 parent 49fe16b commit 494adcc

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

docs/changelog.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [1.1.6] - Current
5+
## [1.1.7] - Current
6+
7+
### Fixed
8+
- **Secrets with control characters**: Fixed `SyntaxError: Bad control character in string literal` when secrets contain newlines or special characters (e.g., GitHub App private keys)
9+
- Replaced `JSON.parse(envsubst(JSON.stringify(obj)))` approach with `lodash.clonedeepwith` for safe environment variable substitution
10+
- Now correctly handles private keys, tabs, carriage returns, and other control characters in secret values
11+
12+
### Dependencies
13+
- Added `lodash.clonedeepwith@^4.5.0` for safe deep object traversal with custom value substitution
14+
15+
## [1.1.6]
616

717
### Added
818
- **"next" tag support**: Both Helm and Operator deployments now support `RHDH_VERSION=next`

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rhdh-e2e-test-utils",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "Test utilities for RHDH E2E tests",
55
"license": "Apache-2.0",
66
"type": "module",
@@ -74,6 +74,7 @@
7474
"@playwright/test": "^1.57.0",
7575
"@types/fs-extra": "^11.0.4",
7676
"@types/js-yaml": "^4.0.9",
77+
"@types/lodash.clonedeepwith": "^4.5.9",
7778
"@types/lodash.mergewith": "^4.6.9",
7879
"@types/node": "^24.10.1"
7980
},
@@ -87,6 +88,7 @@
8788
"eslint-plugin-playwright": "^2.4.0",
8889
"fs-extra": "^11.3.2",
8990
"js-yaml": "^4.1.1",
91+
"lodash.clonedeepwith": "^4.5.0",
9092
"lodash.mergewith": "^4.6.2",
9193
"otplib": "12.0.1",
9294
"prettier": "^3.7.4",

src/deployment/rhdh/deployment.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
generateDynamicPluginsConfigFromMetadata,
99
} from "../../utils/plugin-metadata.js";
1010
import { envsubst } from "../../utils/common.js";
11+
import cloneDeepWith from "lodash.clonedeepwith";
1112
import fs from "fs-extra";
1213
import {
1314
DEFAULT_CONFIG_PATHS,
@@ -81,9 +82,15 @@ export class RHDHDeployment {
8182
this.deploymentConfig.secrets,
8283
]);
8384

85+
// Use cloneDeepWith to substitute env vars in-place, avoiding JSON.parse issues
86+
// with control characters in secrets (e.g., private keys with newlines)
87+
const substituted = cloneDeepWith(secretsYaml, (value: unknown) => {
88+
if (typeof value === "string") return envsubst(value);
89+
});
90+
8491
await this.k8sClient.applySecretFromObject(
8592
"rhdh-secrets",
86-
JSON.parse(envsubst(JSON.stringify(secretsYaml))),
93+
substituted as { stringData?: Record<string, string> },
8794
this.deploymentConfig.namespace,
8895
);
8996
}

yarn.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ __metadata:
362362
languageName: node
363363
linkType: hard
364364

365+
"@types/lodash.clonedeepwith@npm:^4.5.9":
366+
version: 4.5.9
367+
resolution: "@types/lodash.clonedeepwith@npm:4.5.9"
368+
dependencies:
369+
"@types/lodash": "*"
370+
checksum: c690fb28126f7248894f08abe13d6c7684dd0a4e9ac545a419a8687438b50d2e6fe32b31176c65a394d3ade4fd16a145ecbf77e7521992414bf657b8b1d936c8
371+
languageName: node
372+
linkType: hard
373+
365374
"@types/lodash.mergewith@npm:^4.6.9":
366375
version: 4.6.9
367376
resolution: "@types/lodash.mergewith@npm:4.6.9"
@@ -1642,6 +1651,13 @@ __metadata:
16421651
languageName: node
16431652
linkType: hard
16441653

1654+
"lodash.clonedeepwith@npm:^4.5.0":
1655+
version: 4.5.0
1656+
resolution: "lodash.clonedeepwith@npm:4.5.0"
1657+
checksum: 9fbf4ebfa04b381df226a2298eba680327bea3d0d5d19c5118de7ae218fd219186e30e9fd0d33b13729f34ffbc83c1cf09cb27aff265ba94cb602b8a2b1e71c9
1658+
languageName: node
1659+
linkType: hard
1660+
16451661
"lodash.merge@npm:^4.6.2":
16461662
version: 4.6.2
16471663
resolution: "lodash.merge@npm:4.6.2"
@@ -2128,13 +2144,15 @@ __metadata:
21282144
"@playwright/test": ^1.57.0
21292145
"@types/fs-extra": ^11.0.4
21302146
"@types/js-yaml": ^4.0.9
2147+
"@types/lodash.clonedeepwith": ^4.5.9
21312148
"@types/lodash.mergewith": ^4.6.9
21322149
"@types/node": ^24.10.1
21332150
eslint: ^9.39.1
21342151
eslint-plugin-check-file: ^3.3.1
21352152
eslint-plugin-playwright: ^2.4.0
21362153
fs-extra: ^11.3.2
21372154
js-yaml: ^4.1.1
2155+
lodash.clonedeepwith: ^4.5.0
21382156
lodash.mergewith: ^4.6.2
21392157
otplib: 12.0.1
21402158
prettier: ^3.7.4

0 commit comments

Comments
 (0)