Skip to content

CI4: Fine Tune CSRF settings #3632

Closed
Closed

Description

@objecttothis

Starting in 4.0.5 there is more Cookie Samesite support. We need to fine tune these settings and potentially remove any previous efforts at CSRF if it's conflicting with the built-in CI4 implementation. We need to make any appropriate changes in the links below.

https://codeigniter.com/user_guide/installation/upgrade_405.html#cookie-samesite-support
https://codeigniter.com/user_guide/installation/upgrade_415.html#csrf-protection

Activity

  1. added this to the 3.4.0 milestone on Jan 27, 2023
  2. jekkos commented on Jan 30, 2023

    @jekkos
    Member

    good to hear they have support built in now. The session class was customized for this in CI3, we can probably get rid of this and rely on CI4 instead.

  3. objecttothis commented on Jan 30, 2023

    @objecttothis
    MemberAuthor

    I noticed we are manually writing the csrf headers in the partial/header_js.php. I think I read in the documentation that it automatically inserts CSRF tokens with the form helper when form_open is used. I'm less familiar how to do CSRF properly, so if anyone else wants this, I don't think it will be too involved. Probably mostly stripping out what we did for CI3, making sure it's properly enabled for CI4 and adding in anything lacking in the CI4 implementation. We might want to look into turning on CI4's token randomization feature as well to prevent against BREACH or similar attacks.

  4. jekkos commented on Jan 31, 2023

    @jekkos
    Member

    The form open isnt usable in case we are using Ajax calls, so thats why we need a js hook as well. We Can disable csrf temporarily and Ill try to look into it

  5. self-assigned this
    on Jan 31, 2023
  6. added
    CodeIgniter4
    on Dec 12, 2023
  7. objecttothis commented on Oct 22, 2024

    @objecttothis
    MemberAuthor

    @jekkos, while not CSRF, I did copy over the CSP directives we have in the /public/.htaccess, but I'm unable to set $CSPEnabled to true in /Config/App.php because as of now CI 4 does not yet have CSP level 3 support. Enabling without that support throws errors related to script-src-elem, style-src-attr and style-src-elem. https://forum.codeigniter.com/showthread.php?tid=88753

    Do you want to push this issue out to a milestone after 3.4.0 or should we not release until this is done?

  8. modified the milestones: 3.4.0, 3.5.0 on Nov 4, 2024
  9. modified the milestones: 3.5.0, 3.4.2 on Dec 15, 2025
  10. jekkos commented on Dec 15, 2025

    @jekkos
    Member

    @objecttothis I have re-enabled the CSRF now after a bug report by a security researcher. WIll merge once I get confirmation that it's working as it should

  11. jekkos commented on Dec 17, 2025

    @jekkos
    Member

    Should be fixed now in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CodeIgniter4enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions