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 11 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 about 5 hours 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 ensure that only the intended characters are included.

  • General Fix: Replace the problematic character range with a more precise set of characters.
  • Detailed Fix: Modify the regular expression on line 1758 to remove the redundant underscore and ensure that only the intended characters are included.
  • Specific Changes: Update the regular expression in the validateAddress function to use a more precise character set.
  • Requirements: No additional methods, imports, or definitions are needed to implement this change.
Suggested changeset 1
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,3 +1757,3 @@
   const sanitizedMail = removeExtraSpace
-    .replace(/[^\w.@-_]/g, "")
+    .replace(/[^\w.@-]/g, "")
     .replace(/\^/g, "");
EOF
@@ -1757,3 +1757,3 @@
const sanitizedMail = removeExtraSpace
.replace(/[^\w.@-_]/g, "")
.replace(/[^\w.@-]/g, "")
.replace(/\^/g, "");
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants