Esapi WARNING: [SECURITY FAILURE Anonymous:null#unknown -> /ExampleApplication/IntrusionDetector] - esapi

I have this line of code:
ESAPI.validator().isValidInput("user id", userID, "USERID", 8, false);
I have written a test for it, when I run the test and the test fails I get the following warining:
WARNING: [SECURITY FAILURE Anonymous:null#unknown -> /ExampleApplication/IntrusionDetector] Input exceeds maximum allowed length of 8 by 5 characters: context=user id, type=USERID, orig=userid1234567, input=userid1234567
What does the warning mean and how can I get rid of it?

Short answer: You get rid of the warning by passing in valid input.
You are calling Validator.isValidInput(String context, String input, String type, int maxLength, boolean allowNull)
You have the 'maxLength' parameter (the 4th parameter) set to 8. So you are telling this method that it should only return true if the 'input' parameter (your 2nd parameter in this method) has a length of <= maxLength.
Your logged output shows that you are passing it a value of 'userID' which is set to "userid1234567", which has a length of 13 characters. Thus the log message is correctly telling you that your input exceeds the maximum allowed length of 8 by 5 characters. In other words, it is doing exactly what it was designed to do.

Related

Issue with conversion from string to double

I am not able to convert my string to double.I am getting below error
conversion from string to double is not valid
I have tried below approach but all are giving me same error. I am using Assign activity in uipath with intvalue defined as double and row.Item("TaxResult") retrieves the value from excel
intval = Val(row.Item("Tax Result").ToString.Trim)
intVal = Double.Parse(row.Item("Tax Result").ToString.Trim , double)
intVal = cDbl(row.Item("Tax Result").ToString.Trim)
Out of the above three first one is returning to me 0 value while the below two is giving me an error
"conversion from string to double is not valid"
Tax Result column in excel stores the value like (5.2, 19.8, 98.87). I want to sum all these value as part of my requirement
First, you don't need the .Item after row, it should just be row("Tax Result")
Ideally you should use a Double.TryParse() to try and avoid any exceptions if it cant convert to Double.
This can be achieved using an If Statement as seen below, if the Try Parse is successful the string can be converted using Double.Parse(row("Tax Result").ToString.Trim) and on failure I have assigned intval to 0 but you could put handling here to handle if it can't convert the number

How to Determine if a given User input is a Float, String, or a Integer in Ruby

The is_a? method doesn't work; I have tried it and it apparently it checks if the value is derived from an object or something.
I tried something like this:
printf "What is the Regular Price of the book that you are purchasing?"
regular_price=gets.chomp
if regular_price.to_i.to_s == regular_price
print "Thank You #{regular_price}"
break
else
print "Please enter your price as a number"
end
Can someone explain to me more what .to_i and .to_s do? I just thought they convert the user input to a string, or a Numerical Value. I actually don't know how to check input to see if what he put in was a float, a String, or a decimal.
I just keep getting Syntax errors. I just want to know how to check for any of the 3 values and handle them accordingly.
There's a lot to your question so I recommend that you read How do I ask a good question? to help you get answers in the future. I'll go through each of your questions and try to provide answers to point you in the right direction.
The is_a? method works by accepting a class as a parameter and returning boolean. For example:
'foo'.is_a?(String)
=> true
1234.is_a?(Integer)
=> true
'foo'.is_a?(Integer)
=> false
1234.is_a?(String)
=> false
1.234.is_a?(Float)
=> true
The .to_i method is defined on the String class and will convert a string to an Integer. If there is no valid integer at the start of the string then it will return 0. For example:
"12345".to_i #=> 12345
"99 red balloons".to_i #=> 99
"0a".to_i #=> 0
"hello".to_i #=> 0
The .to_s method on the Integer class will return the string representation of the Integer. For example:
1234.to_s
=> '1234'
The same is true of Float:
1.234.to_s
=> '1.234'
Now let's take a look at your code. When I run it I get SyntaxError: (eval):4: Can't escape from eval with break which is happening because break has nothing to break out of; it isn't used to break out of an if statement but is instead used to break out of a block. For example:
if true
break
end
raises an error. But this does not:
loop do
if true
break
end
end
The reason is that calling break says "break out of the enclosing block," which in this case is the loop do ... end block. In the previous example there was no block enclosing the if statement. You can find more detailed explanations of the behavior of break elsewhere on stackoverflow.
Your final question was "I just want to know how to check for any of the 3 values and handle them accordingly." This answer explains how to do that but the code example is written in a way that's hard to decipher, so I've rewritten it below in an expanded form to make it clear what's happening:
regular_price = gets.chomp
begin
puts Integer(regular_price)
rescue
begin
puts Float(regular_price)
rescue
puts 'please enter your price as an Integer or Float'
end
end
What this code does is first it attempts to convert the string regular_price to an Integer. This raises an exception if it can't be converted. For example:
Integer('1234')
=> 1234
Integer('1.234')
ArgumentError: invalid value for Integer(): "1.234"
Integer('foo')
ArgumentError: invalid value for Integer(): "foo"
If an exception is raised then the rescue line stops the exception from being raised and instead continues executing on the next line. In this case, we're saying "if you can't convert to Integer then rescue and try to convert to Float." This works the same way as converting to Integer:
Float('1.234')
=> 1.234
Float('foo')
ArgumentError: invalid value for Float(): "foo"
Finally, we say "if you can't convert to Float then rescue and show an error message."
I hope this helps and answers your questions.

Formatting Localized Strings with Multiple Values

I've created a localized string that takes the form similar to
"text_key" = "Collected %d out of %d";
and am using the following formatter:
let numberOfItems = 2
let totalNumberOfItems = 10
let format = NSLocalizedString("text_key", comment: "Says how many items (1st var) were collected out of total possible (2nd var)")
let text = String.localizedStringWithFormat(format, numberOfItems, totalNumberOfItems)
Which gives
"Collected 2 out of 10"
However I can imagine that in some languages it would be more natural to have these values appear in a different order resulting in a non-sensical string such as
"Out of a possible 2 items you collected 10"
I cannot find a simple way to encode this using the standard Swift library such as
"text_key" = "Out of a possible {2%d} items you collected {1%d}"
and can see this getting cumbersome hardcoding these as more values are added.
String.localizedStringWithFormat() works with “positional arguments”
%n$. In your case
"text_key" = "Out of a possible %2$d items you collected %1$d";
would do the trick.
These are documented in fprintf:
Conversions can be applied to the nth argument after the format in the argument list, rather than to the next unused argument. In this case, the conversion specifier character % (see below) is replaced by the sequence "%n$", where n is a decimal integer in the range [1,{NL_ARGMAX}], giving the position of the argument in the argument list.

String to Integer (atoi) [Leetcode] gave wrong answer?

String to Integer (atoi)
This problem is implement atoi to convert a string to an integer.
When test input = " +0 123"
My code return = 123
But why expected answer = 0?
======================
And if test input = " +0123"
My code return = 123
Now expected answer = 123
So is that answer wrong?
I think this is expected result as it said
Requirements for atoi:
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.
Your first test case has a space in between two different digit groups, and atoi only consider the first group which is '0' and convert into integer

How to check if value in field is decimal and not string (DATASTAGE)?

How to check if value in field is decimal and not string (DATASTAGE) ?
I am using with Datastage Version 8.
Try using IsValid() with the 'decimal' sub-type on the incoming string.
If IsValid("decimal" , in.value_string ) Then in.value_tring Else SetNull()
You can use Alpha & num function inside transformer which gives you whether the given value contains only alphabets.
If alpha(column) is 1 then its purely alphabetical.
Else check if Num(column) is 1, if this true then it is purely a number.
Reference to official doc-https://www.ibm.com/support/knowledgecenter/SSZJPZ_11.5.0/com.ibm.swg.im.iis.ft.usage.doc/topics/r_deeref_String_Functions.html