diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 29ad355f756bd93e7d4183f71f0a1d016cbed3cd..3964ea5facdc29dc7578a51447956480cfc124fb 100755
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -9697,7 +9697,18 @@
       <key>Value</key>
       <integer>1</integer>
     </map>
-    <key>RotateRight</key>
+    <key>RevokePermsOnStopAnimation</key>
+    <map>
+      <key>Comment</key>
+      <string>Clear animation permssions when choosing "Stop Animating Me"</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>Boolean</string>
+      <key>Value</key>
+      <integer>1</integer>
+    </map>
+  <key>RotateRight</key>
     <map>
       <key>Comment</key>
       <string>Make the agent rotate to its right.</string>
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 1a96699cffa3838636764558319ac81f92e3ba1d..3b83811c78925075fdf755523c5e2286b4341baa 100755
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -90,6 +90,7 @@
 #include "llwindow.h"
 #include "llworld.h"
 #include "llworldmap.h"
+#include "lscript_byteformat.h"
 #include "stringize.h"
 
 using namespace LLAvatarAppearanceDefines;
@@ -3072,6 +3073,31 @@ void LLAgent::sendAnimationStateReset()
 	sendReliableMessage();
 }
 
+
+// Send a message to the region to revoke sepecified permissions on ALL scripts in the region
+// If the target is an object in the region, permissions in scripts on that object are cleared.
+// If it is the region ID, all scripts clear the permissions for this agent
+void LLAgent::sendRevokePermissions(const LLUUID & target, U32 permissions)
+{
+	// Currently only the bits for SCRIPT_PERMISSION_TRIGGER_ANIMATION and SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS
+	// are supported by the server.  Sending any other bits will cause the message to be dropped without changing permissions
+
+	if (gAgentID.notNull() && gMessageSystem)
+	{
+		LLMessageSystem* msg = gMessageSystem;
+		msg->newMessageFast(_PREHASH_RevokePermissions);
+		msg->nextBlockFast(_PREHASH_AgentData);
+		msg->addUUIDFast(_PREHASH_AgentID, getID());		// Must be our ID
+		msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+
+		msg->nextBlockFast(_PREHASH_Data);
+		msg->addUUIDFast(_PREHASH_ObjectID, target);		// Must be in the region
+		msg->addS32Fast(_PREHASH_ObjectPermissions, (S32) permissions);
+
+		sendReliableMessage();
+	}
+}
+
 void LLAgent::sendWalkRun(bool running)
 {
 	LLMessageSystem* msgsys = gMessageSystem;
@@ -4175,9 +4201,21 @@ void LLAgent::stopCurrentAnimations()
 
 		sendAnimationRequests(anim_ids, ANIM_REQUEST_STOP);
 
-		// Tell the region to clear any animation state overrides.
+		// Tell the region to clear any animation state overrides
 		sendAnimationStateReset();
 
+		// Revoke all animation permissions
+		if (mRegionp &&
+			gSavedSettings.getBOOL("RevokePermsOnStopAnimation"))
+		{
+			U32 permissions = LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_TRIGGER_ANIMATION] | LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS];
+			sendRevokePermissions(mRegionp->getRegionID(), permissions);
+			if (gAgentAvatarp->isSitting())
+			{	// Also stand up, since auto-granted sit animation permission has been revoked
+				gAgent.standUp();
+			}
+		}
+
 		// re-assert at least the default standing animation, because
 		// viewers get confused by avs with no associated anims.
 		sendAnimationRequest(ANIM_AGENT_STAND,
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index c5b44763189372b898c10eb5ccbaf650327226ba..7fac17d098b4c1b9e078e4d9090924b462f2c916 100755
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -432,6 +432,7 @@ class LLAgent : public LLOldEvents::LLObservable
 	void			sendAnimationRequests(LLDynamicArray<LLUUID> &anim_ids, EAnimRequest request);
 	void			sendAnimationRequest(const LLUUID &anim_id, EAnimRequest request);
 	void			sendAnimationStateReset();
+	void			sendRevokePermissions(const LLUUID & target, U32 permissions);
 
 	void			endAnimationUpdateUI();
 	void			unpauseAnimation() { mPauseRequest = NULL; }