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

  • SEARCH
  • Home
  • 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 8769883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:26:55+00:00 2026-06-13T17:26:55+00:00

Can I securely replace Environment.NewLine with <br /> like I am in the following

  • 0

Can I securely replace Environment.NewLine with <br /> like I am in the following extension method?

public static string HtmlBreaks(this string s)
{
    if (string.IsNullOrEmpty(s)) { return s; }
    return s.Replace(Environment.NewLine, "<br />");
}

I use it like this:

@Html.Raw(Model.Details.HtmlBreaks())

And let me be clearer. Is this secure? Am I breaking any internet security guidelines by replacing text with HTML and then issuing the Raw method? Am I opening this website up to any attacks by this?

  • 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-06-13T17:26:56+00:00Added an answer on June 13, 2026 at 5:26 pm

    This is not secure. Take the example text of the details containing:

    <script>alert('a')</script>

    The HTML.Raw will output that as a script tag and the browser will execute the script. If the user provides the details text, this allows them to inject script into your page (A basic XSS attack).

    If you want to replace the newlines with <br> do it in your view. For example, my controller might look like this:

    MyModel model = new MyModel();
    model.Description = "Hello \r\n how are you today \r\n <script>alert('a')</script> \r\n";
    return View(model);
    

    In my view, I can do this:

    @{ var lines = Model.Description.Split('\r');
       foreach (var line in lines)
       {
           @line.Trim() <br />
       }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the question comes basically down to this: how can i securely create new databases
I want to implement a scenario where two endpoints can securely communicate with each
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
How can I make sure the data that people send to GameCenter (like score,
How can I securely store login credentials for remote service in my web applications
I want to create Java server which can communicate securely with C client over
According to this post I can use the encryption/decryption methods to store/retrieve plist file
We know we can encrypt a file with openssl using this command: openssl aes-256-cbc
In ADO.NET you can add parameters to a command object to securely add user

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.