English

Developer tools · URL encoder & decoder

URL encoding is not sanitisation: decoded parameters still need escaping

· Why it matters

url-encoding security xss

Percent-encoded payload decoded back to original form ready for output escaping
Original ToolAcre vector illustration

Percent-encoding protects URL structure, not your HTML, SQL or shell. This post explains why a correctly encoded value becomes dangerous again the moment it is decoded, and which escaping belongs where.

Why URL encoding alone cannot stop XSS attacks

A "safe" parameter can run script if encoded for transmission but decoded before rendering. Consider XSS payload like img tag with onerror handler percent-encoded as %3Cimg%20src%3Dx%20onerror%3Dalert%281%29%3E. If this travels in URL and decoded by application code before inserted into HTML, browser sees original markup and executes handler. Percent-encoding is representation layer; does not change underlying threat.

Payload is safe only during transmission, when it is encoded string with no special meaning to HTTP or URL parser. Moment it decoded, it becomes dangerous again because reverts to original form. Every downstream context must apply its own escaping rules appropriate to how it will use data. URL encoding is not substitute for HTML escaping, SQL parameterization or shell argument handling.

What percent-encoding is for — keeping delimiters unambiguous on the wire, nothing more

What percent-encoding does is protect URL structure precisely. Ampersand stays part of query string syntax, not reinterpreted as delimiter. Slash does not become path separator. Question mark does not start fragment. By encoding reserved characters as %XX, parser treats them as data, not syntax. This works for one job: keeping URL structure unambiguous on wire.

Decoding reverses that one-way street exactly. Restored bytes are exactly what was encoded, nothing more and nothing less. HTML-dangerous string stays dangerous, SQL-injection vector stays dangerous, and shell command stays dangerous. Percent-encoding is not input validation, not sanitization and not security boundary. It is representation format only.

Decoding restores the original bytes — so every downstream context sees the raw value again

Context-specific escaping is where real protection lives genuinely. HTML context needs entities: less-than becomes <, greater-than becomes >, quotes become ", ampersand becomes &. SQL context needs parameterized queries separating structure from data, preventing attacker from breaking out. Shell context needs argument arrays avoiding word splitting and globbing completely.

Each context has different dangerous characters and different escaping rules precisely. HTML entity is harmless in SQL query but useless for protection there. Backslash prevents SQL injection in some databases but not others. Shell escaping depends on quoting style. Developer must understand destination before choosing how to handle data.

Context-specific escaping — HTML entities for markup, parameterised queries for SQL, argument arrays for shells

Worked example: following payload from link to log to page reveals where encoding and escaping must happen. Link contains encoded XSS payload as query parameter. Server receives it still encoded in HTTP request body. Application decodes query parameter to display it in page. Without output escaping, browser renders payload as HTML and executes it.

If same parameter logged to file, log entry contains decoded payload clearly. Second application reads log, decodes again, inserts it into HTML page without escaping. Payload executes second time. At each step, context determined what was safe. URL decoding was safe. File storage was safe. But HTML output without escaping was fatal.

Worked example: following one payload from link to log to page — where it is encoded, where it is decoded, where it must be escaped

Encoding as filter-evasion tool shows why attackers double-encode and mix hex case significantly. If firewall looks for img tag, attacker sends %3Cimg and hopes application decodes once but firewall does not. If validation rejects %3Cimg but allows different case, same bytes decode to same payload. Security depending on pattern matching encoded input is brittle.

Decoding must be exact and predictable absolutely. Canonical form (lowercase hex, known encoding) allows consistent policy but does not solve underlying problem. Only reliable approach is allow decoding where necessary and apply context-specific output escaping immediately before use. Decoding is never safe; only necessary for transmission.

Encoding as a filter-evasion tool — why attackers double-encode and mix hex case, and why decoding must be exact

Full XSS defense requires understanding data flows completely, contexts it passes through at each step, what escaping each context needs. URL encoding is one small piece: preserves structure during transmission only. But one piece is not defense by itself ever. Many developers conflate encoding with sanitization because both involve replacing characters, but serve completely different important jobs.

Web Application Firewall can detect patterns in request payloads, but encoding easily evade simple pattern matching techniques. WAF tuning is complex and beyond URL encoding. Reliable defense is output escaping in application code, paired with input validation where it makes sense for your specific context and requirements.

What this does not cover — a full XSS defence guide or web application firewall tuning

Full XSS defense requires understanding data flows completely, contexts it passes through at each step, what escaping each context needs throughout the application. URL encoding is one small piece: preserves structure during transmission only. But one piece is not defense by itself ever. Many developers conflate encoding with sanitization because both involve replacing characters, but serve completely different important jobs throughout development.

Test payload end-to-end to see where encoding and escaping matter genuinely throughout entire process. Paste %3Cimg%20src%3Dx%20onerror%3Dalert%281%29%3E into URL decoder and watch become string looking like markup. Then paste result into HTML entity escaper to see how becomes safe text. Two tools show layers clearly visible.

Takeaway: encode for the URL, escape for the output — how the URL encoder & decoder and the HTML entity escaper sit side by side in one product for the two different jobs

Takeaway is that encoding and escaping are separate concerns at different layers absolutely throughout. URL encoding protects transmitted structure only. Output escaping protects rendered content. Correctly encoded value still needs output escaping when reaches HTML. Correctly escaped string never needs URL encoding if not put into URL.

Apply right defense at right layer genuinely. Do not rely on URL encoding to stop XSS attacks. Do not rely on HTML escaping to preserve URL structure. Understand your data flow and apply appropriate transformation at each step. URL encoder helps you see what encoding does; then use HTML entity escaper for output step.