Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 07, 2009 @ 10:51
    Warren Buckley
    0

    How secure would this REST call be in XSLT?

    Hello all,
    I am having a quick look at why my current twitter package has stopped working to showing your friends recent tweets.

    Doing some investigation twitter has put the rest URL I am requesting behind a username and password.

    So it would be possible to get past the authentication problems using this URL format
    http://myTwitterUsername:[email protected]/statuses/friends_timeline.xml?count=5

    But doing this call in XSLT

    <xsl:for-each select="umbraco.library:GetXmlDocumentByUrl('http://myTwitterUsername:[email protected]/statuses/friends_timeline.xml?count=5')//statuses/status">

    How secure would it be, could people figure out what someones username and password is?

    Thanks,
    Warren

  • Roel 151 posts 305 karma points
    Aug 07, 2009 @ 10:58
    Roel
    1

    That would not be secure at all since you are able to request the xslt from a client.
    Try requesting one of your xslt's from within your webbrowser: http://yourdomain.com/xslt/yourxslt.xslt

    I think I would store the username and password in the database and pass it on through a macro.

     

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 07, 2009 @ 11:05
    Warren Buckley
    0

    But the username and password would be parameters passed into the macro and not hardcoded into the XSLT.
    <xsl:value-of select="concat($userTwitterID,':',$userTwitterPass,'@','http://twitter.com/statuses/friends_timeline.xml?count=', $noStatus)" />

    Warren

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Aug 07, 2009 @ 11:08
    Morten Christensen
    0

    Have you tried runing the xslt throug a browser runing a tool like Fiddler for IE - don't know if you are familiar with the tool, but it can show you all requests being made when you enter a site.

    Runing a page with your xslt function will show you if the username and password is sent in clear text ... I'm not really sure that this type of request stays serverside, maybe someone else can answer that. But with the above tool you should be able to get closer to an answer.

    http://www.fiddler2.com/fiddler2/

    - Morten

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 07, 2009 @ 11:10
    Warren Buckley
    0

    Thanks Morten I will give that a try and report back later.

    Warren :)

  • Roel 151 posts 305 karma points
    Aug 07, 2009 @ 11:10
    Roel
    0

    @Warren I thought you meant hardcoded :) I would not recommend that!

    Furthermore I'm with Morten, not quite sure what you will see with fiddler. Would be worth trying...

  • Sjors Pals 617 posts 270 karma points
    Aug 07, 2009 @ 11:13
    Sjors Pals
    0

    A few months ago i found a pretty nice c# wrapper for the Twitter API, in that case the account credentials where in a config file, maybe an option to use that library?

  • leeatkinson 33 posts 44 karma points
    Aug 07, 2009 @ 11:20
    leeatkinson
    1

    As long as no-one can request the username and password from the website (i.e. as Roel says for request XSLT) it will be secure.

    (Cripes, I hadn't thought it was possible to make requests to the .xslt in the browser - will Umbraco still work if I blocked access to this?)

    Someone could sniff the username and password if they got in between your server and Twitter if you weren't using https or used Basic Authentication.

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Aug 07, 2009 @ 11:25
    Simon Dingley
    0

    Sjors, which wrapper was that? Twitterizer?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 07, 2009 @ 11:34
    Morten Bock
    1

    Question is if the parameters sent to a macro are shown in the umbDebugShowTrace=true output. You may want to test that as well...

  • Sjors Pals 617 posts 270 karma points
    Aug 07, 2009 @ 12:27
    Sjors Pals
    0

    Simon i thought i used Yedda.

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 08, 2009 @ 19:40
    Warren Buckley
    0

    OK guys, looked at this and I am not sure I can do the remote XML call with umbraco.library:GetXmlDocumentByUrl

    As I am no coding guru, could someone help me to see if the XSLT extension would be able to do the type of URL call I am after please.

            /// <summary>
    /// Fetches a xml file from the specified url.
    /// the Url can be a local url or even from a remote server.
    /// </summary>
    /// <param name="Url">The URL.</param>
    /// <returns>The xml file as a XpathNodeIterator</returns>
    public static XPathNodeIterator GetXmlDocumentByUrl(string Url)
    {
    XmlDocument xmlDoc = new XmlDocument();
    WebRequest request = WebRequest.Create(Url);
    try
    {
    WebResponse response = request.GetResponse();
    Stream responseStream = response.GetResponseStream();
    XmlTextReader reader = new XmlTextReader(responseStream);

    xmlDoc.Load(reader);

    response.Close();
    responseStream.Close();
    }
    catch (Exception err)
    {
    xmlDoc.LoadXml(string.Format("<error url=\"{0}\">{1}</error>",
    HttpContext.Current.Server.HtmlEncode(Url), err));
    }
    XPathNavigator xp = xmlDoc.CreateNavigator();
    return xp.Select("/");
    }

     

    As a reminder this is the URL I am passing into GetXmlDocumentByUrl but this is not hardcoded BTW ;)
    http://myUsername:[email protected]/statuses/friends_timeline.xml?count=5

    Warren :)

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 08, 2009 @ 21:51
    Morten Bock
    0

    Hi Warren. I get a 401 unauthorized error when trying to use that code. Will try debugging a bit, but that is the current status :-)

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 08, 2009 @ 21:59
    Morten Bock
    1

    Just tested this in a small windows app, so it's not tested in umbraco, but try making your own extension like this:

            public static XPathNodeIterator GetXmlDocumentByUrl(string Url, string user, string password)
            {
                XmlDocument xmlDoc = new XmlDocument();
                WebRequest request = WebRequest.Create(Url);
                request.Credentials = new NetworkCredential(user, password);
                try
                {
                    WebResponse response = request.GetResponse();
                    Stream responseStream = response.GetResponseStream();
                    XmlTextReader reader = new XmlTextReader(responseStream);
    
                    xmlDoc.Load(reader);
    
                    response.Close();
                    responseStream.Close();
                }
                catch (Exception err)
                {
                    xmlDoc.LoadXml(string.Format("<error url=\"{0}\">{1}</error>",
                                                 HttpContext.Current.Server.HtmlEncode(Url), err));
                }
                XPathNavigator xp = xmlDoc.CreateNavigator();
                return xp.Select("/");
            }

    I got it working. Just added on line of code, and a couple of parameters to the method.

     

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 09, 2009 @ 16:26
    Warren Buckley
    0

    Morten looks like this will do the job, have yet to test it yet. Will try out tomorrow when I am back into full swing and out of holiday mode.

    Warren :)

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 10, 2009 @ 10:25
    Warren Buckley
    0

    Morten I am getting this error
    The name 'HttpContext' does not exist in the current context for this line:

    xmlDoc.LoadXml(string.Format("<error url=\"{0}\">{1}</error>",HttpContext.Current.Server.HtmlEncode(Url), err));

    The namepsaces/references I have included are the following:

    using System.Xml.XPath;
    using System.Xml;
    using System.Net;
    using System.IO;

    Have I missed any or am I doing anything wrong?

    Thanks,
    Warren

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 10, 2009 @ 10:38
    Warren Buckley
    0

    For reference it was missing this refrerence:

    using System.Web;

     

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 10, 2009 @ 14:14
    Warren Buckley
    0

    Hey Guys,
    I have updated the twitter for umbraco package/project to use this remote XML call.

    @Morten Christensen as I have no idea really how this fiddler works - would you mind testing this package out and see if the call to twitter is secure or not.

    http://twitter4umbraco.codeplex.com

    http://our.umbraco.org/projects/twitter-for-umbraco

    The more testers the better.

    Thanks,
    Warren

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Aug 10, 2009 @ 14:28
    Morten Christensen
    1

    Okay, I'll try and give it a go and let you know later today.

    - Morten

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 10, 2009 @ 15:21
    Warren Buckley
    0

    Please re-download as was typo in package action for registering XSLT extension.

     

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Aug 10, 2009 @ 16:48
    Morten Christensen
    1

    @Warren, I installed your twitter package and checked it with Fiddler - nothing was sent in clear text (requests, headers etc.) or anything else that could be considered a security concern, so it looks like you are good to go ;-)

    - Morten

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 10, 2009 @ 16:55
    Warren Buckley
    0

    Excellent that is great news. I presumed the package actually worked yeh?

    Warren :)

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 10, 2009 @ 17:00
    Warren Buckley
    0

    Dammn the username/pass can be seen with ?umbDebugShowTrace=true
    Anyway to disable this? - so I can put a warning with the package or do you think I should remove that piece of functionality instead?

    Warren :)

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 10, 2009 @ 20:28
    Morten Bock
    1

    Hi Warren. You can disable it by setting this key in the web.config

        <add key="umbracoDebugMode" value="false" />

    That disaples the querystring debug info.

  • Simon Justesen 436 posts 203 karma points
    Aug 11, 2009 @ 01:29
    Simon Justesen
    0

    Wouldn't it be possible to write a piece of C# code that takes a peek in the web.config and store the twitter username/password there?

    *.config files are not served to the public so that would sort of eliminate the potential risk of having your credentials exposed, or?

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 11, 2009 @ 10:20
    Warren Buckley
    0

    So do you think the best idea is to have a config file for this then?
    What is the convention for package authors on where to store .config files then?

    Warren :)

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 11, 2009 @ 10:30
    Peter Dijksterhuis
    0

    I'd store the config-file in the config-folder. As simon said: config-files aren't served to public (unless someone messed with the IIS-configuration...).

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 11, 2009 @ 10:35
    Warren Buckley
    0

    OK something to do at lunch time then to fix this problem.

Please Sign in or register to post replies

Write your reply to:

Draft