[Live Components] is writeable:false realy safe? #2249
-
Hi, I have component class Captcha{
#[LiveProp(writable: false)]
public ?bool $recaptchaVerified = null;
#[LiveAction]
public function checkCaptcha(GoogleCaptcha $captcha,#[LiveArg] $token): void {
$this->recaptchaVerified = $captcha->captchaverify($token);
}
} My question is: It is property If is, How do you save state of this property on server? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Anybody know this? its realy important to use all this things. @smnandre did you know? Thanks |
Beta Was this translation helpful? Give feedback.
-
A "quick" response that simplifies many aspects but could still be useful for others. 🙂 How Does This Work?1. User Visits → First RenderA user navigates to a page like /foo/bar using a browser that includes a LiveComponent, such as a “Captcha.” 2. Server Response → BrowserWhen the browser receives the page, the LiveComponent JavaScript extracts the props from the HTML and updates any necessary values (though typically not needed during the first render). It also retains a copy of the state returned by the server. 3. User Action → ServerWhen the user interacts (e.g., clicks a live action or types in an input field), the JavaScript records these changes and maintains a map of “updated data.” No TrustFor this system to function, when the browser sends changes to the server, it must also send the previous “state” since the server doesn’t inherently know what occurred on the client side. Therefore, the server needs to trust the data coming from the browser. Multiple security measures are in place to ensure the data appears legitimate (not corrupted) and can be reused. However, this is in no way a security measure. LiveComponents facilitate interactions with users, but any modified data must be validated before being persisted or used to grant user privileges, access, etc. As with controllers, it’s the developer’s responsibility to implement authentication and authorization checks within their application. Pragmatic UsageUltimately, it’s about balancing risks and costs. To address your question:
Good PracticesUse LiveComponent Actions Only with POSTEnsure that actions triggered by LiveComponents use only POST requests. This enhances security by preventing sensitive actions from being exposed via GET requests. Follow Symfony Security RecommendationsAdhere to Symfony’s best security practices, such as strict input validation, protection against CSRF (Cross-Site Request Forgery) attacks, and utilizing built-in authentication and authorization mechanisms. Keep Dependencies UpdatedRegularly update your Composer packages to benefit from the latest security fixes and performance improvements. Use composer update routinely and check for vulnerabilities with tools like composer audit. Never Trust External SourcesAlways treat data from external sources as untrusted. Validate and sanitize all incoming data before using or storing it to prevent injections and other attacks. I hope this answers your question :) |
Beta Was this translation helpful? Give feedback.
A "quick" response that simplifies many aspects but could still be useful for others. 🙂
How Does This Work?
1. User Visits → First Render
A user navigates to a page like /foo/bar using a browser that includes a LiveComponent, such as a “Captcha.”
The PHP code renders a complete HTML page containing the LiveComponent during the first render. This includes HTML tags with the component’s props (the “state”), serialized with a checksum.
2. Server Response → Browser
When the browser receives the page, the LiveComponent JavaScript extracts the props from the HTML and updates any necessary values (though typically not needed during the first render). It also retains a copy of the state returned …