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

feat(workspace): expand forbidden subdomain validation #9082

Merged
merged 12 commits into from
Dec 18, 2024

Conversation

AMoreaux
Copy link
Contributor

Added new forbidden words and regex patterns to subdomain validation in update-workspace-input. Enhanced the ForbiddenWords validator to support both strings and regex matching. Updated tests to verify regex-based forbidden subdomain validation.

Fix #9064

Added new forbidden words and regex patterns to subdomain validation in `update-workspace-input`. Enhanced the `ForbiddenWords` validator to support both strings and regex matching. Updated tests to verify regex-based forbidden subdomain validation.
@AMoreaux AMoreaux self-assigned this Dec 16, 2024
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Enhanced the ForbiddenWords validator to support regex pattern matching for subdomain validation, allowing more flexible control over restricted workspace names.

  • Added regex pattern support in packages/twenty-server/src/engine/utils/custom-class-validator/ForbiddenWords.ts with case-insensitive string comparison
  • Implemented test case in forbidden-words-custom-class-validator.spec.ts to verify regex pattern validation (e.g., 'api-*' subdomains)
  • Expanded forbidden subdomain list in update-workspace-input.ts to include system paths, authentication terms, and country codes
  • Found duplicate entries 'eu' and 'support' in forbidden words list that should be removed

3 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

Added new forbidden words and regex patterns to subdomain validation in `update-workspace-input`. Enhanced the `ForbiddenWords` validator to support both strings and regex matching. Updated tests to verify regex-based forbidden subdomain validation.
Removed 'support' and 'eu' tags from the workspace input DTO. These tags are no longer needed and their removal simplifies the codebase. Ensures the DTO reflects the current requirements accurately.
Replaced 'ForbiddenWords' custom validation with 'NotIn' for clarity and consistency. Updated all references, including test files, to align with the new naming convention.
@FelixMalfait
Copy link
Member

Hey @AMoreaux sorry one last feedback, do you think it would be possible to add a user-friendly message? I feel like this will create support issues

Screenshot 2024-12-16 at 18 00 49

@Weiko
Copy link
Member

Weiko commented Dec 16, 2024

Hey @AMoreaux sorry one last feedback, do you think it would be possible to add a user-friendly message? I feel like this will create support issues

Screenshot 2024-12-16 at 18 00 49

+1 to that, also as a 500 this will be captured by sentry which we don't want 🤔

@AMoreaux
Copy link
Contributor Author

Hey @AMoreaux sorry one last feedback, do you think it would be possible to add a user-friendly message? I feel like this will create support issues

Screenshot 2024-12-16 at 18 00 49

+1 to that, also as a 500 this will be captured by sentry which we don't want 🤔

Is there a guideline or an example to do that ?

@FelixMalfait
Copy link
Member

Maybe look at fieldMetadataGraphqlApiExceptionHandler ?

Updated subdomain validation to disallow prefixes like "api-" and improved error messages for clearer feedback. Adjusted test cases and validation logic to reflect the changes, ensuring consistency across functionality.
Removed unnecessary console logs and commented-out code in the ValidationPipe exceptionFactory. This improves code cleanliness and reduces potential distractions in the production environment.
@@ -101,7 +101,8 @@ export const SettingsDomain = () => {
} catch (error) {
if (
error instanceof Error &&
error.message === 'Subdomain already taken'
(error.message === 'Subdomain already taken' ||
error.message.endsWith('not allowed'))
Copy link
Member

Choose a reason for hiding this comment

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

this feels very manual! We will need to discuss later if we actually want the backend to return error codes to the FE

@@ -54,6 +58,18 @@ const bootstrap = async () => {
app.useGlobalPipes(
new ValidationPipe({
transform: true,
exceptionFactory: (validationErrors: ValidationErrorType[] = []) => {
Copy link
Member

@charlesBochet charlesBochet Dec 17, 2024

Choose a reason for hiding this comment

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

I'm a bit lost, is this a global pipe which is validating our graphql input types !?

Nest is so weird, I would expect it to be passed to graphql yoga directly and yoga to accept a middleware or something like this
@Weiko what do you think?

Copy link
Member

@Weiko Weiko Dec 18, 2024

Choose a reason for hiding this comment

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

@charlesBochet I think the goal of ValidationPipe is to validate class-validator globally, whether it's from typeorm or yoga or any internal part that's using class-validator. Ideally we would want to check if we can make it work with useGraphQLErrorHandlerHook hook for yoga 🤔. I would still keep the ValidationType Globally (without your change) so we still catch those but probably also call it from the hook I mentioned above so we can throw a proper graphql ValidationError

@@ -54,6 +58,18 @@ const bootstrap = async () => {
app.useGlobalPipes(
new ValidationPipe({
transform: true,
exceptionFactory: (validationErrors: ValidationErrorType[] = []) => {
Copy link
Member

@Weiko Weiko Dec 18, 2024

Choose a reason for hiding this comment

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

@charlesBochet I think the goal of ValidationPipe is to validate class-validator globally, whether it's from typeorm or yoga or any internal part that's using class-validator. Ideally we would want to check if we can make it work with useGraphQLErrorHandlerHook hook for yoga 🤔. I would still keep the ValidationType Globally (without your change) so we still catch those but probably also call it from the hook I mentioned above so we can throw a proper graphql ValidationError

Removed custom NotIn validator and its tests. Updated references to use the built-in IsNotIn validator from class-validator for improved maintainability and standardization.
@AMoreaux AMoreaux assigned charlesBochet and unassigned AMoreaux Dec 18, 2024
@charlesBochet charlesBochet merged commit 2bcce44 into main Dec 18, 2024
15 of 16 checks passed
@charlesBochet charlesBochet deleted the chore/ban-specific-subdomains-word branch December 18, 2024 15:47
Copy link

Thanks @AMoreaux for your contribution!
This marks your 31st PR on the repo. You're top 2% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Ban specific keywords for subdomains
4 participants