Skip to content

fix: Make upload requests pass Spring Security checks - #11278

Merged
pleku merged 3 commits into
masterfrom
upload-internal
Jun 21, 2021
Merged

pleku merged 3 commits into
masterfrom
upload-internal

Conversation

@Artur-

@Artur- Artur- commented Jun 17, 2021

Copy link
Copy Markdown
Member

No description provided.

@Artur- Artur- changed the title Consider upload requests an internal request to work with Spring Security fix: Make upload requests pass Spring Security checks Jun 17, 2021
private static boolean isUploadRequest(
String requestedPathWithoutServletMapping) {
return requestedPathWithoutServletMapping
.matches("VAADIN/dynamic/resource/.*/.*/upload");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

With this check, one can make a call to VAADIN/dynamic/resource/../../../upload and this will return true.
I don't see any encoding done here (see isPathUnsafe method). In theory, one could have mapped something to /upload or /some-prefix-path/upload that is secured. That makes at least the contract for the HandlerHelper API method a bit broken as I don't think that URL should return true. There is also no mention of encoding/prechecking the request in the javadocs.

I would fix it just to be safe, even if it is not exploitable through VaadinWebSecurityConfigurerAdapter.java in Spring add-on (I don't know if that is the case) by bypassing security measures there for a fake upload request.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed to check the whole string for valid characters

@vaadin-bot

Copy link
Copy Markdown
Collaborator

SonarQube analysis reported 2 issues

  1. MAJOR HandlerHelper.java#L420: Define and throw a dedicated exception instead of using a generic one. rule
  2. INFO HandlerHelper.java#L432: Public static com.vaadin.flow.server.HandlerHelper.getPublicResources() may expose internal representation by returning HandlerHelper.publicResources rule

@pleku
pleku merged commit 2391524 into master Jun 21, 2021
@pleku
pleku deleted the upload-internal branch June 21, 2021 11:33
@vaadin-bot

Copy link
Copy Markdown
Collaborator

Hi @Artur- and @{commit.merged_by.login}, when i performed cherry-pick to this commit to 7.0, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick 2391524
error: could not apply 2391524... fix: Make upload requests pass Spring Security checks (#11278)
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with platform 21.0.0.alpha8. For prerelease versions, it will be included in its final version.

@darjag

darjag commented Jul 1, 2021

Copy link
Copy Markdown

I have this issue in Vaadin 20.0.3 with VaadinWebSecurityConfigurerAdapter. In my case I use with a property vaadin.urlMapping and don't test without.

@Artur-

Artur- commented Jul 1, 2021

Copy link
Copy Markdown
Member Author

The wast majority of Flow related features and fixed for Spring Security is only in Vaadin 21. For Vaadin 20 you can manually add a rule for allowing requests to VAADIN/dynamic/resource/[0-9]*/[a-z0-9-]**/upload to bypass the CSRF check

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants