Closed (fixed)
Project:
Features
Version:
8.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
5 Aug 2015 at 13:05 UTC
Updated:
2 Jan 2016 at 16:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
joshi.rohit100Comment #3
mpotter commentedCan somebody explain more of the rational behind this patch? It seemed to work in the past so is there a problem using the \Drupal::request()->getSession(); Can somebody point me to the documentation for D8 session handling?
All Features is trying to do here is pass the name of the archive being downloaded via the Session data. While this patch seems to change how the data is retrieved from the session, it doesn't address how the 'features_download' filename was originally saved to the session.
Requiring a full request stack seems overkill for just passing data via the session.
Comment #4
joshi.rohit100@mpotter :-
It is discouraged to direct access the request object. If you see the documentation of \Drupal::request(),
it itself says -
Also if you see this method, it is doing nothing but again accessing the request stack service. So if you see in this context, we are eliminating one service call.
For session documentation http://symfony.com/doc/current/components/http_foundation/introduction.h...
Comment #5
mpotter commentedBut my issue is that your patch only fixes a single call to \Drupal::request(). If you search the Features folder, you'll see dozens of other calls to set/get data via the session. Adding the request stack to all of these other class constructors just really seems overly complicated.
The comment in the docs about not using \Drupal::request() refer to issues around only working for HTTP requests, which is fine in the case of Features because we are only using it to store data for the UI. And we never store the request as warned in the docs.
Even core issues like #2473875: Convert uses of $_SESSION to symfony session retrieved from the request show replacing $_SESSION[] with \Drupal::request()->getSession(). So until I see something more conclusive that documents the best practice for replacing $_SESSION[] in D8, I'm going to stick with what we have.
Comment #6
dawehnerThere are several generic advantages of using non global calls (because this is what this basically is)
Note: The right replacement would have been:
Note2: What is the reason to not pass along the filename as parameter in the URL?
Comment #7
nedjoUm, maybe because I hadn't read the documentation? :)
Comment #8
dawehnerCool, that somehow seems way better ...
Comment #9
nedjoI looked at this a bit more and recalled that I did try passing a route parameter when I first wrote this. The problem is that in
features_file_download()we need to know which file name we're providing access to. We can't just read that information from the URI, since that would open up to all temp files.Is there a better way than the session to provide this file name information? If not, I'm thinking we do need the session and should use the approach in #6. While we're at it, it would be worth looking at the related
\Drupal::request()->getSession()calls inFeaturesGenerationArchive::exportFormSubmit()andfeatures_file_download().Comment #10
dawehnerSomething like this could work for example.
Comment #11
nedjoThat's pretty much what I started to do, but backed out of it. My concern is that, by accepting any value of
$uri, we're supporting requests to any temporary file (any value of$target), rather than just ones we have created.Compare these lines in config_file_download(), where access is granted only to the specific file:
That's the reason I used the session: to be able to pass in the file name, which varies.
Is this a concern?
Comment #12
dawehnerAn alternative could be to pass along a token as well which we can validate?
Comment #13
nedjoThat sounds right.
Comment #14
dawehnerYeah I thought this would be trivial to achieve, see the interdiff, but sadly this resulted into #2630920: _csrf_token is broken due to cacheability metadata integration, results in rendered links without valid CSRF tokens
Comment #15
dawehner.
Comment #17
nedjoThat tiny interdiff in #14 would have been too easy apparently ;) Thanks for filing the core bug. The workaround meantime make sense.
Comment #20
nedjo