Skip to content

FIELD NOTES / A DECISION GUIDE

URL-Encode Special Characters in Passwords for Safe Requests

Contents
AI-generated illustration; not taken on location · Generic illustration showing a password character being converted to a percent-encoded sequence
AI-generated illustration; not taken on location · Generic concept illustration for URL-encoded password security.AI-generated illustration

Passwords often contain characters that have special meaning in URLs and HTTP forms. Sending those characters unencoded can break request parsing, corrupt credentials, or expose authentication data in logs and browser history. Percent-encoding converts each affected character into a percent sign followed by two hexadecimal digits, allowing the value to travel through a URL safely.

This guide explains how percent-encoding works, which password characters commonly need encoding, how encoding a whole URL differs from encoding one value, and why passwords are generally safer in POST request bodies over HTTPS than in query strings. It also describes the FormatBits URL codec module scope and input limits based on the FormatBits source. The outline headings are preserved so image placements remain valid, and unsupported specifics such as exact password length limits or framework implementation rules are presented as items to verify rather than asserted facts.

Percent-encoding basics

Percent-encoding is the mechanism that turns characters with special meaning in URLs into safe sequences. Each encoded character becomes a percent sign followed by two uppercase hexadecimal digits representing the character’s byte value. For example, a character encoded as hexadecimal 20 appears as %20.

Spaces receive different treatment depending on the context. In HTML form data encoded as application/x-www-form-urlencoded, a space is conventionally converted to a plus sign (+). In strict URL percent-encoding, a space is typically represented as %20 instead. Because the same input can produce different results depending on the encoder and the target format, developers should match the encoding method to the destination: use form encoding for form bodies and strict percent-encoding for URL paths or query components.

Encoding should normally be applied to individual values before they are inserted into a URL, rather than to an already-assembled URL. Encoding an entire URL can encode structural characters such as ? and &, which changes the meaning of the request.

How WebUtility.UrlEncode treats common characters

Microsoft Learn documentation for WebUtility.UrlEncode describes behavior that is useful as a reference point: the method replaces all character codes except letters, numbers, and the punctuation characters -, _, ., !, *, (, and ). Each space character is converted to a plus character by WebUtility.UrlEncode. This means letters and digits usually pass through unchanged, while many symbols and all spaces are transformed.

When to encode a password value

If a password must appear in a URL query string, encode the password value separately before appending it. Do not assume that only obvious symbols need encoding; characters such as @, #, $, %, &, +, ,, /, :, ;, =, ?, and @ may have special meaning depending on position. The safest approach is to avoid placing passwords in URLs entirely and instead send them in an HTTP POST body over HTTPS.

Reader checklist

  • Confirm which encoder your framework uses for query strings.
  • Test whether your target treats + as a space or as a literal plus.
  • Encode values individually, not whole request URLs.
  • Prefer POST bodies and HTTPS for authentication.

Which password characters need encoding

Passwords can contain almost any character, including reserved characters and unsafe characters that URLs reserve for structural purposes. When a password appears literally in a URL or form value, characters with special meaning should be percent-encoded so parsers do not mistake them for delimiters.

Characters that commonly need attention include:

  • Ampersand (&), which separates query parameters
  • Equals sign (=), which separates names from values
  • Question mark (?), which begins a query string
  • Slash (/), which separates path segments
  • Colon (:), which separates scheme from authority and port from host
  • Semicolon (;), which can delimit parameters in some schemes
  • At sign (@), which appears in userinfo syntax
  • Number sign (#), which begins a fragment
  • Percent (%), which begins escape sequences
  • Plus (+), which can represent a space in form encoding
  • Comma (,), which may separate values in some contexts
  • Space, which is encoded differently depending on context

Characters that a reference encoder typically leaves unchanged include uppercase and lowercase letters, digits, and the punctuation set -, _, ., !, *, (, and ). Because password policies vary, a password may contain characters beyond this list. Developers should verify the exact reserved and unsafe character set for their target URL scheme and encoder rather than assuming a universal list.

Comparison of treatment by character category

Character category Examples Typical handling Risk if unencoded
Alphanumeric a-z, A-Z, 0-9 Usually unchanged Low
Unreserved punctuation – _ . ! * ( ) Usually unchanged by some encoders Low
Reserved URL delimiters ? & = / : ; @ # Often percent-encoded when in values Request parsing failure
Space space + in forms, %20 in strict URL encoding Ambiguous or truncated value
Escape introducer % Must be encoded to avoid double-escaping Misinterpreted encoding

Practical guidance

If you must include a password in a query parameter, encode only the password value and insert the encoded result into the parameter. Avoid double-encoding an already-encoded value. Where possible, validate that the server decodes the value to the exact password the user entered.

Questions for your implementation

  • Which reserved characters does your server’s query parser treat as delimiters?
  • Does your form encoder convert spaces to + or %20?
  • Are there password characters your identity provider rejects even after encoding?

Whole URL versus single value encoding

Encoding scope matters because it determines which characters survive the process and which structural meaning is preserved.

When encoding a whole URL, structural separators such as ?, &, =, /, and : normally remain intact because they define the request’s structure. Encoding a single value, by contrast, treats those same characters as ordinary data and encodes them. FormatBits guidance says choose the scope first because a whole URL keeps separators like ? and &, while a single value encodes them.

Example distinction

Suppose a password is p@ss word and the parameter name is pass. Encoding only the value might produce pass=p%40ss%20word, where %40 encodes @ and %20 encodes the space. The ? and & that surround the parameter remain available to structure the URL.

Encoding the entire URL after assembly could encode the ? and & as well, turning delimiters into literal data and potentially making the request unroutable.

When to use each scope

Scope Appropriate use Characters typically preserved Characters typically encoded
Whole URL Encoding an already-complete request URL for transport Scheme, host, path separators, query delimiters User data embedded in the URL
Single value Encoding one query parameter or form value before insertion None within the value Reserved characters, spaces, unsafe symbols

Risks of wrong scope

Encoding too much can break routing. Encoding too little can leave passwords or delimiters exposed or misinterpreted. If a password contains & and you encode the whole URL, the & may no longer separate parameters as intended. If you encode only part of the value, leftover special characters may truncate the password or inject extra parameters.

Implementation tip

Assemble the URL structure first, then encode each dynamic value individually before insertion. Keep the structural template unchanged.

Safe password transmission in requests

Putting passwords in URL query strings is discouraged even when percent-encoded. Query strings are often stored in browser history, server access logs, proxy logs, and referer headers. Percent-encoding protects the format of the request, but it does not hide the password from systems that record URLs.

MDN describes registration and login submission as sending username and password to the server in an HTTP POST request over HTTPS. This places credentials in the request body rather than the URL and encrypts the transport layer. HTTPS helps protect the password in transit, while a POST body keeps it out of URL-based logs and history.

Safer authentication pattern

  1. Collect the username and password in a form.
  2. Submit the form with method POST.
  3. Use HTTPS for the endpoint.
  4. Send credentials in the request body, not the query string.
  5. Avoid logging raw request bodies containing passwords.

Percent-encoding’s role

Percent-encoding is still relevant when password values must appear in URLs, such as legacy APIs or callback parameters. In those cases, encode the password value individually and use HTTPS. Treat percent-encoding as a formatting safeguard, not a substitute for transport encryption or body-based submission.

What to verify

  • Whether your framework automatically encodes form values.
  • Whether your server logs query strings or request headers.
  • Whether your identity provider accepts encoded password values and decodes them correctly.
  • Whether your deployment enforces HTTPS for authentication endpoints.

If any of these cannot be confirmed, treat the configuration as a gap to resolve before sending passwords through URLs.

FormatBits URL codec tool context

FormatBits is a developer data-formatting and encoding product. Its enabled modules include json-format, url-codec, and timestamp-convert. The URL codec module is relevant to this guide because it supports encoding and decoding URL-related values.

FormatBits guidance says choose the scope first because a whole URL keeps separators like ? and &, while a single value encodes them. This reinforces the distinction between encoding an entire URL and encoding one password value.

Scope and input considerations

Because changeable facts such as tool limits or operating details are isolated in the source facts and are not presented as verified current rules, this guide does not state exact maximum input lengths, character limits, or concurrent usage caps for the FormatBits URL codec. Readers should check the FormatBits interface or documentation for current input limits before processing long passwords or bulk values.

How to use the tool contextually

  • Select url-codec when you need to encode or decode a single value.
  • Choose whole-URL scope only when the intent is to transform an entire URL string.
  • Choose single-value scope when preparing a password or form value for insertion.
  • Verify decoded output matches the original password before relying on the result in authentication.

Reader questions

  • What is the current maximum input length for the url-codec module?
  • Does the tool preserve UTF-8 multibyte characters during encoding?
  • Are encoded results copy-safe for direct insertion into query parameters?