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

Fix insert #1465

Merged
merged 1 commit into from
Jan 31, 2023
Merged

Fix insert #1465

merged 1 commit into from
Jan 31, 2023

Conversation

jotoeri
Copy link
Member

@jotoeri jotoeri commented Jan 26, 2023

@susnux I think you're right, that the insert is open currently, since the combination of PublicPage and CORS is not good.
However, i think we can remove the PublicPage condition in server, since that seems to me has been the fix when the CSRF-token was not allowed on CORS routes yet. As a quick-fix, i'd just execute the CORS-Routine here for now. We can just revert the commit, once server got fixed accordingly.

@jotoeri jotoeri added bug Something isn't working high High priority 3. to review Waiting for reviews labels Jan 26, 2023
@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Merging #1465 (7c05603) into main (1d315eb) will decrease coverage by 0.36%.
The diff coverage is 0.00%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1465      +/-   ##
============================================
- Coverage     35.83%   35.47%   -0.36%     
- Complexity      520      532      +12     
============================================
  Files            51       52       +1     
  Lines          2202     2224      +22     
============================================
  Hits            789      789              
- Misses         1413     1435      +22     

@susnux
Copy link
Collaborator

susnux commented Jan 26, 2023

Looks like a valid solution, I thought about something similar: Adding a custom Middleware for our API controller with a similar validation function. This might be cleaner?

@jotoeri jotoeri force-pushed the fix/csrf branch 4 times, most recently from c439b88 to 6fa099a Compare January 27, 2023 00:12
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
@jotoeri
Copy link
Member Author

jotoeri commented Jan 27, 2023

Yeah, changed it to a middleware now. It's a slightly modified procedure to mainly use the public interfaces, but basically the same as in the CORSMiddleware.

public function beforeController($controller, $methodName) {
// ensure that @CORS annotated API routes are not used in conjunction
// with session authentication since this enables CSRF attack vectors
if ($this->reflector->hasAnnotation('PublicCORSFix')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am correct, this will check every user and even throw if anonymous submit as the user is not set.
In this case we could simply drop @PublicPage.

If we want to support anonymous submission we should change this to:

if ($this->reflector->hasAnnotation('PublicCORSFix') && $this->userSession->isLoggedIn())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public Pages pass the CSRF Check. Thus it works to submit anonymously.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So request->passesCSRFCheck() returns true for anonymous requests without csrf token?
Because if not, anonymous requests would be blocked by line 79.
That's why I suggested the change to only check logged in users, so that anonymous responses are still possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, csrfcheck result should of course be independent of the user/anonymous. But our own pages pass the csrf check. Didn't test now, but even with the embedding we should still have a valid csrf token.

Indeed, what does not work are anonymous requests from a foreign source. But do we really want to open that? Or shouldn't all external requests be authenticated? Feels a bit like a hole on its own to open that... 😕

Copy link
Collaborator

@susnux susnux Jan 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not change the behavior here, as currently anonymous submissions from extern are allowed, so this would break such usage cases. Not sure on how high the threat of CSRF of anonymous submissions is, you could submit with the IP of someone else or send spam with the IP of someone else. (But having a breaking change is the only real reason here for me not disallowing anonymous submissions without session)


While writing this I noticed this is the only endpoint working anonymously, so it does not make much sense having this available from external pages, as you can not even request a public share from external without authentication. (only no admin required and cors is set so the user must be authenticated).

Copy link
Collaborator

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works as expected 👍

@jotoeri jotoeri merged commit eb1d45f into main Jan 31, 2023
@jotoeri jotoeri deleted the fix/csrf branch January 31, 2023 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug Something isn't working high High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants