<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,6 @@
 require 'open-uri'
 require 'base64'
+require 'digest/sha1'
 
 # Load RMagick
 begin</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,16 +17,27 @@ module Fleximage
     module ClassMethods
       
       # Invoke this method to enable this controller to allow editing of images via Aviary
-      def editable_in_aviary(model_class)
+      def editable_in_aviary(model_class, options = {})
+        unless options.has_key?(:secret)
+          raise ArgumentError, &quot;:secret key in options is required.\nExample: editable_in_aviary(Photo, :secret =&gt; \&quot;My-deep-dark-secret\&quot;)&quot;
+        end
+        
         # Don't verify authenticity for aviary callback
         protect_from_forgery :except =&gt; :aviary_image_update 
         
         # Include the necesary instance methods
         include Fleximage::AviaryController::InstanceMethods
         
+        # Add before_filter to secure aviary actions
+        before_filter :aviary_image_security, :only =&gt; [:aviary_image, :aviary_image_update]
+        
+        # Allow the view access to the image hash generation method
+        helper_method :aviary_image_hash
+        
         # Save the Fleximage model class
         model_class = model_class.constantize if model_class.is_a?(String)
         dsl_accessor :aviary_model_class, :default =&gt; model_class
+        dsl_accessor :aviary_secret, :default =&gt; options[:secret]
       end
       
     end
@@ -35,19 +46,29 @@ module Fleximage
       
       # Deliver the master image to aviary
       def aviary_image
-        model_class = self.class.aviary_model_class
-        @model = model_class.find(params[:id])
-        render :text =&gt; @model.load_image.to_blob, :content_type =&gt; Mime::Type.lookup_by_extension(model_class.image_storage_format.to_s)
+        render :text =&gt; @model.load_image.to_blob,
+               :content_type =&gt; Mime::Type.lookup_by_extension(self.class.aviary_model_class.image_storage_format.to_s)
       end
       
       # Aviary posts the edited image back to the controller here
       def aviary_image_update
-        @model = self.class.aviary_model_class.find(params[:id])
         @model.image_file_url = params[:imageurl]
         @model.save
         render :text =&gt; 'Image Updated From Aviary'
       end
       
+      protected
+        def aviary_image_hash(model)
+          Digest::SHA1.hexdigest(&quot;fleximage-aviary-#{model.id}-#{model.created_at}-#{self.class.aviary_secret}&quot;)
+        end
+        
+        def aviary_image_security
+          @model = self.class.aviary_model_class.find(params[:id])
+          unless aviary_image_hash(@model) == params[:key]
+            render :text =&gt; '&lt;h1&gt;403 Not Authorized&lt;/h1&gt;', :status =&gt; '403'
+          end
+        end
+      
     end
   end
   </diff>
      <filename>lib/fleximage/aviary_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -28,8 +28,9 @@ module Fleximage
     #
     # All other options are passed directly to the @link_to@ helper.
     def link_to_edit_in_aviary(text, model, options = {})
-      image_url = options.delete(:image_url)        || url_for(:action =&gt; 'aviary_image',        :id =&gt; model, :only_path =&gt; false)
-      post_url  = options.delete(:image_update_url) || url_for(:action =&gt; 'aviary_image_update', :id =&gt; model, :only_path =&gt; false)
+      key       = aviary_image_hash(model)
+      image_url = options.delete(:image_url)        || url_for(:action =&gt; 'aviary_image',        :id =&gt; model, :only_path =&gt; false, :key =&gt; key)
+      post_url  = options.delete(:image_update_url) || url_for(:action =&gt; 'aviary_image_update', :id =&gt; model, :only_path =&gt; false, :key =&gt; key)
       api_key   = Fleximage::AviaryController.api_key
       url       = &quot;http://aviary.com/flash/aviary/index.aspx?tid=1&amp;phoenix&amp;apil=#{api_key}&amp;loadurl=#{CGI.escape image_url}&amp;posturl=#{CGI.escape post_url}&quot;
       </diff>
      <filename>lib/fleximage/helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c9baa88cba13d43dbe06e8a6e8f332ab0bfcdd5c</id>
    </parent>
  </parents>
  <author>
    <name>Alex Wayne</name>
    <email>alex@beautifulpixel.com</email>
  </author>
  <url>http://github.com/Squeegy/fleximage/commit/996afb7928ee011867986416cd5a6dc114dfb8ac</url>
  <id>996afb7928ee011867986416cd5a6dc114dfb8ac</id>
  <committed-date>2009-05-24T12:49:20-07:00</committed-date>
  <authored-date>2009-05-24T12:49:20-07:00</authored-date>
  <message>Added some much needed security to aviary integration.</message>
  <tree>1e180332552c66bf2294d39b040c011eac3713c8</tree>
  <committer>
    <name>Alex Wayne</name>
    <email>alex@beautifulpixel.com</email>
  </committer>
</commit>
