Skip to content

Commit 03947fb

Browse files
committed
fixes
1 parent dfe8e34 commit 03947fb

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

backend/internal/services/project_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ func (s *ProjectService) RemoveProjectCustomFile(ctx context.Context, projectID,
12071207
return err
12081208
}
12091209

1210-
if err := projects.RemoveCustomFile(proj.Path, filePath); err != nil {
1210+
if err := projects.RemoveCustomFile(proj.Path, filePath, s.getExternalPathsConfig(ctx)); err != nil {
12111211
return fmt.Errorf("failed to remove custom file: %w", err)
12121212
}
12131213

backend/internal/utils/projects/files.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ func resolveParentSymlinks(absPath string) (string, error) {
124124
// isWithinDirectory checks if evalPath is within the given directory.
125125
func isWithinDirectory(evalPath, dir string) bool {
126126
if evalPath == dir {
127-
return false // Explicitly not "within" - equal paths handled by caller
127+
return false
128128
}
129+
evalPath = filepath.Clean(evalPath)
129130
prefix := dir + string(filepath.Separator)
130131
return strings.HasPrefix(evalPath+string(filepath.Separator), prefix)
131132
}
@@ -304,9 +305,6 @@ func WriteIncludeFile(projectDir, includePath, content string, cfg ExternalPaths
304305
}
305306

306307
dir := filepath.Dir(validatedPath)
307-
if dir == "" || dir == "." {
308-
return fmt.Errorf("invalid include path: cannot create directory '%s'", dir)
309-
}
310308

311309
// Only create directory if it doesn't exist
312310
if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) {
@@ -430,7 +428,7 @@ func RegisterCustomFile(projectDir, filePath string, cfg ExternalPathsConfig) er
430428

431429
// Create only if file doesn't exist; existing files are registered as-is
432430
if _, err := os.Stat(absPath); os.IsNotExist(err) {
433-
if dir := filepath.Dir(absPath); dir != "." {
431+
if dir := filepath.Dir(absPath); dir != "" {
434432
if err := os.MkdirAll(dir, common.DirPerm); err != nil {
435433
return fmt.Errorf("failed to create directory: %w", err)
436434
}
@@ -455,7 +453,7 @@ func WriteCustomFile(projectDir, filePath, content string, cfg ExternalPathsConf
455453
return err
456454
}
457455

458-
if dir := filepath.Dir(absPath); dir != "." {
456+
if dir := filepath.Dir(absPath); dir != "" {
459457
if err := os.MkdirAll(dir, common.DirPerm); err != nil {
460458
return fmt.Errorf("failed to create directory: %w", err)
461459
}
@@ -468,14 +466,16 @@ func WriteCustomFile(projectDir, filePath, content string, cfg ExternalPathsConf
468466
}
469467

470468
// RemoveCustomFile removes a file from the manifest.
471-
func RemoveCustomFile(projectDir, filePath string) error {
472-
absProjectDir, _ := filepath.Abs(projectDir)
473-
474-
// Compute possible manifest paths
475-
absPath := filePath
476-
if !filepath.IsAbs(filePath) {
477-
absPath = filepath.Join(absProjectDir, filePath)
469+
func RemoveCustomFile(projectDir, filePath string, cfg ExternalPathsConfig) error {
470+
absPath, err := ValidateFilePath(projectDir, filePath, cfg, PathValidationOptions{
471+
CheckReservedNames: false,
472+
AllowProjectDir: false,
473+
})
474+
if err != nil {
475+
return fmt.Errorf("invalid file path: %w", err)
478476
}
477+
478+
absProjectDir, _ := resolveAbsPath(projectDir)
479479
mPath := manifestPath(absPath, absProjectDir)
480480

481481
manifest, err := ReadManifest(projectDir)
@@ -485,7 +485,7 @@ func RemoveCustomFile(projectDir, filePath string) error {
485485

486486
var updated []string
487487
for _, f := range manifest.CustomFiles {
488-
if f != mPath && f != filePath {
488+
if f != mPath {
489489
updated = append(updated, f)
490490
}
491491
}

frontend/src/routes/(app)/environments/[id]/+page.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@
9191
let formDiskUsagePath = $state('/app/data/projects');
9292
let formMaxImageUploadSize = $state(500);
9393
let formBaseServerUrl = $state('http://localhost');
94-
let formAllowedExternalPaths = $state('');
9594
let formScheduledPruneEnabled = $state(false);
9695
let formScheduledPruneInterval = $state(1440);
9796
let formScheduledPruneContainers = $state(true);
9897
let formScheduledPruneImages = $state(true);
9998
let formScheduledPruneVolumes = $state(false);
10099
let formScheduledPruneNetworks = $state(true);
101100
let formScheduledPruneBuildCache = $state(false);
101+
let formAllowedExternalPaths = $state('');
102102
103103
type PollingIntervalMode = 'hourly' | 'daily' | 'weekly' | 'custom';
104104
@@ -160,14 +160,14 @@
160160
formDiskUsagePath = settings.diskUsagePath || '/app/data/projects';
161161
formMaxImageUploadSize = settings.maxImageUploadSize || 500;
162162
formBaseServerUrl = settings.baseServerUrl || 'http://localhost';
163-
formAllowedExternalPaths = settings.allowedExternalPaths || '';
164163
formScheduledPruneEnabled = settings.scheduledPruneEnabled ?? false;
165164
formScheduledPruneInterval = settings.scheduledPruneInterval ?? 1440;
166165
formScheduledPruneContainers = settings.scheduledPruneContainers ?? true;
167166
formScheduledPruneImages = settings.scheduledPruneImages ?? true;
168167
formScheduledPruneVolumes = settings.scheduledPruneVolumes ?? false;
169168
formScheduledPruneNetworks = settings.scheduledPruneNetworks ?? true;
170169
formScheduledPruneBuildCache = settings.scheduledPruneBuildCache ?? false;
170+
formAllowedExternalPaths = settings.allowedExternalPaths || '';
171171
172172
// Initialize derived states
173173
pollingIntervalMode = imagePollingOptions.find((o) => o.minutes === settings.pollingInterval)?.value ?? 'custom';
@@ -224,14 +224,14 @@
224224
formDiskUsagePath !== (settings.diskUsagePath || '/app/data/projects') ||
225225
formMaxImageUploadSize !== (settings.maxImageUploadSize || 500) ||
226226
formBaseServerUrl !== (settings.baseServerUrl || 'http://localhost') ||
227-
formAllowedExternalPaths !== (settings.allowedExternalPaths || '')))
228227
formScheduledPruneEnabled !== (settings.scheduledPruneEnabled ?? false) ||
229228
formScheduledPruneInterval !== (settings.scheduledPruneInterval ?? 1440) ||
230229
formScheduledPruneContainers !== (settings.scheduledPruneContainers ?? true) ||
231230
formScheduledPruneImages !== (settings.scheduledPruneImages ?? true) ||
232231
formScheduledPruneVolumes !== (settings.scheduledPruneVolumes ?? false) ||
233232
formScheduledPruneNetworks !== (settings.scheduledPruneNetworks ?? true) ||
234-
formScheduledPruneBuildCache !== (settings.scheduledPruneBuildCache ?? false)))
233+
formScheduledPruneBuildCache !== (settings.scheduledPruneBuildCache ?? false) ||
234+
formAllowedExternalPaths !== (settings.allowedExternalPaths || '')))
235235
);
236236
237237
async function refreshEnvironment() {
@@ -257,14 +257,14 @@
257257
formDiskUsagePath = settings.diskUsagePath || '/app/data/projects';
258258
formMaxImageUploadSize = settings.maxImageUploadSize || 500;
259259
formBaseServerUrl = settings.baseServerUrl || 'http://localhost';
260-
formAllowedExternalPaths = settings.allowedExternalPaths || '';
261260
formScheduledPruneEnabled = settings.scheduledPruneEnabled ?? false;
262261
formScheduledPruneInterval = settings.scheduledPruneInterval ?? 1440;
263262
formScheduledPruneContainers = settings.scheduledPruneContainers ?? true;
264263
formScheduledPruneImages = settings.scheduledPruneImages ?? true;
265264
formScheduledPruneVolumes = settings.scheduledPruneVolumes ?? false;
266265
formScheduledPruneNetworks = settings.scheduledPruneNetworks ?? true;
267266
formScheduledPruneBuildCache = settings.scheduledPruneBuildCache ?? false;
267+
formAllowedExternalPaths = settings.allowedExternalPaths || '';
268268
269269
// Initialize derived states
270270
pollingIntervalMode = imagePollingOptions.find((o) => o.minutes === settings.pollingInterval)?.value ?? 'custom';
@@ -354,14 +354,14 @@
354354
diskUsagePath: formDiskUsagePath,
355355
maxImageUploadSize: formMaxImageUploadSize,
356356
baseServerUrl: formBaseServerUrl,
357-
allowedExternalPaths: formAllowedExternalPaths
358357
scheduledPruneEnabled: formScheduledPruneEnabled,
359358
scheduledPruneInterval: sanitizedScheduledPruneInterval,
360359
scheduledPruneContainers: formScheduledPruneContainers,
361360
scheduledPruneImages: formScheduledPruneImages,
362361
scheduledPruneVolumes: formScheduledPruneVolumes,
363362
scheduledPruneNetworks: formScheduledPruneNetworks,
364-
scheduledPruneBuildCache: formScheduledPruneBuildCache
363+
scheduledPruneBuildCache: formScheduledPruneBuildCache,
364+
allowedExternalPaths: formAllowedExternalPaths
365365
});
366366
}
367367

0 commit comments

Comments
 (0)