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

Harden JSONP callback filter #1553

Merged
merged 1 commit into from
Nov 22, 2023
Merged

Harden JSONP callback filter #1553

merged 1 commit into from
Nov 22, 2023

Conversation

osma
Copy link
Member

@osma osma commented Nov 21, 2023

Reasons for creating this PR

I noticed that the FILTER_UNSAFE_RAW input filter was still used once in the Controller, for processing the name of the JSONP callback method/function. As the name implies, this filter is unsafe by design. In PR #1385, other input filters were changed but not this one. I don't see why a stricter filter couldn't be used here, because JSONP callbacks are typically just alphanumeric function names, so this PR switches to FILTER_SANITIZE_FULL_SPECIAL_CHARS.

In practice, this is very unlikely to be exploitable at least in the normal JSONP usage scenario (which itself has gone out of fashion as applications have switched to CORS). The application constructing the JSONP URL already has full control of the JS environment, so being able to run arbitrary JS code via the callback method name doesn't add any new capabilities. But better safe than sorry, and maybe code scanning tools will be happier.

Link to relevant issue(s), if any

Description of the changes in this PR

  • switch the input filter used for JSONP callback method names to FILTER_SANITIZE_FULL_SPECIAL_CHARS

Known problems or uncertainties in this PR

This needs to be adapted to Skosmos 3 as well and applied to the skosmos-3 branch.

Checklist

  • phpUnit tests pass locally with my changes
  • I have added tests that show that the new code works, or tests are not relevant for this PR (e.g. only HTML/CSS changes)
  • The PR doesn't reduce accessibility of the front-end code (e.g. tab focus, scaling to different resolutions, use of .sr-only class, color contrast)
  • The PR doesn't introduce unintended code changes (e.g. empty lines or useless reindentation)

@osma osma added the bug label Nov 21, 2023
@osma osma added this to the 2.17 milestone Nov 21, 2023
@osma osma self-assigned this Nov 21, 2023
Copy link

sonarcloud bot commented Nov 21, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link

codecov bot commented Nov 21, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (e9e5447) 70.20% compared to head (33ef7e8) 70.20%.

Files Patch % Lines
controller/RestController.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1553   +/-   ##
=========================================
  Coverage     70.20%   70.20%           
  Complexity     1664     1664           
=========================================
  Files            32       32           
  Lines          4293     4293           
=========================================
  Hits           3014     3014           
  Misses         1279     1279           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@osma osma merged commit 88c2c78 into master Nov 22, 2023
13 of 17 checks passed
@osma osma deleted the fix-jsonp-callback-filter branch November 22, 2023 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done (verified in test.dev.finto.fi, set Milestone 3.0 for both issue & PR)
Development

Successfully merging this pull request may close these issues.

2 participants