PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Security issue

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
stefan



Joined: 22 Nov 2006
Posts: 1

PostPosted: Wed Nov 22, 2006 3:10 pm    Post subject: Security issue Reply with quote

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
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Thu Nov 23, 2006 10:36 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
cmgarnett



Joined: 24 May 2007
Posts: 11
Location: Bedford, UK

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

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?
Back to top
View user's profile Send private message
cmgarnett



Joined: 24 May 2007
Posts: 11
Location: Bedford, UK

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

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)
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Jun 06, 2007 10:26 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
cmgarnett



Joined: 24 May 2007
Posts: 11
Location: Bedford, UK

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

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.
Back to top
View user's profile Send private message
Stefan Lange



Joined: 12 Oct 2006
Posts: 47
Location: Cologne, Germany

PostPosted: Thu Jun 07, 2007 9:07 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
cmgarnett



Joined: 24 May 2007
Posts: 11
Location: Bedford, UK

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

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.)
Back to top
View user's profile Send private message
cmgarnett



Joined: 24 May 2007
Posts: 11
Location: Bedford, UK

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

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.)
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com