Accessing outside data question Options
desmo
Posted: Thursday, August 24, 2006 4:57:24 PM

Rank: Aficionado

Joined: 7/19/2006
Posts: 171
Location: NYC
I'm working on an Umbraco site that needs to access outside data. Currently, I'm using a technique based on Kasper's flickr post [url href="http://kasperb.dk/2006/6/26/display_your_flickr_images_on_your_umbraco_driven_website.aspx"]here[/url].

(hope that link works...)

I pass in parameters via the querystring, a macro loads a page that dumps SQL Server query results to XML and use XSLT to parse the results. This works nicely, but may not be the most efficient way to do this. And I understand that maybe I should be using a library to do this.

Given all that, here's my question. Is there a way for me to grab the data as above in a macro, and then access this same data with other macros in the template? Something like UMBRACO_GETITEM but for my own dataset?

If I sat down with one of you guys for 10 minutes, I'm sure you could show me how to do a library, but you're all too far away at the moment. :-)

I know this is a slightly involved question, but if anyone has any good advice, I'd love to hear it. I would prefer to use the method I have now, but if I really should be doing a library, let me know.

Thanks!

- Mark
Gregorius
Posted: Friday, August 25, 2006 5:57:21 AM

Rank: Addict

Joined: 7/29/2006
Posts: 507
Location: Melbourne, Australia

Great question Mark... Unfortunately I can't answer it, just posting so I get notified of responses. ;)

Wishes he could work with Umbraco all the time.
hartvig
Posted: Friday, August 25, 2006 10:18:05 AM

Rank: Addict

Joined: 3/17/2008
Posts: 952
Location: Nyborg, Denmark
Our special agent from Belgium aka Len has posted a library that might get you further:
http://forum.umbraco.org/extending-umbraco/xslt-extension-dll-for-querying-databases

Jeeeez, did I really start this :-)
twynham
Posted: Saturday, August 26, 2006 2:14:05 PM
Rank: Devotee

Joined: 7/28/2006
Posts: 57
Mark Burnham wrote:


I pass in parameters via the querystring, a macro loads a page that dumps SQL Server query results to XML and use XSLT to parse the results. This works nicely, but may not be the most efficient way to do this. And I understand that maybe I should be using a library to do this.



Sounds good, but make sure to watch for SQL injection here. For the benefit of others, suppose you have a drop down which populates a page by selecting the product category, the query might look like:

SELECT * FROM products WHERE product_type = 'eggchairs';

...the URL to do this becomes something like:

/mypage.aspx?category=eggchairs

...where the category is placed into the SQL query. BUT, if I re-write the URL to:

/mypage.aspx?category=eggchairs';%20exec..master%20xp_cmdshell%20'net%20user%20john%20john%20/add';%20exec..master%20xp_cmdshall%20'net%20localgroup%20administrators%20john%20/add';--

...I am able to append other SQL commands onto the end of the SELECT statement - I've now created a new administrator on your computer called "john", and can now easily take over your life... :dontgetit:

Solution:

1) Escaping single quotes helps (replace ' with '') BUT there are plenty of other ways to inject SQL... Integers are a particular problem, so need to be cast as such.

2) Best bet is to build a dedicated library of functions where the SQL calls are hard coded AND parameterised (google if you don't know). This largely(-ish!) solves the problem because parameters are passed to the server separately and the SQL interpreter cannot mistake parameters for SQL commands.

For example, you might now want to create: mylibrary.lookupProductsByType(string productType) instead of mylibrary.doGenericSqlCall(string query)

Stewart
Bawden Quinn Associates
UK

Bawden Quinn Associates, UK
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.