PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Mar 29, 2024 2:26 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Security issue
PostPosted: Wed Nov 22, 2006 3:10 pm 
Offline

Joined: Wed Nov 22, 2006 3:02 pm
Posts: 1
First of all, thanks for a great tool!

In a recent project I needed some data to be available in PDF-format and I've tried it on my development server and it works liks a charm. However, when I upload the code to the server it's suppose to run on I run into security issues:

------------------------------------------------------
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
------------------------------------------------------

I realise this is not a problem with PDFSharp but with the webserver... I'm just looking for pointers here since I don't have any idea of how to follow up on this. It's seems that the exception is thrown when I try to do pdfRenderer.RenderDocument();.

Any help is appriciated!

Regards
/Stefan


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 23, 2006 10:36 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Is this an ASPX application?

If yes, create an Application Pool with appropriate rights and use this AppPool for your web application.
You can use "Local System" as Identity for the new AppPool to try this. If this works, you can create a new account with tailored (more restricted) rights for your application pool.
See IIS in Computer Management to administrate Websites and Application Pools.

If no, then the solution is similar - find out how to set the account your application uses and change the account or the account rights.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jun 06, 2007 8:35 am 
Offline

Joined: Thu May 24, 2007 10:20 pm
Posts: 11
Location: Bedford, UK
I am having the same problem but my site is being hosted on a server running a medium trust environment.

Is there anything that I can do to the code, or during compilation, to get PDFSharp to run on my remote host?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jun 06, 2007 10:13 am 
Offline

Joined: Thu May 24, 2007 10:20 pm
Posts: 11
Location: Bedford, UK
I have added some tracing to my code, to show which PDFSharp lines were executed. There are other lines of code between these traces but I was only tracing lines that used the PDFSharp library.

The following lines of code seem to have run successfully....

Dim oPDFDocument As PdfDocument
Dim oPDFPage As PdfPage
Dim oXGraphics As XGraphics
Dim oXFont_H As XFont
Dim oXTextFormatter As XTextFormatter
oPDFDocument = New PdfDocument 'create a new PDF document
oPDFPage = oPDFDocument.AddPage 'create a new page in the document

The trace line immediately before this line was the last one to be seen, and the trace line immediately after this line was never seen!

oXGraphics = XGraphics.FromPdfPage(oPDFPage) 'get an XGraphics object from the page for drawing

It would appear to be a problem with the line oXGraphics = XGraphics.FromPdfPage(oPDFPage)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jun 06, 2007 10:26 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
cmgarnett wrote:
It would appear to be a problem with the line oXGraphics = XGraphics.FromPdfPage(oPDFPage)

Interesting information.
From the source code I suspect the error occurs in
Code:
XGraphics(PdfPage page, XGraphicsPdfPageOptions options, XGraphicsUnit pageUnit, XPageDirection pageDirection)

at the line
Code:
this.gfx = Graphics.FromHwnd(IntPtr.Zero);

(but I could be wrong)
Would you please verify this with a few more traces?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jun 06, 2007 10:34 am 
Offline

Joined: Thu May 24, 2007 10:20 pm
Posts: 11
Location: Bedford, UK
The full error that I get is...

Quote:
Server Error in '/demo/cmn' Application.
--------------------------------------------------------------------------------

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +59
System.Drawing.Graphics.FromHwnd(IntPtr hwnd) +53
PdfSharp.Drawing.XGraphics..ctor(PdfPage page, XGraphicsPdfPageOptions options, XGraphicsUnit pageUnit, XPageDirection pageDirection) in XGraphics.cs:130
PdfSharp.Drawing.XGraphics.FromPdfPage(PdfPage page) in XGraphics.cs:286
admgpsolo.Page_Load(Object sender, EventArgs e) +1028
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6953
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +154
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.admgpsolo_aspx.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +154
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64


and line 130 in XGraphics.cs is ...

Code:
this.gfx = Graphics.FromHwnd(IntPtr.Zero);


so I would agree with you about which line might be causing the problem.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 07, 2007 9:07 am 
Offline
empira Employee
User avatar

Joined: Thu Oct 12, 2006 10:07 pm
Posts: 49
Location: Cologne, Germany
System.Drawing.Graphics.FromHwnd(IntPtr hwnd)
is one of the reasons why PDFsharp.dll needs full trust by design.
You can prevent a lot of problems if you put the Assembly to the GAC.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 07, 2007 9:11 am 
Offline

Joined: Thu May 24, 2007 10:20 pm
Posts: 11
Location: Bedford, UK
Yes, I had found several pages on Google suggesting that some of the .Net objects could not be used on a medium trust host!

I'm only scratching the surface of .Net so I will have to ty and learn about putting
Quote:
Assembly to the GAC.

_________________
Regards
Chris
(Learning all the time.)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 07, 2007 9:40 am 
Offline

Joined: Thu May 24, 2007 10:20 pm
Posts: 11
Location: Bedford, UK
Am I right in thinking that adding an assembly to the GAC is something that the administrators of the server would have to do and that after it was done, any sites that they host would be able to use PDFSharp?

_________________
Regards
Chris
(Learning all the time.)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 155 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group