To keep sensitive data off the screen is the easy part -- the one-argument select() can do that. So can closing STDOUT (and maybe STDERR).

The hard part is making sure things bound for output file 1 aren't going to output file 2.

A rather simplistic form of this can be accomplished in plain Perl without modules so long as you only use a special restricted print sub for output. Here's an example:

#!/usr/bin/perl -w use strict; my %allowed; my %file; my ( $foo, $bar, $baz ) = ( 'foo', 'bar', 'baz' ); my $eol = "\n"; $allowed{ \$foo } = 'a'; $allowed{ \$bar } = 'a'; $allowed{ \$baz } = 'b'; $allowed{ \$eol } = 'b'; $file{ 'a' } = *STDERR; $file{ 'b' } = *STDOUT; sub rp { my $fh = shift; for ( my $i = 0; $i < @_; $i++ ) { if ( $fh eq $file{ $allowed{ \$_[$i] } } ) { print $_[$i]; } else { print "\nAttempt to print unallowed data using restricted +print\n"; } } } rp (*STDERR, $foo, $bar, $baz, $eol ); rp (*STDOUT, $foo, $bar, $baz, $eol );

Now, that's not very useful if someone throws a print() in the program instead of using the restricted printing sub. If you could throw that functionality into a moduie and use Safe or some other way to make sure that only your restricted printing module can issue a print, printf, sprintf, write, etc. then you have a good start. If one could override the built-in output statements, that'd work, too.

Part of the problem is that you don't really want to restrict a particular variable in an application when security is of such import. You want to make sure that nothing can be output except to where explicitly allowed. If you disagree with that statement and really do want to allow by default and restrict explicitly, then the example above wouldn't be too difficult to change in that direction.

I'm not really sure how well the idea will help secure applications, as I haven't thought about it yet. It shouldn't be too difficult to implement, though, even as a hack well above the core which wouldn't slow anything down when this idea isn't in use.

I'd personally, like I did here, look at the output routines first. Wrapping it up in the filehandle somehow, whether through IO::Handle, layers, tie, or whatever could be an option, but that's back to explicit restrictions instead of explicit allow.



Christopher E. Stith

In reply to Re: 'Restricted' data, an additional security mechanism for Perl. by mr_mischief
in thread 'Restricted' data, an additional security mechanism for Perl. by pjf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.