Skip to content

Commit 7989b61

Browse files
Redact credentials from Git URLs in logs (#184)
* Redact git credentials from logs Git URLs with authentication tokens were leaking in logs during clone operations. Added GitLogger wrapper to automatically sanitize credentials from all log output. * Use URL parsing instead of regex * Fix credential redaction in embedded URLs The regex-based approach now correctly handles URLs embedded in error messages. Simplified sanitizeGitData() to use general recursion for all fields instead of field-specific logic. * Use URL parsing instead of regex Replaces regex pattern with simple string scanning to eliminate ReDoS vulnerability while maintaining credential redaction. * Fix formatting * Improve credential redaction completeness URL boundary detection now stops at structural delimiters (quotes, brackets) to handle JSON/XML formats correctly. GitLogger now sanitizes Error objects to prevent credential leaks when error messages contain repository URLs. Replace 'any' with Record<string, unknown> for type safety.
1 parent 2011e85 commit 7989b61

File tree

17 files changed

+528
-257
lines changed

17 files changed

+528
-257
lines changed

.changeset/new-students-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudflare/sandbox': patch
3+
---
4+
5+
Redact credentials from Git URLs in logs

.github/workflows/pullrequest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ jobs:
120120
with:
121121
context: .
122122
file: packages/sandbox/Dockerfile
123-
platforms: linux/amd64 # Explicit single-arch for compatibility with release-amd64 cache
124-
load: true # Load into Docker daemon for local testing
123+
platforms: linux/amd64 # Explicit single-arch for compatibility with release-amd64 cache
124+
load: true # Load into Docker daemon for local testing
125125
tags: cloudflare/sandbox-test:${{ needs.unit-tests.outputs.version || '0.0.0' }}
126126
cache-from: |
127127
type=gha,scope=pr-${{ github.event.pull_request.number }}-amd64

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119
context: .
120120
file: packages/sandbox/Dockerfile
121121
platforms: linux/amd64
122-
push: false # Don't push, just cache
122+
push: false # Don't push, just cache
123123
cache-from: type=gha,scope=release-amd64
124124
cache-to: type=gha,mode=max,scope=release-amd64
125125
build-args: |
@@ -190,7 +190,7 @@ jobs:
190190
context: .
191191
file: packages/sandbox/Dockerfile
192192
platforms: linux/amd64
193-
push: false # Don't push, just cache
193+
push: false # Don't push, just cache
194194
cache-from: type=gha,scope=release-amd64
195195
cache-to: type=gha,mode=max,scope=release-amd64
196196
build-args: |

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The Cloudflare Sandbox SDK enables secure, isolated code execution in containers
3434
- `CodeInterpreter`: High-level API for running Python/JavaScript with structured outputs
3535
- `proxyToSandbox()`: Request handler for preview URL routing
3636

37-
2. **`@repo/shared` (packages/shared/)** - Shared types and error system
37+
2. **`@repo/shared` (packages/shared/)** - Shared utilities
3838
- Type definitions shared between SDK and container runtime
3939
- Centralized error handling and logging utilities
4040
- Not published to npm (internal workspace package)

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ Thank you for your interest in contributing to the Cloudflare Sandbox SDK! This
1515

1616
1. Fork the repository to your GitHub account
1717
2. Clone your fork:
18+
1819
```bash
1920
git clone https://github.com/YOUR-USERNAME/sandbox-sdk.git
2021
cd sandbox-sdk
2122
```
2223

2324
3. Install dependencies:
25+
2426
```bash
2527
npm install
2628
```
2729

2830
4. Build the packages:
31+
2932
```bash
3033
npm run build
3134
```
@@ -40,6 +43,7 @@ Thank you for your interest in contributing to the Cloudflare Sandbox SDK! This
4043
### Making Changes
4144

4245
1. Create a new branch for your changes:
46+
4347
```bash
4448
git checkout -b feat/your-feature-name
4549
# or
@@ -49,6 +53,7 @@ Thank you for your interest in contributing to the Cloudflare Sandbox SDK! This
4953
2. Make your changes following our coding standards (see CLAUDE.md)
5054

5155
3. Run code quality checks:
56+
5257
```bash
5358
npm run check # Linting + type checking
5459
npm run fix # Auto-fix linting issues
@@ -73,6 +78,7 @@ Follow the [7 rules for great commit messages](https://cbea.ms/git-commit/):
7378
7. Use the body to explain what and why vs. how
7479

7580
Example:
81+
7682
```
7783
Add session isolation for concurrent executions
7884
@@ -90,11 +96,13 @@ npx changeset
9096
```
9197

9298
This will interactively guide you through:
99+
93100
1. Selecting which packages to include
94101
2. Choosing the semantic version bump (`patch`, `minor`, or `major`)
95102
3. Writing a description of your changes
96103

97104
Use semantic versioning:
105+
98106
- `patch`: Bug fixes, minor improvements
99107
- `minor`: New features, non-breaking changes
100108
- `major`: Breaking changes
@@ -104,6 +112,7 @@ The changeset bot will comment on your PR if a changeset is needed.
104112
## Submitting a Pull Request
105113

106114
1. Push your branch to your fork:
115+
107116
```bash
108117
git push origin feat/your-feature-name
109118
```
@@ -119,6 +128,7 @@ The changeset bot will comment on your PR if a changeset is needed.
119128
### Review Process
120129

121130
A maintainer will review your PR and may:
131+
122132
- Request changes
123133
- Ask questions
124134
- Suggest improvements
@@ -135,12 +145,14 @@ We use Biome for linting and formatting. Key guidelines:
135145
- Write concise, readable code
136146
- Add comments for complex logic
137147
- Follow patterns in existing code
148+
- Use the provided logger (`this.logger.info()`) instead of `console.log()` in production code
138149

139150
## Testing
140151

141152
### Unit Tests
142153

143154
Located in `packages/*/tests/`:
155+
144156
- Test individual components in isolation
145157
- Mock external dependencies
146158
- Fast feedback loop
@@ -150,6 +162,7 @@ Run with: `npm test`
150162
### E2E Tests
151163

152164
Located in `tests/e2e/`:
165+
153166
- Test full workflows against real Workers and containers
154167
- Require Docker
155168
- Slower but comprehensive

package-lock.json

Lines changed: 5 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sandbox-container/src/core/container.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Logger } from '@repo/shared';
2-
import { createLogger } from '@repo/shared';
2+
import { createLogger, GitLogger } from '@repo/shared';
33
import { ExecuteHandler } from '../handlers/execute-handler';
44
import { FileHandler } from '../handlers/file-handler';
55
import { GitHandler } from '../handlers/git-handler';
@@ -96,6 +96,9 @@ export class Container {
9696
// Initialize SessionManager
9797
const sessionManager = new SessionManager(logger);
9898

99+
// Create git-specific logger that automatically sanitizes credentials
100+
const gitLogger = new GitLogger(logger);
101+
99102
// Initialize services
100103
const processService = new ProcessService(
101104
processStore,
@@ -108,7 +111,11 @@ export class Container {
108111
sessionManager
109112
);
110113
const portService = new PortService(portStore, securityAdapter, logger);
111-
const gitService = new GitService(securityAdapter, logger, sessionManager);
114+
const gitService = new GitService(
115+
securityAdapter,
116+
gitLogger,
117+
sessionManager
118+
);
112119
const interpreterService = new InterpreterService(logger);
113120

114121
// Initialize handlers
@@ -117,7 +124,7 @@ export class Container {
117124
const fileHandler = new FileHandler(fileService, logger);
118125
const processHandler = new ProcessHandler(processService, logger);
119126
const portHandler = new PortHandler(portService, logger);
120-
const gitHandler = new GitHandler(gitService, logger);
127+
const gitHandler = new GitHandler(gitService, gitLogger);
121128
const interpreterHandler = new InterpreterHandler(
122129
interpreterService,
123130
logger

0 commit comments

Comments
 (0)