faint-bear-71759
12/06/2024, 1:34 PMbrief-egg-61061
12/06/2024, 1:34 PMbrief-egg-61061
12/06/2024, 1:34 PM< set-cookie: aHR0cHM6Ly9wbGF5Z3JvdW5kLnByb2plY3RzLm9yeWFwaXMuY29tL2FwaS9rcmF0b3MvcHVibGlj_csrf_token=UlKMcLe00G8B9GjC7D1I5rvQ6P79Q0YpzKb4lo7uLtw=; Path=/api/kratos/public; Domain=<http://playground.projects.oryapis.com|playground.projects.oryapis.com>; Max-Age=31536000; HttpOnly; Secure; SameSite=None
2. The flow response also includes a CSRF token in the UI nodes, which you should include in your form submission. This token is typically found in a hidden input field named csrf_token
, as shown in the [login submission documentation](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#submit-login-flow): json { "type": "input", "group": "default", "attributes": { "name": "csrf_token", "type": "hidden", "value": "fEbwhQFcC/q5AkS9RsdqiX65Az7PTrC1tecZH4wNevAV7N/jSvVron06mYYs7y5HVedX/W2QbqGx3KvJpsvhNg==", "required": true, "disabled": false, "node_type": "input" }, "messages": [], "meta": {} }
3. When submitting the flow, you need to include both the CSRF cookie and the CSRF token from the form. For browser applications, you must send all cookies and include the CSRF token in the request body, as stated in the [submit login flow documentation](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#submit-login-flow). By following this approach, you're using Kratos' built-in CSRF protection mechanism, which is designed to work securely with its flows. Issuing your own CSRF cookie is not necessary and could potentially cause conflicts or security issues. If you're experiencing specific problems with CSRF protection in your implementation, it would be better to troubleshoot those issues rather than trying to implement your own CSRF mechanism on top of Kratos.faint-bear-71759
12/06/2024, 1:35 PMbrief-egg-61061
12/06/2024, 1:35 PMbrief-egg-61061
12/06/2024, 1:36 PMaHR0cHM6Ly9wbGF5Z3JvdW5kLnByb2plY3RzLm9yeWFwaXMuY29tL2FwaS9rcmF0b3MvcHVibGlj_csrf_token
Make sure your custom CSRF cookie name is clearly different. 3. Cookie attributes: When setting your CSRF cookie, consider using secure attributes similar to those used by Kratos. For example, set HttpOnly
, Secure
, and an appropriate SameSite
policy. 4. Token generation and validation: Implement a robust method for generating and validating CSRF tokens for your non-Kratos requests. You can refer to the [OWASP CSRF Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html) for best practices. 5. Consistent usage: Ensure that your custom CSRF protection is consistently applied to all relevant non-Kratos endpoints in your application. By implementing your own CSRF protection for non-Kratos requests while allowing Kratos to handle its own security, you can maintain a clear separation of concerns and ensure that both parts of your application are protected against CSRF attacks. Remember to thoroughly test your implementation to verify that it works correctly alongside Kratos and doesn't introduce any security vulnerabilities or usability issues.