문제인식
MFA 관련 개발을 하면서 Google Authentication 앱을 사용하여 QR Code 이미지를 페이지에 보여주도록 하는 일이 있었다.
문제는 생성된 QR Code 이미지가 안드로이드 폰에서는 잘 작동하는데, iOS에서는 잘못된 바코드라는 오류메시지와 함께 작동하지 않았다.
이유를 찾다보니까 QR Code 이미지를 web URL을 이용하여 생성하는데, 이때 사용되는 문자열에 URL에서 중요하게 사용되는 예약 문자가 있어서 문자열을 파싱하는데 이슈가 있었다.
URL Encoding
URL Encoding은 예약문자들을 표현하기 위하여 대체문자를 사용하는 것을 의미한다.
Percent Encoding이라고 표현하기도 하며, 관련 규약은 RFC 3986에 정의되어 있다.
2.1. Percent-Encoding
A percent-encoding mechanism is used to represent a data octet in a component when that octet's corresponding character is outside the allowed set or is being used as a delimiter of, or within, the component. A percent-encoded octet is encoded as a character triplet, consisting of the percent character "%" followed by the two hexadecimal digits representing that octet's numeric value. For example, "%20" is the percent-encoding for the binary octet "00100000" (ABNF: %x20), which in US-ASCII corresponds to the space character (SP). Section 2.4 describes when percent-encoding and decoding is applied.
pct-encoded = "%" HEXDIG HEXDIG
The uppercase hexadecimal digits 'A' through 'F' are equivalent to the lowercase digits 'a' through 'f', respectively. If two URIs differ only in the case of hexadecimal digits used in percent-encoded octets, they are equivalent. For consistency, URI producers and normalizers should use uppercase hexadecimal digits for all percent- encodings.
위의 표에 있는 예약 문자들은 옥텟 단위로 묶어서 16진수 값으로 인코딩해야 한다.
예를들어 ? 문자는 이후에 나오는 내용이 쿼리스트링 파라미터라는 것을 의미하며, cp = 0 은 key = value 값을 의미한다.
이런 의미를 가지고 있는 기호들이 제대로 동작하기 위하여 의미가 아닌 문자로 쓰여야 하는 예약문자는 %인코딩으로 표현하여야 한다.
참고자료
https://ko.wikipedia.org/wiki/%ED%8D%BC%EC%84%BC%ED%8A%B8_%EC%9D%B8%EC%BD%94%EB%94%A9
퍼센트 인코딩 - 위키백과, 우리 모두의 백과사전
ko.wikipedia.org
https://datatracker.ietf.org/doc/html/rfc3986
RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax
datatracker.ietf.org
'IT > WEB' 카테고리의 다른 글
[Nginx] Nginx Architecture (0) | 2023.04.11 |
---|---|
[Nginx] Nginx 소개 (0) | 2023.04.05 |
[WEB]Session이란? (0) | 2022.06.14 |