-
Notifications
You must be signed in to change notification settings - Fork 75
String Manipulation Methods
Ohpe edited this page Jan 29, 2016
·
1 revision
JavaScript has some string manipulation methods. It is important to identify their behaviour in order to understand how they treat specific characters.
- escape/unescape
- encodeURI/decodeURI
- encodeURIComponent/decodeURIComponent
for(i=0;i<256;i++){
var cc=String.fromCharCode(i);
var es=escape(cc),eu=encodeURI(cc),euc=encodeURIComponent(cc)
if( es!=eu | es!=euc| eu!=euc)
console.log(cc+"["+i+"]= "+es+" "+eu+" "+euc);
}
Char | escape |
encodeURI |
encodeURIComponent |
---|---|---|---|
! (33) |
%21 | ! | ! |
# (35) |
%23 | # | %23 |
$ (36) |
%24 | $ | %24 |
& (38) |
%26 | & | %26 |
' (39) |
%27 | ' | ' |
( (40) |
%28 | ( | ( |
) (41) |
%29 | ) | ) |
* (42) |
* |
* |
* |
+ (43) |
+ | + | %2B |
, (44) |
%2C | , | %2C |
- (45) |
- | - | - |
. (46) |
. | . | . |
/ (47) |
/ | / | %2F |
0 (48-57) |
0-9 | 0-9 | 0-9 |
: (58) |
%3A | : | %3A |
; (59) |
%3B | ; | %3B |
= (61) |
%3D | = | %3D |
? (63) |
%3F | ? | %3F |
@ (64) |
@ | @ | %40 |
A (65-90) |
A-Z | A-Z | A-Z |
_ (95) |
_ |
_ |
_ |
a (97-122) |
a-z | a-z | a-z |
~ (126) |
%7E | ~ | ~ |
� (128) |
%80 | %C2%80 | %C2%80 |
for(i=0;i<256;i++){
var cc=String.fromCharCode(i);
try{
var eu=decodeURI(escape(cc)),euc=decodeURIComponent(escape(cc))
if( eu!=euc)
console.log("| `"+cc+"``[`"+i+") | "+eu+" | "+euc+ " | ");
}catch(e){console.log('ee :'+i)}
}
Char | decodeURI | decodeURIComponent |
---|---|---|
# (35) |
%23 | # |
$ (36) |
%24 | $ |
& (38) |
%26 | & |
, (44) |
%2C | , |
: (58) |
%3A | : |
; (59) |
%3B | ; |
= (61) |
%3D | = |
? (63) |
%3F | ? |
for i >= 128
exception is triggered
console.log(decodeURI("%C3%D8"));
This behaviour could be exploited in cases such as:
var locParameter = getFromQueryString("aParameter");
try{
...
locParameter = encodeUriComponent(locParameter);
...
}catch(e){}
...
document.write(locParameter);
...
where the tainted variable is overwritten with its encoded value and later used in a sink.
-
g
: global flag -
i
: case insensitive -
m
: multi line
\s
\w
-
[
]
-
(
)
- Home
- Sources
-
Sinks
- Direct Execution Sinks
- Set Object Sinks
- HTML Manipulation Sinks
- Style Sinks
- XMLHttpRequest Sink
- Set Cookie Sink
- Set Location Sink
- Control Flow Sink
- [Use of Equality And Strict Equality](Use of Equality And Strict Equality)
- Math.random Sink
- JSON Sink
- XML Sink
- [Common JavaScript libraries](Common JavaScript libraries)
- String Manipulation Methods
- Local DOMXSS
- Finding DOMXSS
- Object Shadowing
- Filters
- Glossary
- References