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

fix: prevent HTML input in the form field "name" for order templates and wishlists #1385

Merged
merged 5 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FormlyFieldConfig } from '@ngx-formly/core';
import { pick } from 'lodash-es';

import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { OrderTemplate } from '../../models/order-template/order-template.model';

Expand Down Expand Up @@ -72,9 +73,13 @@ export class OrderTemplatePreferencesDialogComponent implements OnInit {
hideRequiredMarker: true,
maxLength: 35,
},
validators: {
validation: [SpecialValidators.noHtmlTags],
},
validation: {
messages: {
required: 'account.order_template.form.name.error.required',
noHtmlTags: 'account.name.error.forbidden.html.chars',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { SelectOption } from 'ish-core/models/select-option/select-option.model';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { OrderTemplatesFacade } from '../../facades/order-templates.facade';

Expand Down Expand Up @@ -43,8 +44,14 @@ export class SelectOrderTemplateFormComponent implements OnInit {
props: {
required: true,
},
validators: {
validation: [SpecialValidators.noHtmlTags],
},
validation: {
messages: { required: 'account.order_template.name.error.required' },
messages: {
required: 'account.order_template.name.error.required',
noHtmlTags: 'account.name.error.forbidden.html.chars',
},
},
},
];
Expand Down Expand Up @@ -86,8 +93,14 @@ export class SelectOrderTemplateFormComponent implements OnInit {
props: {
required: true,
},
validators: {
validation: [SpecialValidators.noHtmlTags],
},
validation: {
messages: { required: 'account.order_template.name.error.required' },
messages: {
required: 'account.order_template.name.error.required',
noHtmlTags: 'account.name.error.forbidden.html.chars',
},
},
expressions: {
'props.disabled': conf => conf.model.orderTemplate !== 'new',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { SelectOption } from 'ish-core/models/select-option/select-option.model';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { WishlistsFacade } from '../../facades/wishlists.facade';

Expand Down Expand Up @@ -39,9 +40,13 @@ export class SelectWishlistFormComponent implements OnInit {
props: {
required: true,
},
validators: {
validation: [SpecialValidators.noHtmlTags],
},
validation: {
messages: {
required: 'account.wishlist.name.error.required',
noHtmlTags: 'account.name.error.forbidden.html.chars',
},
},
},
Expand Down Expand Up @@ -84,9 +89,13 @@ export class SelectWishlistFormComponent implements OnInit {
props: {
required: true,
},
validators: {
validation: [SpecialValidators.noHtmlTags],
},
validation: {
messages: {
required: 'account.wishlist.name.error.required',
noHtmlTags: 'account.name.error.forbidden.html.chars',
},
},
expressions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FormlyFieldConfig } from '@ngx-formly/core';
import { pick } from 'lodash-es';

import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { Wishlist } from '../../models/wishlist/wishlist.model';

Expand Down Expand Up @@ -73,8 +74,14 @@ export class WishlistPreferencesDialogComponent implements OnInit {
hideRequiredMarker: true,
maxLength: 35,
},
validators: {
validation: [SpecialValidators.noHtmlTags],
},
validation: {
messages: { required: 'account.wishlists.wishlist_form.name.error.required' },
messages: {
required: 'account.wishlists.wishlist_form.name.error.required',
noHtmlTags: 'account.name.error.forbidden.html.chars',
},
},
},
{
Expand Down
8 changes: 8 additions & 0 deletions src/app/shared/forms/validators/special-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export class SpecialValidators {
return noSpecialCharsPattern.test(control.value) ? undefined : { noSpecialChars: { valid: false } };
}

/**
* Prevent "<" and ">" to avoid usage of HTML tags.
*/
static noHtmlTags(control: FormControl): { [error: string]: { valid: boolean } } {
const noHtmlTagsPattern = /^[^\<\>]*$/;
return noHtmlTagsPattern.test(control.value) ? undefined : { noHtmlTags: { valid: false } };
}

static punchoutLogin(control: FormControl): { [error: string]: { valid: boolean } } {
const punchoutLoginPattern = /^[a-zA-Z0-9_.@]*$/;
return punchoutLoginPattern.test(control.value) ? undefined : { punchoutLogin: { valid: false } };
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"account.my_account.link": "Mein Konto",
"account.my_account.overview.link": "Kontoübersicht",
"account.name.error.forbidden.chars": "Nur alphanumerische Zeichen sind erlaubt.",
"account.name.error.forbidden.html.chars": "This type of special characters is not allowed. Please remove \"<\", \">\" or both.",
"account.navigation.logout.link": "Abmelden",
"account.navigation.quotes.link": "Preisangebote",
"account.new_user.heading": "Neue Benutzer",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"account.my_account.link": "My Account",
"account.my_account.overview.link": "Account Overview",
"account.name.error.forbidden.chars": "Only alphanumeric characters are allowed.",
"account.name.error.forbidden.html.chars": "This type of special characters is not allowed. Please remove \"<\", \">\" or both.",
"account.navigation.logout.link": "Logout",
"account.navigation.quotes.link": "Quoting",
"account.new_user.heading": "New Users",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"account.my_account.link": "Mon compte",
"account.my_account.overview.link": "Aperçu du compte",
"account.name.error.forbidden.chars": "Seuls les caractères alphanumériques sont autorisés.",
"account.name.error.forbidden.html.chars": "This type of special characters is not allowed. Please remove \"<\", \">\" or both.",
"account.navigation.logout.link": "Déconnexion",
"account.navigation.quotes.link": "Devis",
"account.new_user.heading": "Nouveaux utilisateurs",
Expand Down