From 36e8a3ec9bbbc54c2e2948777c0ce53ccd766651 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 18 Nov 2021 18:32:44 +0100
Subject: [PATCH] fix(config): compare scopes lowercase (#12740)

---
 lib/config/decrypt.ts | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/config/decrypt.ts b/lib/config/decrypt.ts
index 86a51a435b..547f7b47e7 100644
--- a/lib/config/decrypt.ts
+++ b/lib/config/decrypt.ts
@@ -99,7 +99,7 @@ export async function tryDecrypt(
             const orgName = org.replace(regEx(/\/$/), ''); // Strip trailing slash
             if (is.nonEmptyString(repo)) {
               const scopedRepository = `${orgName}/${repo}`;
-              if (scopedRepository === repository) {
+              if (scopedRepository.toLowerCase() === repository.toLowerCase()) {
                 decryptedStr = value;
               } else {
                 logger.debug(
@@ -107,12 +107,14 @@ export async function tryDecrypt(
                   'Secret is scoped to a different repository'
                 );
                 const error = new Error('config-validation');
-                error.validationError = `Encrypted secret is scoped to a different repository: ${scopedRepository}.`;
+                error.validationError = `Encrypted secret is scoped to a different repository: "${scopedRepository}".`;
                 throw error;
               }
             } else {
               const scopedOrg = `${orgName}/`;
-              if (repository.startsWith(scopedOrg)) {
+              if (
+                repository.toLowerCase().startsWith(scopedOrg.toLowerCase())
+              ) {
                 decryptedStr = value;
               } else {
                 logger.debug(
@@ -120,7 +122,7 @@ export async function tryDecrypt(
                   'Secret is scoped to a different org'
                 );
                 const error = new Error('config-validation');
-                error.validationError = `Encrypted secret is scoped to a different org" ${scopedOrg}.`;
+                error.validationError = `Encrypted secret is scoped to a different org: "${scopedOrg}".`;
                 throw error;
               }
             }
-- 
GitLab