How QR codes work and what makes them dangerous – a computer scientist explains
<p>Among the many changes brought about by the pandemic is the widespread use of QR codes, graphical representations of digital data that can be printed and later scanned by a smartphone or other device.</p>
<p>QR codes have a <a href="https://www.forbes.com/sites/forbescommunicationscouncil/2021/03/25/how-the-pandemic-saved-the-qr-code-from-extinction/" target="_blank" rel="noopener">wide range of uses</a> that help people avoid contact with objects and close interactions with other people, including for sharing <a href="https://www.cnbc.com/2021/08/21/qr-codes-have-replaced-restaurant-menus-industry-experts-say-it-isnt-a-fad.html" target="_blank" rel="noopener">restaurant menus</a>, email list sign-ups, car and home sales information, and checking in and out of medical and professional appointments.</p>
<p>QR codes are a close cousin of the bar codes on product packaging that cashiers scan with infrared scanners to let the checkout computer know what products are being purchased.</p>
<p>Bar codes store information along one axis, horizontally. QR codes store information in both vertical and horizontal axes, which allows them to hold significantly more data. That extra amount of data is what makes QR codes so versatile.</p>
<p><strong>Anatomy of a QR code</strong></p>
<p>While it is easy for people to read Arabic numerals, it is hard for a computer. Bar codes encode alphanumeric data as a series of black and white lines of various widths. At the store, bar codes record the set of numbers that specify a product’s ID. Critically, data stored in bar codes is redundant. Even if part of the bar code is destroyed or obscured, it is still possible for a device to read the product ID.</p>
<p>QR codes are designed to be scanned using a camera, such as those found on your smartphone. QR code scanning is built into many camera apps for Android and iOS. QR codes are most often used to store web links; however, they can store arbitrary data, such as text or images.</p>
<p>When you scan a QR code, the QR reader in your phone’s camera deciphers the code, and the resulting information triggers an action on your phone. If the QR code holds a URL, your phone will present you with the URL. Tap it, and your phone’s default browser will open the webpage.</p>
<p>QR codes are composed of several parts: data, position markers, quiet zone and optional logos.</p>
<figure class="align-center zoomable"><em><a href="https://images.theconversation.com/files/451140/original/file-20220309-17-1jkfl5t.png?ixlib=rb-1.1.0&q=45&auto=format&w=1000&fit=clip"><img src="https://images.theconversation.com/files/451140/original/file-20220309-17-1jkfl5t.png?ixlib=rb-1.1.0&q=45&auto=format&w=754&fit=clip" sizes="(min-width: 1466px) 754px, (max-width: 599px) 100vw, (min-width: 600px) 600px, 237px" srcset="https://images.theconversation.com/files/451140/original/file-20220309-17-1jkfl5t.png?ixlib=rb-1.1.0&q=45&auto=format&w=600&h=372&fit=crop&dpr=1 600w, https://images.theconversation.com/files/451140/original/file-20220309-17-1jkfl5t.png?ixlib=rb-1.1.0&q=30&auto=format&w=600&h=372&fit=crop&dpr=2 1200w, https://images.theconversation.com/files/451140/original/file-20220309-17-1jkfl5t.png?ixlib=rb-1.1.0&q=15&auto=format&w=600&h=372&fit=crop&dpr=3 1800w, https://images.theconversation.com/files/451140/original/file-20220309-17-1jkfl5t.png?ixlib=rb-1.1.0&q=45&auto=format&w=754&h=467&fit=crop&dpr=1 754w, https://images.theconversation.com/files/451140/original/file-20220309-17-1jkfl5t.png?ixlib=rb-1.1.0&q=30&auto=format&w=754&h=467&fit=crop&dpr=2 1508w, https://images.theconversation.com/files/451140/original/file-20220309-17-1jkfl5t.png?ixlib=rb-1.1.0&q=15&auto=format&w=754&h=467&fit=crop&dpr=3 2262w" alt="a black-and-white pattern with four numerical markers attached to arrows pointing to portions of the pattern" /></a></em><figcaption><em><span class="caption">The QR code anatomy: data (1), position markers (2), quiet zone (3) and optional logos (4).</span> <span class="attribution"><span class="source">Scott Ruoti</span>, <a class="license" href="http://creativecommons.org/licenses/by-nd/4.0/" target="_blank" rel="noopener">CC BY-ND</a></span></em></figcaption></figure>
<p>The data in a QR code is a series of dots in a square grid. Each dot represents a one and each blank a zero in binary code, and the patterns encode sets of numbers, letters or both, including URLs. At its smallest this grid is 21 rows by 21 columns, and at its largest it is 177 rows by 177 columns. In most cases, QR codes use black squares on a white background, making the dots easy to distinguish. However, this is not a strict requirement, and QR codes can use any color or shape for the dots and background.</p>
<p>Position markers are squares placed in a QR code’s top-left, top-right, and bottom-left corners. These markers let a smartphone camera or other device orient the QR code when scanning it. QR codes are surrounded by blank space, the quiet zone, to help the computer determine where the QR code begins and ends. QR codes can include an optional logo in the middle.</p>
<p>Like barcodes, QR codes are designed with data redundancy. Even if as much as 30% of the QR code is destroyed or difficult to read, <a href="https://www.businessinsider.com/what-is-a-qr-code?op=1" target="_blank" rel="noopener">the data can still be recovered</a>. In fact, logos are not actually part of the QR code; they cover up some of the QR code’s data. However, due to the QR code’s redundancy, the data represented by these missing dots can be recovered by looking at the remaining visible dots.</p>
<p><strong>Are QR codes dangerous?</strong></p>
<p>QR codes are not inherently dangerous. They are simply a way to store data. However, just as it can be hazardous to click links in emails, visiting URLs stored in QR codes can also be risky in several ways.</p>
<p>The QR code’s URL can take you to a phishing website that tries to <a href="https://www.ic3.gov/Media/Y2022/PSA220118" target="_blank" rel="noopener">trick you</a> into entering your username or password for another website. The URL could take you to a legitimate website and trick that website into doing something harmful, such as giving an attacker access to your account. While such an attack requires a flaw in the website you are visiting, such vulnerabilities are <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting" target="_blank" rel="noopener">common on the internet</a>. The URL can take you to a malicious website that tricks another website you are logged into on the same device to take an unauthorized action.</p>
<p>A malicious URL could open an application on your device and cause it to take some action. Maybe you’ve seen this behavior when you clicked a Zoom link, and the Zoom application opened and automatically joined a meeting. While such behavior is ordinarily benign, an attacker could use this to trick some apps into revealing your data.</p>
<p>It is critical that when you open a link in a QR code, you ensure that the URL is safe and comes from a trusted source. Just because the QR code has a logo you recognize doesn’t mean you should click on the URL it contains.</p>
<p>There is also a slight chance that the app used to scan the QR code could contain a vulnerability that allows <a href="https://www.lifewire.com/how-to-protect-yourself-from-malicious-qr-codes-2487772" target="_blank" rel="noopener">malicious QR codes to take over your device</a>. This attack would succeed by just scanning the QR code, even if you don’t click the link stored in it. To avoid this threat, you should use trusted apps provided by the device manufacturer to scan QR codes and avoid downloading custom QR code apps.<!-- Below is The Conversation's page counter tag. Please DO NOT REMOVE. --><img style="border: none !important; box-shadow: none !important; margin: 0 !important; max-height: 1px !important; max-width: 1px !important; min-height: 1px !important; min-width: 1px !important; opacity: 0 !important; outline: none !important; padding: 0 !important;" src="https://counter.theconversation.com/content/177217/count.gif?distributor=republish-lightbox-basic" alt="The Conversation" width="1" height="1" /><!-- End of code. If you don't see any code above, please get new code from the Advanced tab after you click the republish button. The page counter does not collect any personal data. More info: https://theconversation.com/republishing-guidelines --></p>
<p><em><a href="https://theconversation.com/profiles/scott-ruoti-1318954" target="_blank" rel="noopener">Scott Ruoti</a>, Assistant Professor of Computer Science, <a href="https://theconversation.com/institutions/university-of-tennessee-688" target="_blank" rel="noopener">University of Tennessee</a></em></p>
<p><em>This article is republished from <a href="https://theconversation.com" target="_blank" rel="noopener">The Conversation</a> under a Creative Commons license. Read the <a href="https://theconversation.com/how-qr-codes-work-and-what-makes-them-dangerous-a-computer-scientist-explains-177217" target="_blank" rel="noopener">original article</a>.</em></p>
<p><em>Image: Getty Images</em></p>