Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6857471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:01:25+00:00 2026-05-27T02:01:25+00:00

Is safe make a webform, where the user can enter sed command, like: s/\(.*\)

  • 0

Is safe make a webform, where the user can enter sed command, like:

s/\(.*\) *\(.*)/\2:\1/;s/$/end of line/;s/this/that/g

after the form submit i want execute the sed command like:

sed '<<string from the form>>' < FILE1 >FILE2

Is this safe? What is the correct way executing user-supplied sed commands from the security standpoint? What i need to check or how to prepare the sed command?

adding the calling mode – mean something like this – so will not run via shell…

use 5.014;
use warnings;
use autodie;

use FileHandle;
use IPC::Open2;
use File::Slurp;

my $sedcommand = 's/a/QQ/g';
my $input = read_file('inputfile.txt');
my $out = sed_edit($sedcommand, $input);
say $out;

sub sed_edit {
    my($command, $text) = @_;
    my($fromsed, $tosed);
    my $pid = open2($fromsed, $tosed, "sed", "$command" );
    print $tosed $text;
    close($tosed);
    my $result = <$fromsed>;
    close($fromsed);
    waitpid($pid, 0);
    return($result);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:01:27+00:00Added an answer on May 27, 2026 at 2:01 am

    If a user can enter anything they want in the string and you pass that string unmodified to the shell so it can insert it into the sed command line you have there, then no, it is not safe. (Actually, it’s difficult to say for certain without knowing more implementation details. But the likely answer is: Not safe.)

    There are probably ways to make this safe, but doing so would involve getting into a lot of implementation details.

    That said, the very first step would probably be to figure out what the appropriate characters the user should be allowed to enter are, and put in checking to make sure they only entered a string with those characters before doing anything with it.

    That is a first step, but it is probably not the last step.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After exploding with excitement over learning about how to make thread-safe calls to Windows
Question is simple. How can I make 100% safe photo upload script with php?
I'm not sure , how I can really make a safe inputs with strings.
When writing the usual view controller code, can I assume that this will only
I run all my integers through a (int)Integer to make them safe to use
Is it safe to let users make their own Django templates with a set
I need to make an ArrayList of ArrayLists thread safe. I also cannot have
I am tying to make comments in a blog engine XSS-safe. Tried a lot
I'm wondering what is the best way to make data thread-safe. Specifically, I need
How safe is it to use Silverlight in production for a graphic form? Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.