Magic string

In computer programming, a magic string is an input that a programmer believes will never come externally and which activates otherwise hidden functionality. A user of this program would likely provide input that gives an expected response in most situations. However, if the user does in fact innocently provide the pre-defined input, invoking the internal functionality, the program response is often quite unexpected to the user (thus appearing "magical").[1]

Background

Typically, the implementation of magic strings is due to time constraints. A developer must find a fast solution instead of delving more deeply into a problem and finding a better solution.

For example, when testing a program that takes a user's personal details and verifies their credit card number, a developer may decide to add a magic string shortcut whereby entering the unlikely input of "***" as a credit card number would cause the program to automatically proceed as if the card were valid, without spending time verifying it. If the developer forgets to remove the magic string, and a user of the final program happens to enter "***" as a placeholder credit card number while filling in the form, the user would inadvertently trigger the hidden functionality.

Resolution

Situations/issues of cause

Often there are significant time constraints out of the developer's control right from the beginning of their involvement in a project. Common issues that might lead to this anti-pattern as a result:

  • Null != null[2] or any variation where a data type doesn't compare bitwise to a supposedly identical type. This is an issue that can even occur within the same development environment (same programming language and compiler). This problem has a long history for numerical and boolean types and most compilers handle this well (with applicable warnings and errors, default resolution, etc...). Nullable types such as strings have the difficulty of historically different definitions for NULL. The errors/warnings produced are often general or a 'best fit' default error whose message does not actually describe what's going on. If the developer can't get enough clues to track the issue down through debugging, taking a short cut, and coding in a 'default' string, may be the only way to keep the project on schedule. One solution to this may be the application of the Null Object pattern.[3]
  • Programmed into a corner. Sometimes a design seems straightforward and even simple but turns out to have a logical flaw, dependent upon the possible user inputs, due to an often unforeseen circumstance towards the end of planned development. Thus a developer might feel the need to implement a user input with special security/operational allowances to deal with such circumstances. This can be particularly ironic since it will sometimes become obvious that a more robust design from the beginning would likely have left room to handle the flaw. However this would perhaps have taken too much time to implement and it might have conflicted with the fundamental engineering concept of KISS, keeping a design and implementation simple and meeting only the initial necessary requirements.
  • Allowing external access to a global flag.[4] Over-confidence that a global flag can never be set accidentally or maliciously (often a quite reasonable assumption) justifies such implementation for testing and debug purposes, especially for small applications with simple interfaces. If the distribution of the program is considerable however, it is usually just a matter of time before somebody sets the flag. An obvious solution is to never use a global variable in such a manner. A developer might also make the flag circumstantially accessible. So the magic string by itself would be dealt with by the program as any other input.[5] The user has to then reproduce the setting as well as produce some collection of other events, that the user interface discreetly allows, for the flag to accept the setting; a far more unlikely scenario, though still possible.

Strict formatting

Restricting the format of the input is a possible maintenance (bug fixing) solution.[clarification needed] Essentially, this means validating input information to check that it is in the correct format, in order to reduce the possibility of the magic string being discovered by the user. Examples include validating a telephone number to ensure that it contains only digits (and possibly spaces and punctuation to a limited extent) or checking that a person's name has a forename and a surname (and is appropriately capitalised). An exception is made for the magic string in the validation code so that it will not be rejected by validation. It is expected that, since a user would likely quickly notice the strict enforcement of formatting, it would likely not occur to the user to try inputting a string not conforming to the format. Therefore, it is very unlikely for the user to try the magic string.

As with any input validation process, it is important to ensure that the format is not restrictive in a way that unintentionally restricts the use of the application by some users. An example of this is restricting telephone number or postal code[6] input based on one country's system (e.g. requiring every user to give a five-digit ZIP code), causing problems for legitimate users who are based in other countries.

Purposeful implementation

As is often the case with anti-patterns, there exist specific scenarios where magic strings are a correct solution for an implementation. Examples include cheat codes[7] and Easter eggs. Furthermore, there are cases when users invent magic strings, and systems that have not coded to accept them can produce unexpected results such as missing license plates.[8]

Incidents

The following is a list of some known incidents where use of a magic string has caused problems.

  • In several different cases, motorists with personalized strings on their vehicle registration plates have received incorrect traffic tickets. In affected ticketing systems, when police officers would fill out a traffic ticket for a car with no registration plate, they would write "NOPLATE", "NOTAG", "MISSING", or similar. This caused issues when motorists were granted actual registration plates with these values, and thus began receiving numerous traffic tickets intended for these plateless vehicles.[8]
  • In 1999, hackers revealed a security flaw in Hotmail that permitted anybody to log in to any Hotmail account using the password 'eh'. At the time it was called "the most widespread security incident in the history of the Web".[9]
  • People with the last name Null have reported a variety of problems using online systems, such as being unable to book plane tickets, use government tax websites, or pay utility bills.[10] The issue stems from these systems confusing their name for a null pointer. Depending on the system, this may cause the system to not show their name, to ask the user to enter a different name (sometimes with a message claiming that the name field had been left blank), or to show an error message.[11]

See also

References

  1. ^ Chris Falter (March 6, 2008), A Good Solution for Magic String Data, Egghead Cafe Tuturiols, retrieved May 11, 2009
  2. ^ Wang Lam (May 21, 2003), The Behavior of NULL's in SQL, Stanford University, retrieved May 13, 2009
  3. ^ Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates; 2004, Head First Design Patterns, 1st ed., O'Reilly, Chapter 6, pg. 214, The Command Pattern, ISBN 0-596-00712-4, ISBN 978-0-596-00712-6
  4. ^ James McCaffrey (2009), Test Automation for ASP.NET Web Apps with SSL, Microsoft, retrieved May 13, 2009
  5. ^ Andrew Cumming; 2007, SQL Hacks, 1st ed., O'Reilly, pg. 174, Prevent an SQL Injection Attack, ISBN 0-596-52799-3, ISBN 978-0-596-52799-0
  6. ^ Brian Knight, Allan Mitchell, Darren Green, Douglas Hinson, Kathi Kellenberger; 2005, Professional SQL server 2005 integration services, 1st ed., John Wiley and Sons, Chapter 5, pg. 129, Handling Dirty Data, ISBN 0-7645-8435-9, ISBN 978-0-7645-8435-0
  7. ^ Sezen, Tonguc Ibrahim; Isikoglu, Digdem (April 27, 2007). "From Ozans to God-Modes: Cheating in Interactive Entertainment From Different Cultures" (PDF). p. 8. Retrieved January 24, 2009.
  8. ^ a b "What Happens when Your License Plate Says 'NO PLATE'?". October 30, 1999.
  9. ^ Glave, James (August 30, 1999). "Hotmail Hackers: 'We Did It'". Wired. Condé Nast. Retrieved July 16, 2024.
  10. ^ Baraniuk, Chris (March 25, 2016). "These unlucky people have names that break computers". BBC.com. Retrieved January 30, 2022.
  11. ^ Null, Christopher (November 5, 2015). "Hello, I'm Mr. Null. My Name Makes Me Invisible to Computers". Wired. Retrieved January 30, 2022.

Read other articles:

Itochu CorporationNama asli伊藤忠商事株式会社Nama latinItōchū Shōji kabushiki gaishaSebelumnyaC. Itoh & Co., Ltd.JenisPublik KKKode emitenTYO: 8001Komponen TOPIX Large 70IndustriPerdagangan umumDidirikan1858 (perusahaan pendahulu)1949 (perusahaan saat ini)PendiriChubei ItohKantorpusatKita-ku, Osaka, JepangMinato, Tokyo, Jepang[butuh rujukan]TokohkunciEizo Kobayashi (Chairman)Masahiro Okafuji (Presiden dan CEO)Pendapatan ¥4,838 triliun (Maret 2018)Laba bersih ¥374,5 m...

 

Aphrodisium faldermannii Klasifikasi ilmiah Kerajaan: Animalia Filum: Arthropoda Kelas: Insecta Ordo: Coleoptera Famili: Cerambycidae Genus: Aphrodisium Spesies: Aphrodisium faldermannii Aphrodisium faldermannii adalah spesies kumbang tanduk panjang yang tergolong famili Cerambycidae. Spesies ini juga merupakan bagian dari genus Aphrodisium, ordo Coleoptera, kelas Insecta, filum Arthropoda, dan kingdom Animalia. Larva kumbang ini biasanya mengebor ke dalam kayu dan dapat menyebabkan kerusaka...

 

Ini adalah nama Jepang, nama keluarganya adalah Noguchi. Yonejirō NoguchiLahir(1875-12-08)8 Desember 1875Tsushima, Aichi, JepangMeninggal13 Juli 1947(1947-07-13) (umur 71)TokyoNama penaYone NoguchiPekerjaanPenyairessayistkritikus sastraPeriode1897–1947Aliran sastraImagismePasanganMatsu TakedaPasangan hidupEthel ArmesLéonie GilmourAnakIsamu Noguchi Yonejirō Noguchi (野口 米次郎code: ja is deprecated , Noguchi Yonejirō, 8 Desember 1875 – 13 Juli 19...

Genus of bacteria Enterobacter Enterobacter cloacae on trypticase soy agar Scientific classification Domain: Bacteria Phylum: Pseudomonadota Class: Gammaproteobacteria Order: Enterobacterales Family: Enterobacteriaceae Genus: EnterobacterHormaeche & Edwards 1960 Species This list is incomplete; you can help by adding missing items. (October 2021) E. aerogenes E. amnigenus E. arachidis E. asburiae E. bugandensis E. cancerogenous E. cloacae E. cowanii E. dissolvens E. gergoviae E. helveticu...

 

State beach in Santa Cruz County, California, United States New Brighton State BeachShow map of CaliforniaShow map of the United StatesLocationSanta Cruz County, CaliforniaNearest cityCapitolaCoordinates36°58′42″N 121°56′15″W / 36.97833°N 121.93750°W / 36.97833; -121.93750Governing bodyCalifornia Department of Parks and Recreation Stairs to campgrounds New Brighton State Beach is a 95 acres (38 ha) beach park on Monterey Bay in Santa Cruz Cou...

 

Voce principale: Hellas Verona Football Club. Associazione Calcio Hellas VeronaStagione 1981-1982 Sport calcio Squadra Verona Allenatore Osvaldo Bagnoli Presidente Celestino Guidotti Serie B1º posto (promosso in Serie A). Coppa ItaliaFase a gironi Miglior marcatoreCampionato: Penzo (14)Totale: Penzo (16) StadioMarcantonio Bentegodi Abbonati4 764[1] Media spettatori19 273 1980-1981 1982-1983 Si invita a seguire il modello di voce Questa voce raccoglie le informazioni r...

La stabilità statica longitudinale è la capacità di un velivolo di riguadagnare un precedente assetto di equilibrio longitudinale una volta esaurito l'effetto di una piccola perturbazione che agisca nel piano di beccheggio del velivolo stesso. Indice 1 Equilibrio statico longitudinale 2 Stabilità statica longitudinale 2.1 Velivoli con configurazione convenzionale 2.2 Velivoli con stabilità statica rilassata 2.3 Velivoli canard 3 Note 4 Bibliografia 5 Voci correlate 6 Altri progetti Equil...

 

古斯塔夫·胡萨克Gustáv Husák捷克斯洛伐克共产党中央委员会总书记(1969-1971年称第一书记)任期1969年4月17日—1987年12月17日(18年244天)前任亞歷山大·杜布切克继任米洛什·雅克什捷克斯洛伐克总统任期1975年5月29日—1989年12月10日(14年195天)前任卢德维克·斯沃博达继任瓦茨拉夫·哈维尔 个人资料出生(1913-01-10)1913年1月10日 奥匈帝国布拉迪斯拉发杜布拉夫卡逝世1991年11...

 

Sumber referensi dari artikel ini belum dipastikan dan mungkin isinya tidak benar. Mohon periksa, kembangkan artikel ini, dan tambahkan sumber yang benar pada bagian yang diperlukan. (Pelajari cara dan kapan saatnya untuk menghapus pesan templat ini) artikel ini perlu dirapikan agar memenuhi standar Wikipedia. Tidak ada alasan yang diberikan. Silakan kembangkan artikel ini semampu Anda. Merapikan artikel dapat dilakukan dengan wikifikasi atau membagi artikel ke paragraf-paragraf. Jika sudah d...

The Vickers Wellington is a British twin-engined, long-range medium bomber aircraft that was produced from 1936 to 1945 and used throughout World War II. It was operated by a number of nations and service branches around the world. Operators Australia Royal Australian Air Force No. 458 Squadron RAAF Code letters FU No. 460 Squadron RAAF Code letters UV and AR No. 466 Squadron RAAF Code letters HD Canada Royal Canadian Air Force No. 405 Squadron RCAF 'Vancouver Squadron' Code letters LQ No. 4...

 

العلاقات الغرينادية الليبيرية غرينادا ليبيريا   غرينادا   ليبيريا تعديل مصدري - تعديل   العلاقات الغرينادية الليبيرية هي العلاقات الثنائية التي تجمع بين غرينادا وليبيريا.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: وجه ...

 

Artikel ini tidak memiliki referensi atau sumber tepercaya sehingga isinya tidak bisa dipastikan. Tolong bantu perbaiki artikel ini dengan menambahkan referensi yang layak. Tulisan tanpa sumber dapat dipertanyakan dan dihapus sewaktu-waktu.Cari sumber: Kera shio – berita · surat kabar · buku · cendekiawan · JSTOR Shio Kera (Hanzi: 猴, Pinyin: Hóu) adalah shio kesembilan dari kedua belas shio yang ada dalam penanggalan Tionghoa. Orang yang bershi...

بات هانراهان   معلومات شخصية الميلاد مايو 1955 (69 سنة)  مواطنة الولايات المتحدة  عضو في الأكاديمية الوطنية للهندسة،  وجمعية آلات الحوسبة،  والأكاديمية الأمريكية للفنون والعلوم  الحياة العملية المدرسة الأم جامعة ويسكونسن-ماديسون  المهنة مهندس،  وعالم حا�...

 

Original source of information created at the time under study For Wikipedia's policy on the use of primary sources, see Wikipedia:No original research § Primary. This wall painting found in the Roman city of Pompeii is an example of a primary source about people in Pompeii in Roman times (portrait of Terentius Neo). In the study of history as an academic discipline, a primary source (also called an original source) is an artifact, document, diary, manuscript, autobiography, recording, ...

 

Demographics of England This article is about all people living in Cornwall. For the ethnic group, see Cornish people. This article cites its sources but does not provide page references. You can help providing page numbers for existing citations. (November 2021) (Learn how and when to remove this message) Cornwall is a unitary authority and ceremonial county of England in the United Kingdom. At the 2011 census it had a population of 532,000.[1] Cornwall is the homeland of the Cornish...

Kwara merupakan sebuah negara bagian yang terletak di bagian barat Nigeria. Ibu kotanya ialah Ilorin. Didirikan pada tahun 1967. Negara bagian ini memiliki luas wilayah 36.825 km². Dengan memiliki jumlah penduduk sebanyak 2.591.555 jiwa (2005). Pembagian administrasi Asa Baruten Edu Ekiti Ifelodun Ilorin-East Ilorin-South Ilorin-West Irepodun Isin Kaiama Moro Offa Oke-Ero Oyun Patigi lbsNegara bagian di Nigeria Abia · Wilayah Ibu Kota Federal Abuja · Adamawa · Akwa Ibom...

 

History United States NameUSS LST-701 BuilderJeffersonville Boat & Machine Company, Jeffersonville, Indiana Laid down1 April 1944 Launched18 May 1944 Commissioned13 June 1944 Decommissioned13 July 1946 Stricken28 August 1946 Honours andawards3 battle stars (World War II) FateSold for scrapping, 27 October 1947 General characteristics Class and typeLST-542-class tank landing ship Displacement 1,625 long tons (1,651 t) light 3,640 long tons (3,698 t) full Length328 ft (100&#...

 

Awaloedin DjaminAwaloedin Djamin saat menjadi Ketua Badan Pertimbangan Pendidikan Nasional (1998–2003) Rektor Universitas PancasilaMasa jabatan1983–1995PenggantiSubrotoKepala Staf Angkatan Kepolisian Republik Indonesia ke-8Masa jabatan26 September 1978 – 3 Desember 1982PresidenSoehartoPendahuluWidodo BudidarmoPenggantiAnton SoedjarwoDuta Besar Indonesia untuk Jerman Barat ke-8Masa jabatan1976–1978PresidenSoehartoPendahuluAchmad TirtosudiroPenggantiJosef MuskitaKepala ...

Extinct genus of vascular plants in the Order Equisetales Not to be confused with Calamities. This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Calamites – news · newspapers · books · scholar · JSTOR (October 2020) (Learn how and when to remove this message) CalamitesTemporal range: Carboniferous–Early Permi...

 

Questa voce o sezione deve essere rivista e aggiornata appena possibile. Sembra infatti che questa voce contenga informazioni superate e/o obsolete. Se puoi, contribuisci ad aggiornarla. Questa voce sull'argomento competizioni ciclistiche è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Grote Prijs Sven NysSport Ciclocross TipoGara individuale CategoriaUomini Elite, Under-23, JuniorDonne Elite, Junior F...