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 173047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:16:25+00:00 2026-05-11T13:16:25+00:00

The GString concept in Groovy is pretty powerful (see http://groovy.codehaus.org/Strings+and+GString ). GStrings let you

  • 0

The GString concept in Groovy is pretty powerful (see http://groovy.codehaus.org/Strings+and+GString).

GStrings let you do things like:

world = 'World' println 'Hello ${world}' # Output: Hello World println '1+2 = ${1+2}' # Output: 1+2 = 3 println '${System.exit(-1)}' # Program terminated 

I’m trying to figure out if using Groovy GString:s can introduce security problems in your code similar to SQL injection attacks.

In the example above the code was written by the author of the program, so the execution of the System.exit(-1) command cannot be seen as a security flaw as it was the stated intent of the author.

Let’s say I’m writing a Grails web-app, where user input is taken from form fields (reading POST/GET params) and database tables (using GORM). Let’s assume that an attacker controls both what’s sent as POST/GET requests to the server and what’s in the database.

The code in my app looks like this:

def str1 = params.someParameterControlledByTheAttacker def str2 = SomeGORMPersistedObject.get(1).somePropertyFieldControlledByTheAttacker render 'Hello! Here is some text: ${str1} and ${str2}' 

Is there any way an attacker can execute code in the above scenario? Why? Why not? My initial hypothesis is that GString usage is always safe. Please feel free to prove me wrong. Please be as concrete as possible.

Update #1: To keep the discussion focused, please disregard any HTML-XSS problems in the code since this question is about code-execution on the server-side, not on the client-side.

Update #2: Some people have pointed out that it is ‘generally a good idea to filter out unwanted strings’. While filtering out ‘potentially bad characters’ might certainly save you from some classes of security problems, it would be even better to write code that would be safe even without filtering. You can compare it with usage of PreparedStatements in the Java JDBC API – correct usage of PreparedStatements is guaranteed to save you from certain classes of injection attacks. Filtering your SQL input will probably give you the same result, but using PreparedStatements strictly dominates the filtering approach IMHO.

  • 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. 2026-05-11T13:16:26+00:00Added an answer on May 11, 2026 at 1:16 pm

    No, you won’t have any new problems introduced by the GString mechanism, because the formation of GStrings is a ‘compile time’ phenomenon. While their value may be determined (and changed) at run time their form is not.

    Another way of looking at it: anything you can do with GStrings could be done with a closure and string concatenation, with exactly the same semantics; GStrings are just syntactic sugar. Unless you are worried about closures (or, heaven forbid, string concatenation) you shouldn’t worry about GStrings.

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

Sidebar

Ask A Question

Stats

  • Questions 108k
  • Answers 108k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer 1- avoid spam, use captcha or other thing to prevent… May 11, 2026 at 9:15 pm
  • Editorial Team
    Editorial Team added an answer I'm no expert, but have you tried out this tool?… May 11, 2026 at 9:15 pm
  • Editorial Team
    Editorial Team added an answer Buy a faster server Buy more servers Do less work… May 11, 2026 at 9:15 pm

Related Questions

The 1st example below illustrates the working code. I want to take the working
Most Java code is also syntactically valid Groovy code. However, there are a few
I am having problems getring a simple redirect statement to take effect on my
I have a very simple class with only one field member (e.g. String). Is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.