diff --git a/src/lib/features/dependent-features/dependent-features-service.ts b/src/lib/features/dependent-features/dependent-features-service.ts index fd7603094600..318b7740e4ec 100644 --- a/src/lib/features/dependent-features/dependent-features-service.ts +++ b/src/lib/features/dependent-features/dependent-features-service.ts @@ -90,6 +90,12 @@ export class DependentFeaturesService { ): Promise { const { enabled, feature: parent, variants } = dependentFeature; + if (child === parent) { + throw new InvalidOperationError( + 'A feature flag cannot depend on itself.', + ); + } + const [children, parentExists] = await Promise.all([ this.dependentFeaturesReadModel.getChildren([child]), this.featuresReadModel.featureExists(parent), diff --git a/src/lib/features/dependent-features/dependent.features.e2e.test.ts b/src/lib/features/dependent-features/dependent.features.e2e.test.ts index 3fac621fa327..6e135b758e5a 100644 --- a/src/lib/features/dependent-features/dependent.features.e2e.test.ts +++ b/src/lib/features/dependent-features/dependent.features.e2e.test.ts @@ -194,3 +194,16 @@ test('should check if any dependencies exist', async () => { const { body: dependenciesExistAfter } = await checkDependenciesExist(); expect(dependenciesExistAfter).toBe(true); }); + +test('should not allow to add dependency to self', async () => { + const parent = uuidv4(); + await app.createFeature(parent); + + await addFeatureDependency( + parent, + { + feature: parent, + }, + 403, + ); +});