cleanUrl: /posts/user-agent-is-not-recomended
share: true

이 내용은 RFC7231 문서에서 확인한 내용이다. 실제로 Client 의 device 와 관련된 정보를 파악하기에는 추천되지 않는다. Microsoft 문서에서도 User-Agent 를 사용자의 client 정보를 확인하는데 사용하지 말 것을 추천한다.

RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content

The User-Agent (Section 5.5.3), Via (Section 5.7.1 of [RFC7230]), and Server (Section 7.4.2) header fields often reveal information about the respective sender's software systems. In theory, this can make it easier for an attacker to exploit known security holes; in practice, attackers tend to try all potential holes regardless of the apparent software versions being used.

Proxies that serve as a portal through a network firewall ought to take special precautions regarding the transfer of header information that might identify hosts behind the firewall. The Via header field allows intermediaries to replace sensitive machine names with pseudonyms.

User-Agent 에서 수집하는 정보는 다음과 같다.

이와 같은 정보를 수집하는 HTTP header 이다.

하지만 이 정보들이 항상 있다고 확신할 수는 없다.

RFC에 규칙은 명시되어 있지만, 이 규칙을 따르지 않는 경우가 많다.

위 정보를 바탕으로 Mobile, Tablet, Desktop, etc. 를 찾아내야 한다. (app 사용 여부는 추가된 문자열로 파악이 더 간단하다)

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36

User-agent 를 확인한 나의 맥북이 ARM(M1) 맥북이지만, Intel 이라고 반환된다.

구분이 가능한 경우