Skip to content
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

Add CSRF protection #105

Open
cedricfrancoys opened this issue Mar 24, 2024 · 0 comments
Open

Add CSRF protection #105

cedricfrancoys opened this issue Mar 24, 2024 · 0 comments

Comments

@cedricfrancoys
Copy link
Collaborator

We need to ensure that requests from identified users are made via an application provided by the original site (and not through a link [even if valid] received from another source), which for some controllers could lead to CSRF attacks.

So, we limit ourselves to two things:

  1. Check the presence of the CSRF token when it's a required condition.
  2. When it's present, verify that the token is valid (generated by the backend).

Note: CSRF mechanism cannot be implemented on public routes. If deemed necessary, it indicates a flaw in the application logic (public routes should never trigger the execution of sensitive actions).

  1. Implement a two-part structure:
    format : {payload}.{signature}
    payload corresponds to a JSON object, base64 encoded, with the structure {body: bin2hex(random_bytes(10)), time: time()}
    signature corresponds to the payload, hashed with the installation's secret key.

  2. implement verification when required
    To verify the token's validity, we extract the payload and generate a hash from it using the installation's secret key. The obtained value should match the received signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant