Double URL encoding happens when a value that is already percent-encoded gets encoded a second time. The % sign of each escape becomes %25, so a space turns from %20 into %2520 and a slash from %2F into %252F. You fix it by finding the layer that encodes an already-encoded string and making sure each raw value is encoded exactly once, at the point where the URL is built.
What double URL encoding looks like
Double URL encoding shows up as %25 followed by two hex digits that were themselves meant to be an escape. The percent sign is the marker for every escape, so RFC 3986 says a literal % used as data must be written as %25. An encoder that sees %20 can't tell it was already an escape, so it treats the % as data.
Here is the chain for a single space:
- The raw value is
a b. - The first encode gives
a%20b. - The second encode escapes the
%and givesa%2520b.
The usual giveaways in logs and address bars:
| You see | Original character | What happened |
|---|---|---|
%2520 |
space | %20 encoded again |
%252F |
/ |
%2F encoded again |
%253A |
: |
%3A encoded again |
%2526 |
& |
%26 encoded again |
The same RFC section sets the rule: implementations "must not percent-encode or decode the same string more than once."
A reproducible example in JavaScript
The most common cause in JavaScript is encoding a value by hand and then giving it to an API that encodes for you. I ran this in Node.js v24:
const raw = "a b/c";
const once = encodeURIComponent(raw); // "a%20b%2Fc"
const params = new URLSearchParams({ q: once });
params.toString(); // "q=a%2520b%252Fc"
URLSearchParams expects raw text. Its documentation shows the same effect for keys: appending the already-encoded key %24%26 serializes to %2524%2526. Setting the value through url.searchParams.set() gave me the identical q=a%2520b%252Fc.
The fix is to delete the manual step:
const url = new URL("https://api.example.com/search");
url.searchParams.set("q", "a b/c"); // pass the raw value
url.href; // "https://api.example.com/search?q=a+b%2Fc"
For which function encodes which characters, see encodeURI vs encodeURIComponent.
Where the second encode usually comes from
The second encode almost always comes from two layers that each believe they own encoding:
- Client code plus an HTTP library. You call
encodeURIComponent, then pass the result to a client that builds the query string itself. - Stored URLs. A database or config file holds an already-encoded link, and the code that reads it encodes it again before redirecting.
- Proxies and gateways. A reverse proxy or API gateway rewrites the path and re-encodes it before forwarding it to the backend.
- Redirect parameters. A
returnTo=value is encoded by the page, then encoded again by a login service that wraps it in its own redirect.
Encoded slashes are a special case. Apache HTTP Server's AllowEncodedSlashes setting defaults to Off, and with that default, URLs containing %2F in the path are refused with a 404. Some teams respond by encoding to %252F on purpose, and then every other layer has to know about it.
How to fix double URL encoding step by step
The lasting fix is to choose one place that encodes and make every other layer pass raw values through.
- Capture the bad URL exactly as it leaves each layer: browser network tab, client logs, proxy access log, backend request log.
- Find the first hop where
%25appears in front of an escape. The layer just before it is doing the extra encode. - Remove the manual encode if a library already encodes. Give
URLSearchParams,requestsparams or similar APIs raw strings. - Store raw values, not encoded ones, or label stored URLs as already encoded so nothing touches them again.
- Decode on the server once, through the framework. In PHP, for example, the urldecode manual warns that
$_GETand$_REQUESTare already decoded and that decoding them again "could have unexpected and dangerous results."
To test the fix, send a b/c%: a space, a slash and a real percent sign. The backend should receive exactly that string.
Why "decode until it stops changing" is the wrong fix
Decoding in a loop until the value stops changing looks like a quick repair, but it breaks real data. Take a search for 100%20 discount, where the user typed the characters %20. One decode returns that text. A loop decodes again and quietly turns it into 100 discount.
Loops also crash on some input. decodeURIComponent("100%") throws URIError: URI malformed in Node, because a lone % is not a valid escape. The decodeURIComponent reference documents this error.
My take: decode twice only as a labelled, temporary patch for data already broken in storage, and delete it once the source is fixed. A permanent double decode hides the bug and opens the security hole below.
Double encoding as a security problem
Double encoding is also a known attack technique. The OWASP page on double encoding describes attackers encoding input twice to get past filters that decode only once, while a later component decodes again without the same checks.
Its example is path traversal. ../ becomes %2E%2E%2F after one encode and %252E%252E%252F after two. A filter that blocks ../ after one decode sees only %2E%2E%2F and lets it through. The same trick works on cross-site scripting filters with %253Cscript%253E.
The defence is the RFC rule again. Decode exactly once, before any validation or authorization check runs, and treat whatever is left as data. A second decode anywhere after the checks is the gap an attacker will use.
Checking a value by hand
When a log line looks wrong, decode it one step at a time and compare. If one decode still leaves %20 or %2F in the text, the value was encoded twice. A second decode should then give the readable original.
The URL decoder on this site does this: paste the value, then paste the result back in to peel another layer. It runs in the page and sends your input nowhere. It cannot tell you which of your services added the extra layer. For that you need the hop-by-hop logs from step 1.
For related problems, see which characters need URL encoding, why a plus sign decodes to a space and HTML encoding vs URL encoding.
FAQ
What does %2520 mean in a URL?
%2520 is a space that was encoded twice. The space became %20 the first time, then the % sign became %25 the second time. One decode gives back %20, and a second decode gives the space.
Is %25 always a sign of double encoding?
No. %25 is the correct encoding of a literal percent sign. A value like 100%25 for the text 100% is fine. It points to double encoding only when %25 sits in front of two hex digits that were meant as an escape, such as %2520 or %252F.
Should I just decode the value twice on the server?
Only as a short-term patch for data that is already broken. The lasting fix is to stop the second encode at its source, because decoding twice also corrupts values that really contain a percent sign.
Why does URLSearchParams double encode my value?
URLSearchParams expects raw text and encodes it for you. If you pass it a value you already ran through encodeURIComponent, it treats the % signs as data and encodes them again as %25.