[1.x] Kontainer media

Created on 24 November 2023, 12 months ago
Updated 11 March 2024, 8 months ago

This module provides an integration of Kontainer DAM with Drupal. Provides creation of media entities/reference of CDN links from Kontainer and a Kontainer files usage statistics GET endpoint for usage tracking on the DAM side.

Project Link

https://www.drupal.org/project/kontainer

Manual reviews of other projects

Testsuite
URL Text
Summary Only

📌 Task
Status

Fixed

Component

module

Created by

🇸🇮Slovenia slogar32

Live updates comments and jobs are added and updated live.
  • PAreview: review bonus

    This issue tag is used in the "Drupal.org security advisory coverage applications" queue for applications that follow the review bonus program.

Sign in to follow issues

Comments & Activities

  • Issue created by @slogar32
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Thank you for applying!

    Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

    The important notes are the following.

    • If you have not done it yet, you should run phpcs --standard=Drupal,>DrupalPractice on the project, which alone fixes most of what reviewers would report.
    • For the time this application is open, only your commits are allowed.
    • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status will not be changed by this application; no other user will be able to opt projects into security advisory policy.
    • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the branch to review and the project name.

    To the reviewers

    Please read How to review security advisory coverage applications , Application workflow , What to cover in an application review , and Tools to use for reviews .

    The important notes are the following.

    • It is preferable to wait for a Code Review Administrator before commenting on newly created applications, even to leave a comment similar to the following one. Code Review Administrators will do some preliminary checks that are necessary before any change on the project files is suggested.
    • It is also preferable to wait before using a CLI tool to report what needs to be changed, especially because the comment left from Code Review Administrators suggests to use PHP_CodeSniffer. Before that, manual reviews should be done.
    • Reviewers should not copy-paste the output of a CLI tool. They should use a CLI tool only once per application. When they do that, they should later verify the code has been correctly changed; this means, for example, that adding a documentation comment that is not correct just to avoid to get a warning/error is not a correct change that should be reported in a further comment.
    • It may be best to have the applicant fix things before further review.

    For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues .

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work 11 months ago
  • 🇮🇳India vishal.kadam Mumbai

    1. FILE: kontainer.module

    /**
     * @file
     * Drupal Module: Kontainer.
     */

    The description for a module is Hook implementations for the [module name] module. where [module name] is the module name given in the .info.yml file.

    2. The documentation comment for constructors is not mandatory anymore, If it is given, the description must be Constructs a new [class name] object. where [class name] includes the class namespace.

      /**
       * Class constructor.
       *

    Function and method declarations are written on a single line.

    src/Plugin/Field/FieldFormatter/KontainerCdnFormatter.php
    src/Plugin/Field/FieldWidget/KontainerCdnItemWidget.php
    src/Plugin/Field/FieldWidget/KontainerReferenceItemWidget.php
    src/Plugin/Validation/Constraint/KontainerLinkConstraintValidator.php
    src/Plugin/media/Source/KontainerFileAssetDeriver.php
    src/Service/KontainerService.php
    src/Form/KontainerConfigForm.php
    src/Controller/KontainerController.php

  • Assigned to slogar32
  • Issue was unassigned.
  • Status changed to Needs review 11 months ago
  • 🇸🇮Slovenia slogar32

    Thank you for your feedback!

    I have fixed everything from your list of findings. The changes have been pushed to the 1.x branch. If there is something more to do, please let me know.

  • Status changed to Needs work 11 months ago
  • 🇮🇳India vishal.kadam Mumbai

    docs and main are wrong names for a branch and should be removed. Release branch names always end with the literal .x as described in Release branches .

    The only exception is for the main branch, which is actually not fully supported on drupal.org and should be avoided.

  • Status changed to Needs review 11 months ago
  • 🇸🇮Slovenia slogar32

    Both branches have been deleted.

  • 🇸🇮Slovenia slogar32

    I am changing the issue priority as per issue priorities .

  • Status changed to RTBC 10 months ago
  • 🇺🇸United States trigve hagen Washington DC

    There are a couple of the phpcs error in this file. Code looks good. No duplication of code or functionality that I could see. README.md looks good, No security vulnerabilities that I can see off hand. Moving to Reviewed and tested if no one objects.

    FILE: /var/www/html/global/web/modules/contrib/kontainer/js/kontainer.js
    ---------------------------------------------------------------------------------------------
    FOUND 7 ERRORS AFFECTING 5 LINES
    ---------------------------------------------------------------------------------------------
    3 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
    7 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
    28 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
    34 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
    63 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
    63 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
    63 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
    ---------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------

    Time: 3.75 secs; Memory: 12MB

  • 🇸🇮Slovenia slogar32

    Thanks for the extra review! Yeah, this is in the JS file, but you can't write FALSE, TRUE and NULL upper case in JS, so this Drupal standard should be ignored for the Javascript file, DrupalPractice doesn't return any errors for it also.

  • Status changed to Needs work 9 months ago
  • 🇦🇹Austria klausi 🇦🇹 Vienna

    manual review:

    1. rote kontainer.delete_media_types: this is vulnerable to CSRF exploits as this is a destructive operation. You need to protect the route with a CSRF token or confirmation form.
    2. KontainerAuth::authenticate(): this is vulnerable to timing attacks. When comparing secret strings you need to use the hash_equals() function instead of "===".
    3. KontainerReferenceItemWidget::formElement(): there should be a way to generate URLs with manually setting up the CSRF token. If you use the normal URL generator it should spit out the URL including the CSRF token, as Drupal knows that the route should be CSRF protected.
    4. kontainer.create_media: This route is missing access control? What permission does the user need to create media? The CSRF token is not an access protection, it is a validation of user intent. Looks like an access bypass vulnerability.

    Please fix the 3 security vulnerabilities and check your code for other similar issues. And please don't remove the security tag, we keep that for statistics and to show examples of security problems.

  • Status changed to Needs review 9 months ago
  • 🇸🇮Slovenia slogar32

    Thank you very much for the review!

    I have some questions/information about your points:

    4. I didn't put any access requirements to the route definition in the routing.yml file, because I check this dynamically in code (see checkAccess function in KontainerService.php, which is called in the createEntities function in the controller for this route). I did this, because the media type is fetched dynamically from the JSON response each time from the Kontainer DAM, or decided based on the module configurations (if CDN is set as media source, then it is set to this value which is not in the response from the JSON.) So I would leave this as it is, if you do not see it as an access bypass vulnerability, based on this explanation.

    3. I am not exactly sure what I need to do here. I am generating the CSRF token based on the route path, then I add this token to the ajaxTrustedUrl drupalSettings, where the token is added as a query parameter to the media path only (and not the URL), and I also add It to custom drupalSettings. Then in the Javascript library, where the actual call to the route is made ( url: Drupal.url(url) + '?token=' + drupalSettings.kontainer.token,) I build the URL from the values, that are generated in the widget class. I was doing this based on this example here: https://drupal.stackexchange.com/questions/221251/generating-url-with-csrf-token

    So what I see that I could change here is to actually generate the URL object in the widget class by adding the CSRF token as the URL query parameter directly to the object, and then add this URL object to the drupalSettings, instead of building the URL in the Javascript library with Drupal.url(). But the CSRF token generation would stay as it is. Is this the direction, that you are pointing me to? If not, could you please provide me an explanation or an example, that would lead me in the right direction? Thanks!

    Points 1 and 2 are clear to me. I will push those fixes by the end of this week, but I would again kindly ask you to provide some information on the above two points, when you have some time (I am putting the application back to Needs review, so you see my questions, even though I didn't push any changes yet).

    Thank you again for the feedback!

  • 🇸🇮Slovenia slogar32

    I have now pushed the changes for points 1. and 2. from the above list, and explained number 4. in my above comment. I understand, that those were the 3 security issues that were mandatory to fix. If I need to do something on point 3 from the list, please read my above questions and point me in the right direction. Otherwise, I think this is ready for review now.

  • Status changed to Fixed 9 months ago
  • 🇦🇹Austria klausi 🇦🇹 Vienna

    Thanks for the fixes!

    kontainer.create_media: ah I see, did not see the access check later in the service. I would recommend to untangle that and do the access checking explicitly on the routing layer, then there is a lower risk that this gets lost in a refactoring for example.

    Generating URLs with CSRF token: it works like this, which you can use similarliy for your ajaxTurstedUrl

    use Drupal\Core\Url;
    $route_name = 'system.run_cron';
    $url = Url::fromRoute($route_name);
    print $url->toString();
    

    Which will output /admin/reports/status/run-cron?token=QJoWTyS5Bcf8KP_gvhmjUwm-s1rlrvSqL3XHgVsxEKQ
    Or do you need to CSRF token standalone for some reason? It is only every useful in combination with the path?

    src/Authentication/Provider/KontainerAuth.php: hash_equals(): Caution: It is important to provide the user-supplied string as the second parameter, rather than the first. You are doing that wrong. But I think it is very hard to exploit this with a timing attack, so would consider this a security hardening and not a security blocker.

    Otherwise looks good to me!

    Thanks for your contribution, Domen!

    I updated your account so you can opt into security advisory coverage now.

    Here are some recommended readings to help with excellent maintainership:

    You can find lots more contributors chatting on Slack or IRC in #drupal-contribute. So, come hang out and stay involved !

    Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review . I encourage you to learn more about that process and join the group of reviewers.

    Thanks to the dedicated reviewer(s) as well.

  • 🇸🇮Slovenia slogar32

    Thank you so much for the explanations! I can say, that I learned something new and useful from this application :)

    Thank you again for your time!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024