473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Code Access Security - Assert problem

I'm writing an application that is trusted, but I want it to run some
untrusted code, and I don't understand how I do that. I'm including an
example.
I want to trust my class, TrustedClass, to do whatever it wants to the
file system. I don't want to trust UntrustedClass, so I don't give it
any permissions. But the untrusted code just calls Assert() before it
accesses the file system, and it succeeds.

How do I modify TrustedClass to make sure that UntrustedClass cannot
access the file system?

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Permissions;
using System.Security;
using System.IO;

namespace SecurityTest
{
//My class
class TrustedClass
{
static void Main(string[] args)
{
PermissionSet permissions = new PermissionSet(null);
permissions.PermitOnly();

UntrustedClass.UntrustedMethod();
}
}

//Adversary's class
class UntrustedClass
{
public static void UntrustedMethod()
{
FileIOPermission permission = new
FileIOPermission(PermissionState.Unrestricted);
permission.Assert();

FileStream fs = new FileStream(@"C:\testing.txt",
FileMode.Create);
}
}
}

Dec 20 '06 #1
0 1075

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help...
1
by: John Smith | last post by:
I don't think I have understood the concept of Code Access Security in Dotnet fully. 1) I simply can't appreciate the method - *Permission.Assert that asserts the 'right' and bypasses the...
10
by: Michel Walsh | last post by:
Hi, What is the "declaration" (class) I need to assert the permission that my code can run unmanaged code. I have: ================
0
by: Rich Forman | last post by:
Hey guys, VB.NET question: I want my app to overwrite files in its own directory with later-version-#'s of the same files that it finds in a designated "updates" directory. It works great when...
0
by: Filippo Bettinaglio | last post by:
Security problem running unmanaged code (.ocx control) in a windows from control hosted in IE6 Hi, I have design a windows from control which contain a .OCX in one of its forms....
5
by: Peter Ritchie [C# MVP] | last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time. I've just recently had the cycles to investigate the warning. The warning message...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
8
by: Daniel T. | last post by:
#include <cassert> class Foo { public: virtual void fnA() = 0; virtual void fnB() = 0; }; int main() { assert( &Foo::fnB );
3
by: zr | last post by:
Hi, Does usage of checked iterators and checked containers make code more secure? If so, can that code considered to be reasonably secure?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.