-
Notifications
You must be signed in to change notification settings - Fork 2
Signup form domain validation #399
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
base: main
Are you sure you want to change the base?
Conversation
supun-io
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: This is not fully reviewed. I have one pending question: what if the user does not want to embed the form on one of the sending domain websites? There would be no way to block that domain since all sending domains are implicitly allowed. It might have been a bad idea on our part to allow all sending domains. Needs to discuss. So, don't work further on this PR until this is resolved
| throw new UnprocessableEntityHttpException('Newsletter not found'); | ||
| } | ||
|
|
||
| $referer = $request->headers->get('referer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
referer is unreliable. We have to send location.origin manually from the frontend.
| $validationResult = $this->domainValidationService->validateDomain($newsletter, $domain); | ||
|
|
||
| if (!$validationResult->isAllowed) { | ||
| $settingsUrl = $this->appConfig->getUrlApp() . '/console/' . $newsletter->getId() . '/settings'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console URL uses the slug, not the ID
| name VARCHAR(255) NOT NULL, | ||
| test_sent_emails JSONB | ||
| test_sent_emails JSONB, | ||
| allowed_domains JSONB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think messing with null everywhere would be a mistake. Make it not-null and set the default to an empty array
| /** | ||
| * @var string[]|null | ||
| */ | ||
| public ?array $allowed_domains; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it not null
| /** | ||
| * @var string[]|null | ||
| */ | ||
| public ?array $allowed_domains; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not null
| $this->subdomain = $newsletter->getSubdomain(); | ||
| $this->created_at = $newsletter->getCreatedAt()->getTimestamp(); | ||
| $this->name = $newsletter->getName(); | ||
| $this->allowed_domains = $newsletter->getAllowedDomains() ?? []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here null coalescing would not be needed
| * @var string[]|null | ||
| */ | ||
| #[ORM\Column(type: 'json')] | ||
| private ?array $allowed_domains = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not null
| // But we need the inverse: check if embedDomain is a subdomain of user's domain | ||
| // | ||
| // We fetch active domains and check in PHP for reliability | ||
| $domains = $this->createQueryBuilder('d') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad solution: can't load all domains into memory. Some accounts may have thousands of domains.
|
|
||
| namespace App\Service\Domain; | ||
|
|
||
| readonly class DomainValidationResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the class name must be changed, since this is only about the form domain, not the sending domains
Close #317