Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIN-4810 clear tenant mail address #985

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rGregnanin
Copy link
Contributor

No description provided.


// Here I am removing strange characters or special symbols
const sanitizedMail = removeExtraSpace
.replace(/[^\w.@-_]/g, "")

Check warning

Code scanning / CodeQL

Overly permissive regular expression range Medium

Suspicious character range that overlaps with \w in the same character class.

Copilot Autofix AI 3 days ago

To fix the problem, we need to adjust the regular expression to avoid the overly permissive range. Specifically, we should remove the redundant underscore _ from the range and explicitly list the characters we want to include. The corrected regular expression should only include the characters that are not part of \w but are still allowed in the sanitized email address.

  • Update the regular expression on line 1758 to explicitly list the allowed special characters.
  • Ensure that the new regular expression does not overlap with the \w character class.
packages/tenant-process/src/services/tenantService.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/tenant-process/src/services/tenantService.ts b/packages/tenant-process/src/services/tenantService.ts
--- a/packages/tenant-process/src/services/tenantService.ts
+++ b/packages/tenant-process/src/services/tenantService.ts
@@ -1757,4 +1757,4 @@
   const sanitizedMail = removeExtraSpace
-    .replace(/[^\w.@-_]/g, "")
-    .replace(/\^/g, "");
+    .replace(/[^\w.@-]/g, "")
+    .replace(/[\^_]/g, "");
 
EOF
@@ -1757,4 +1757,4 @@
const sanitizedMail = removeExtraSpace
.replace(/[^\w.@-_]/g, "")
.replace(/\^/g, "");
.replace(/[^\w.@-]/g, "")
.replace(/[\^_]/g, "");

Copilot is powered by AI and may make mistakes. Always verify output.
@@ -1751,4 +1740,51 @@ async function revokeCertifiedAttribute(
} satisfies Tenant;
}

function validateAddress(address: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO there are too many steps in order to validate a mail, are these really necessary?
With the regex we don't need the extra steps of removing characters and spaces since it's already included.

I suggest to use this one: ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$ (taken from here)? Note: the regex must be case insensitive for it to work properly.

There's no perfect regex for validating a mail, but this one is simpler and covers most of the cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to leave emailPattern as it is so that it is aligned with the frontend as well, since it is the same pattern they use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants