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

publicly available node AccessDenied, when get info about node #228

Open
Kors1981 opened this issue Mar 1, 2023 · 4 comments
Open

publicly available node AccessDenied, when get info about node #228

Kors1981 opened this issue Mar 1, 2023 · 4 comments

Comments

@Kors1981
Copy link

Kors1981 commented Mar 1, 2023

Description:
Im using GetNodeFromLinkAsync method, to get Node on the following url
https://mega.nz/file/B7BnxarD#pt_9ebHpGvzCi3LBVVfBcudIys7mZGma_wHHquWTEkE
I get AccessDenied apiexception, though url can be opened in browser.

what are you trying to do

Actual Behavior:

what happens

Expected Behavior:
I expect to get back Node.

what should happen

Steps to Reproduce:

MegaApiClient Version: latest

@gpailler
Copy link
Owner

gpailler commented Mar 6, 2023

Hello,

I'm not able to reproduce the issue you described with the following test

[Theory]
[InlineData("https://mega.nz/file/B7BnxarD#pt_9ebHpGvzCi3LBVVfBcudIys7mZGma_wHHquWTEkE")]
public async void GetNodeFromLinkAsync_Succeeds(string fileLink)
{
  var instance = new MegaApiClient();
  await instance.LoginAnonymousAsync();
  var node = await instance.GetNodeFromLinkAsync(new Uri(fileLink));

  Assert.NotNull(node);
  Assert.Equal("fm.png", node.Name);
  Assert.Equal(597194, node. Size);
}

Could you provide a small sample?

@adeyblue
Copy link

adeyblue commented Mar 19, 2023

It happens when querying a just created folder now. The created folder shows up as 'undecrypted folder' in the web file manager

using System;
using System.Collections.Generic;
using CG.Web.MegaApiClient;

namespace ConsoleApp1
{
    class Program
    {
        static INode GetRootNode(MegaApiClient client)
        {
            IEnumerable<INode> newNodes = client.GetNodes();
            INode rootNode = null;
            foreach (INode node in newNodes)
            {
                if (node.Type == NodeType.Root)
                {
                    rootNode = node;
                    break;
                }
            }
            return rootNode;
        }

        static void Main(string[] args)
        {
            MegaApiClient client = new MegaApiClient();
            try
            {
                MegaApiClient.LogonSessionToken token = client.Login("email", "pass");
                Console.WriteLine("Logged in on session {0}", token.SessionId);
                INode rootNode = GetRootNode(client);
                string upFile = args[0];
                INode testFolder = client.CreateFolder("testFolder", rootNode);
                Console.WriteLine("Created {0}, type {1}, size {2}, id {3}", testFolder.Name, testFolder.Type, testFolder.Size, testFolder.Id);
                Console.WriteLine("Getting link");
                Uri link = client.GetDownloadLink(testFolder);
                Console.WriteLine("Got link {0}", link);
                INode newFolderNode = client.GetNodeFromLink(link);
                Console.WriteLine("Got node {0}, type {1}, size {2}, id {3}", newFolderNode.Name, newFolderNode.Type, newFolderNode.Size, newFolderNode.Id);
            }
            catch(Exception e)
            {
                Console.WriteLine("Caught exception type {0}: ({1}){2}{3}", e.GetType().Name, e.Message, Environment.NewLine, e.StackTrace);
            }
            client.Logout();
        }
    }
}

Logged in on session f_vJfH_...
Created testFolder, type Directory, size 0, id P9xj2CDZ
Getting link
Got link https://mega.nz/folder/bt5gGCSS#NNIYUaTjxQom2jvgzJgGeA
Caught exception type ApiException: (API response: AccessDenied)
at CG.Web.MegaApiClient.MegaApiClient.RequestCore[TResponse](RequestBase request, Byte[] key) in //MegaApiClient/MegaApiClient.cs:line 1136
at CG.Web.MegaApiClient.MegaApiClient.Request[TResponse](RequestBase request, Byte[] key) in /
/MegaApiClient/MegaApiClient.cs:line 1092
at CG.Web.MegaApiClient.MegaApiClient.GetNodeFromLink(Uri uri) in /_/MegaApiClient/MegaApiClient.cs:line 672
at ConsoleApp1.Program.Main(String[] args) in T:\nettest\ConsoleApp1\Program.cs:line 38

@gpailler
Copy link
Owner

gpailler commented Mar 19, 2023

The link references a folder so you should use GetNodeSFromLink() method instead.
I will update the library to throw a meaningful exception when GetNode(s)FromLink are called with incorrect url

gpailler added a commit that referenced this issue Mar 19, 2023
… folder share or GetNodesFromLink() with a file share
@adeyblue
Copy link

adeyblue commented Mar 24, 2023

Thanks, still having problems though.
This code with this link
https://mega.nz/folder/L1xlRRAL#I5Lq0N5aUBT4dyLgp0QPFg
shows

Logged in on session Saz...
Got node Attribute deserialization failed: Unexpected character encountered while parsing value: ?. Path '', line 0, position 0., type Root, size 0, id O8AWGJBa

Got node Attribute deserialization failed: Unexpected character encountered while parsing value: (. Path '', line 0, position 0., type File, size 507568, id 68BWELLS

Both the file and folder are named AMlNVS0u1Co0STJw0CrOyHBTSMtLUcvPLHDML1fwVE9LUVYsMFUwydNNSwgoSAIL.
Trying to access the link via web browser shows 'Invalid decryption key' but that's the link that was generated by GetDownloadLink and is the one Mega shows.
link

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using CG.Web.MegaApiClient;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            MegaApiClient client = new MegaApiClient();
            try
            {
                MegaApiClient.LogonSessionToken token = client.Login("mail", "pass");
                Console.WriteLine("Logged in on session {0}", token.SessionId);
                Uri link = new Uri(args[0]);
                IEnumerable<INode> newFolderNodes = client.GetNodesFromLink(link);
                foreach (INode dlNode in newFolderNodes)
                {
                    Console.WriteLine("Got node {0}, type {1}, size {2}, id {3}", dlNode.Name, dlNode.Type, dlNode.Size, dlNode.Id);
                }
            }
            catch(Exception e)
            {
                Console.WriteLine("Caught exception type {0}: ({1}){2}{3}", e.GetType().Name, e.Message, Environment.NewLine, e.StackTrace);
            }
            client.Logout();
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@gpailler @adeyblue @Kors1981 and others