PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Security issue
http://forum.pdfsharp.com/viewtopic.php?f=2&t=26
Page 1 of 1

Author:  stefan [ Wed Nov 22, 2006 3:10 pm ]
Post subject:  Security issue

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

Author:  Thomas Hoevel [ Thu Nov 23, 2006 10:36 am ]
Post subject: 

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.

Author:  cmgarnett [ Wed Jun 06, 2007 8:35 am ]
Post subject: 

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?

Author:  cmgarnett [ Wed Jun 06, 2007 10:13 am ]
Post subject: 

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)

Author:  Thomas Hoevel [ Wed Jun 06, 2007 10:26 am ]
Post subject: 

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?

Author:  cmgarnett [ Wed Jun 06, 2007 10:34 am ]
Post subject: 

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.

Author:  Stefan Lange [ Thu Jun 07, 2007 9:07 am ]
Post subject: 

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.

Author:  cmgarnett [ Thu Jun 07, 2007 9:11 am ]
Post subject: 

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.

Author:  cmgarnett [ Thu Jun 07, 2007 9:40 am ]
Post subject: 

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?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/