Console icon indicating copy to clipboard operation
Console copied to clipboard

Unable to download file via ListView or Out-Download

Open kningyi opened this issue 3 years ago • 7 comments

Expected Behavior

File should be able to be downloaded when running the Out-Download command or clicking on the Export buttons in ListView

Example Code

$items = Get-ChildItem -path "/sitecore/content" 
$items | Show-ListView
[string[]]$data = $items | ConvertTo-Csv -NoTypeInformation
Out-Download -Name "test report.csv" -InputObject $data

Actual Behavior

Nothing gets downloaded when I run the Out-Download command. Nothing gets downloaded when I click Export XLSX or CSV in ListView. No error is shown in the blue powershell console. Wrapping the code in a try-catch block, it did not reach the catch block.

When I open browser inspector, I notice a 404 in the Network tab for the following URL:

image

/login.aspx?ReturnUrl=%2Fsitecore%2520modules%2FPowerShell%2FServices%2FRemoteScriptCall.ashx%3Fscript%3D%2F%26sc_database%26scriptDb%3Dbb08ac525a734ec7b2ca95b5b88db8f4%26apiVersion%3Dhandle

When I checked spe logs, the closest error I see is:

ManagedPoolThread #11 07:01:04 WARN  The property cannot be processed because the property "Name" already exists.At line:1 char:26
+ $ScPsSlvPipelineObject | Select-Object -Property $ScPsSlvProperties
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Exception: System.Management.Automation.PSArgumentException
Message: The property cannot be processed because the property "Name" already exists.

I have no issues running Send-File -Path "robots.txt" -NoDialog, so there's no problems in downloading files from the server.

Any ideas why I get this issue?

Error seems to only occur on one of my staging environments; I'm unable to replicate in my local or other environments.

The Spe.IdentityServer.config is already enabled.

Please include the version number of SPE and Sitecore.

  • Sitecore 10.0.1
  • Sitecore PowerShell Extensions 6.2.0.34182

kningyi avatar Nov 18 '22 07:11 kningyi

Ok, I think I managed to replicate the issue on different environments.

Basically I have password protection using basic auth on my site via this module https://github.com/nabehiro/HttpAuthModule

I have parts of the site whitelisted from password protection, including any backend urls, like those beginning with /sitecore or /-/

When I have not entered the basic auth creds in the browser for the front-facing site, I'm able to trigger downloads from the ListView or Out-Download.

However, after I entered the basic auth creds in the same browser but different tab, I get the 404 error when triggering the download. Somehow it seems like there's a 302 redirect to a 404 page..

image

I realised I missed out this warning from the SPE logs:

A request to the handleDownload service could not be completed because the provided credentials are invalid

Comparing the headers of the errored handler request with the one without error, the one that's doing a 302->404 redirect has an additional 'www-authenticate:' in the response headers and 'authorization' in the request headers from the basic auth creds.

Seems related to #1203?

When I implemented the following code in web.config, the download works whether or not I entered basic auth creds, but this seems kinda nuclear lol.

<location path="-/script/handle">
    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <remove name="www-authenticate:" />
        </customHeaders>
      </httpProtocol>
    </system.webServer>
  </location>

So any ideas on how to fix this?

kningyi avatar Nov 18 '22 10:11 kningyi

As seen in the documentation, most of the services are disabled by defaults. You can enable the handle endpoint if you want to be able to download from the UI provided by SPE.

The error message you pointed out from the log file is the key indicator that the service is disabled.

In short, this is by design and there's nothing to fix but rather configure.

michaellwest avatar Nov 18 '22 13:11 michaellwest

Read more about it here: https://doc.sitecorepowershell.com/security#configure-web-services

michaellwest avatar Nov 18 '22 13:11 michaellwest

Hmmm I'm running the code through the SPE ISE though? Documentation link looks like it's for accessing outside of Sitecore..

Also, I'm able to trigger the Out-Download as long as I do not enter any basic auth creds in my site. However, when I entered basic auth creds in the same window (hence resulting in the response header having a "www-authenticate:" for the domain), the Out-Download now fails.

kningyi avatar Nov 18 '22 15:11 kningyi

If you are testing this locally you can try the "Shields Down" config to see if everything starts working. Can you tell me the outcome of that?

michaellwest avatar Nov 18 '22 17:11 michaellwest

Yes, I already have that config in my local and same issue when I entered basic auth creds.

kningyi avatar Nov 21 '22 06:11 kningyi

Ok an update, apparently removing name="www-authenticate:" from web.config did not affect my headers. Had to implement the script workaround in https://github.com/SitecorePowerShell/Console/issues/1203#issuecomment-670036374 instead with extra line req.setRequestHeader("Authorization", ""); below req.open("GET", url, true);, no web.config changes needed.

kningyi avatar Nov 22 '22 09:11 kningyi

This seems like it was handled and, the issue also appears to be stale.

AdamNaj avatar May 09 '24 21:05 AdamNaj