Skip to content

Conversation

@Nolab0
Copy link
Member

@Nolab0 Nolab0 commented Dec 26, 2025

Close #317

@Nolab0 Nolab0 requested review from Nadil-K and supun-io December 27, 2025 14:16
@supun-io supun-io changed the title 317 signup form domain validation Signup form domain validation Jan 4, 2026
Copy link
Member

@supun-io supun-io left a 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');
Copy link
Member

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';
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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() ?? [];
Copy link
Member

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;
Copy link
Member

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')
Copy link
Member

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
Copy link
Member

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

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.

Signup Form: Domain Validation

3 participants