#!/usr/bin/perl -wTR use strict; use CGI; use DBI; restrict DBPassword, DB; my DBPassword $passwd = "abcdef"; my DB $dbh = DBI->connect("DBI:mysql:something", "someone", $passwd); # ALLOWED my $cgi = new CGI; print $cgi->header(); print $passwd; # NOT ALLOWED, program terminates print STDERR $passwd; # NOT ALLOWED, program terminates open(FILE, "> somefile") or die "Failed to open: $!"; print FILE $passwd; # NOT ALLOWED, program terminates restrict CreditCard, CreditCardGateway; my CreditCard $credit_card = $cgi->param("credit_card"); my CreditCard $expiry = $cgi->param("expiry"); my $foo = "$credit_card $expiry"; # Foo is now # CreditCard type too. print $foo; # NOT ALLOWED, program terminates print STDERR $foo; # NOT ALLOWED, program terminates print FILE $foo; # NOT ALLOWED, program terminates my CreditCardGateway $gateway; open ($gateway, "| cc_card_gateway") or die "failed to open gateway: $ +!"; print $gateway $foo; # ALLOWED print $gateway $credit_card; # ALLOWED print $gateway $expiry; # ALLOWED $foo++; # Still of CreditCard type...
By providing a filter function we should be able to send this data on any output. Outputs which are of the correct type get the full data and everything else gets the filtered data. The absense of a nominated filter ensures that the output can ONLY be sent to correct outputs.restrict CreditCard, CreditCardGateway; filter CreditCard, \&clean_credit_card; my CreditCard $credit_card = $cgi->param("credit_card"); print $credit_card; # ALLOWED (filters card) my CreditCardGateway $gateway; open ($gateway, "| cc_card_gateway") or die "failed to open gateway: $ +!"; print $gateway $credit_card; # ALLOWED (prints full # details) # very very naive cleaning function sub clean_credit_card { my ($restricted) = @_; $restricted = s/.{12}/./; # replace 12 digits with .s return $restricted; }
So, does anyone other than pjf and I think this would be worth while?
Update: changed the title
In reply to Restricted' data, a clarification
by jarich
in thread 'Restricted' data, an additional security mechanism for Perl.
by pjf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |