Skip to main content
View on YouTube to comment and like!

Syntax Video

Apple Source Code LEAKED | App Store Analysis

Chapter 1 00:00

Transcript

Apple just launched a brand new web-based version of their app store. So, previously these were just native apps on iOS and Mac, but now you can visit them in a web browser, including Firefox and uh navigate and see all of the apps that they have available. And it's built with spelt, which is good news for the spelt crowd. But when they released their website, they also included source maps. And source maps actually allow you to see the original source code. Now, of course, this is just front-end source code, but I have seen some things. I've seen things that Apple probably does not want you to see based on these source maps, which they have since removed. So, in this video, we're going to dive into all of the things that I found, as well as talk about like, should you publish source maps? Because in this Reddit thread, there are all kinds of people that are attempting to dunk on juniors or front-end devs that don't know anything, saying that exposing exposing your source maps is an okay thing to do. But I'm here to show you that in instances like this, it is not because it's actually revealed a lot of internal things about Apple that they probably didn't want you to know. So, in this video, we're going to dive into that.

And I'd love to hear from you as well in the comments. Do you release source maps when you publish your application? Uh because, as I'm going to show, maybe you shouldn't. But anyways, welcome to Syntax. We have all kinds of videos. We publish regularly. We have tasty treats for web developers. Um including other videos where we dive into how websites were built. And uh we have a podcast that's published twice a week. and a newsletter you can subscribe to to keep you up to date on all the latest tech and also some interesting things that we find around the web. If that sounds good, just subscribe and uh welcome to syntax. My name is CJ. Let's dive in.

[music] Okay, first I want to show you what a source map is and what it gives you. So here I have a spelt and vit application and source maps are not enabled. So this is a fully built application. This is something like you would deploy to a static server. If we open up the dev tools, click on debugger, we can see under assets, there's just a single JavaScript file. And this is a minified and bundled JavaScript file. So even though we're using spelt, all of that is in a single JavaScript file. And in the uh debugger here, I can actually format it and see all of the codes. And um somewhere in there is uh this code here that actually has a button that we can click on. Um, I believe it's getting rendered like right here. But you can see that this is not straightforward to look at, right? This is not code that I wrote. This is code that got generated by the build. Now, in this instance, source maps are not enabled. And that's why we're only seeing a single JavaScript file. Because if we take a look at the network tab, when I load

Chapter 2 1:32

what are source maps?

this web page, it's just going to load the HTML, JavaScript, CSS, and then some SVGs. That's the only stuff that it needs to load, and that's all is required to make this counter work. Okay. Now, let's enable source maps. And so in a VIT application to enable source maps in the build section you can set source map to inline and then we'll run a build. So do pmppm build. You'll actually see in the output that the map itself is 300 kilobyt. So that's all of my comments. That's actually the actual spelt source code. It's including all of that in the map. So when we look at it in the debugger, we're going to see the original source code and not just the minified source code. So now if I refresh the page, open up the dev tools, you'll see it's more than just a single JavaScript file. And because these are inline source maps, you'll notice even if we look at the network tab, there's nothing extra being sent across the network because those source maps are embedded in that JavaScript file. So now on the debugger tab, we can see all of our node modules and dependencies like spelt and we can see our source directory. So if we click on this, this

Chapter 3 2:37

how to enable / disable source maps?

Chapter 4 3:02

view source maps in dev tools

is the actual spelt component for the app component. And then if we go into lib, this is the actual spelt component for that counter component. And we're seeing the original source code, right? We're not seeing the minified version. And so this is what source maps give you. and they're really great for debugging, but they also could include certain secret information. And that's what I want to show you. So, in this counter component, I left a comment behind that says to-do the query param is not publicly known. Don't let people use this until we are ready. And you'll notice that if I include a query param, it's going to set the initial value of count. So, basically, if I do initial equals 42, now when the page loads, the button starts at 42. Now again this is this is a client side vulnerability but this could be talking to some back-end service and also you could have other things in the comments here um and when you include source maps all of your comments all of your original source code is included as well. So this is what source maps are and they are very useful but as I've shown here comments get included and it's a lot easier to

Chapter 5 4:17

comparing original code and minified code

see what the original code was right looking at this I can see okay read in the params from the search get that initial value parse it make sure it's not nan set it on initial state this is code that me as someone that understands spelt can read and understand if we look at the minified version you have to do a lot of extra work to actually figure out what's going on there um and so Let's let's redo this with the minified version where there are no source maps.

And I'll point out by removing the source maps that file is now only 26 kilobytes. So it removed all that extra information. It's just the code that's needed to actually run the site. Now if we take a look, we have this single JavaScript file. Now, like I mentioned, this is minified. You could still try to understand it. Maybe you could throw it at an AI to figure out what this code is doing. Um, but it's going to take a lot more time for an attacker from for a person that does not have good intentions with your website to figure out what's going on. Um, so we could search because I know the vulnerability here. I could search for like URL search params. Yeah. And even this, I mean, you know, you could kind of understand what this is doing. Get get the param and then set it on the number here. But this is minified. And in the security world, this is known as security through obscurity. So this is obfuscation. The reason we do this in the world of web is this is a lot smaller to send across the wire. So by sending a variable with a single letter as its name instead of the full variable name like initial value,

Chapter 6 5:32

why we minify web code

you're actually saving bytes that get sent across uh the network and in turn um your site's going to load a lot faster. So this is why we do this. But these days with sites that we're building that are getting larger and larger and sometimes including business logic on the front end, this minification is sometimes a good thing because it makes it a bit harder for people to figure out what's actually going on. Now, I'm not here to argue that uh obfuscation is security because it's not it's like one level of security, but again, a savvy attacker could could figure out what this code is actually doing and try to find some hidden features or hidden vulnerabilities. So, that's what source maps are. That's what they could make available. And honestly, at the end of the day, one of the biggest reasons to not enable them probably is embarrassment, right? You don't want people seeing your variable names or your folder structure or your uh comments. Those are things best kept secret and internal. So, that's what source maps are. Now, let's take a look at the Apple source code. So, this is the code as was made available by the source maps. I'm not going to make this code public and I'm not going to point

Chapter 7 5:57

minification is good in the modern web

Chapter 8 6:40

apple source code overview

to where you can find it because Apple has since removed those source maps. So, they don't want you to see this stuff. Um, first of all, we can see some dependencies in the node modules folder. And if we look into the source directory and for instance look in components, every single component for the app is available here, including things like the star rating system or the video player. And again, I'm not showing you all of the source code because Apple doesn't want you to see this stuff, but all of that is available via the source maps, including the main app.spelt entry point, including lots of comments that um might have some internal info as well. Now, on that note, some of the main things I found in here that Apple probably doesn't want you to see are in the comments, which can be easily stripped out, but a lot of these comments revealed information about internal architecture and internal structure and internal flow. And all of those things could be used by an attacker to figure out how Apple works internally. And so, if they somehow get access, then they have a better idea of what they're looking at once they get internal access. And one of the first

Chapter 9 7:21

comments reveal a lot

Chapter 11 8:38

internal bug tracking ids

NS hipster about Apple's bug reporting. And if you're in the world of iOS, you probably have come across this before, but Radar is their internal bug tracking tool. They also make some of it publicly available, so you can submit like public bug reports, but I'm guessing that a lot of these IDs are internal Radar IDs. And this points to bugs. It points to features that aren't implemented yet.

And as an attacker, I could go through all of these. And I don't have access to radar, so I can't see the full descriptions, but they do have so a short description next to each one. So with each one of these radar comments, I could start to figure out what are the parts of the codebase that maybe aren't as logically sound or maybe have a bug in them and then try to exploit them on the main website. Now, another thing I found is they're actually using Sentry, which is fun because everything on Syntax is brought to you by Sentry. So they have this internal module called error kit and it actually wraps Sentry to send errors off to Sentry. And if you're not familiar with Sentry, it is an error reporting platform. So if you're running apps in production like Apple is, you want to see what's going wrong. All of those errors that happen while your app is running in production get reported back to the Sentry dashboard. We also have tracing and profiling. Uh you can see which pages are slow or which database queries are slow. You can see what a user was doing when an error happened with replay as well as a ton of other insights into apps running in production. So, Apple trusts Sentry. Don't quote me on that

Chapter 12 9:29

apple uses sentry

because I don't know if it's public, so you should too. Uh, but it's great. Check out Sentry. Everything we do here at Syntax is brought to you by Sentry. We love Sentry. And Apple apparently loves Centry, too. Now, another thing I found about their internal architecture is the particular API gateway that they use. Now, as an attacker, you could use that information to maybe find vulnerabilities uh in that API gateway or you now have more information to be able to poke and prod at their systems.

Chapter 13 10:16

internal api gateway

Chapter 14 10:32

internal private packages leaked

Now, the last thing I found that they definitely did not want to be available to the world are the things inside of node modules and the things inside of shared. And these are essentially internal libraries that are used on multiple Apple websites for utilities like working with objects or arrays or working with the network or uh working with certain UI components. They basically have things in here that are used all across Apple. And typically those pieces are tree shaken and broken apart and embedded and bundled with the rest of their app. But because they included the source maps, all of the source code for those libraries are in this folder here. And again, I don't want to reveal any names of the packages, but these are not available on npm. These are private packages that they host internally. And one of them appears to be a TypeScript port of the native iOS app store. And that's probably how they got a lot of this functionality in here. And that's one of the things that also links out to specific git repos in the comments referencing certain implementations. Um, like I mentioned, there's also utilities for like working with arrays and

objects. And as an attacker, you might actually try to analyze that library and figure out maybe there's a cross-ite scripting vulnerability somewhere in there. And if you know that that package is used across multiple web properties owned by Apple, you could try to start and exploit it as well. So, there's definitely some stuff in here that they did not want you to see, and it would have been much better to be obuscated and also tree shaken and missing so that people could not have prying eyes on this stuff. Now, with all of that said, I want to highlight some of the comments from this Reddit thread because again, I think people are overgeneralizing. So, this top comment, I've had this argument so many times with inexperienced front-end developers. This is not exposing their source code. While yes, it may not be minified and it's slightly more human readable, it's not exposing any additional logic. Remember, obfuscation is not security. talked about this at the beginning. It's a form of security, but it's not ultimate security. But the one thing we noticed in this analysis is it actually did expose some internal libraries. So even though you may think that source maps are only including the the code required for the website, even code that isn't

Chapter 15 11:57

dunking on redditors

linked and would typically be treeshaken is included in those source maps as well. So you can't just say that source code is not exposed because clearly more code is exposed here than would have been if the source maps were disabled. Now, another comment here is it's easier to debug production issues if you have source maps enabled. Well, you don't have to enable them for everyone. You can actually lock the source map URLs to specific internal IP addresses. So, that way they're only accessible internally.

Or you could use a tool like Sentry. So, when you push a new build with Sentry, you can actually upload your source maps. And that way, the app that's running in production, those source source maps aren't available. But if an error occurs, you're actually going to see the source map in your Sentry dashboard. So, there are ways around this to not make your source maps available to the entire world. And this comment, front-end code, not really that big a deal. Not all of its source code.

Like I showed, there's some stuff in here that they do not want you to see. Uh, this also highlights some fun aspects of this. And so, for learning purposes, going through their codebase, seeing that real developers have to-do statements and fix me statements because those were sprinkled throughout the codebase as well. And so, if anything, it is a little bit embarrassing to have those comments exposed to the world like this. But again, if you just disabled source maps, then those wouldn't get leaked to the world. Uh, to this user, nothing special. Wouldn't even mention it in a conversation. Well, my friends, I thought it was worth an entire video.

So, I think it's worth more than a conversation. [laughter] So, just stop releasing your s like I my main issue with this Reddit thread is so many people are downplaying, oh, just release your source maps when very clearly some internal information can be leaked if you leave your source maps on. Bro thinks they found a gold mine here. I I don't know, man. I don't I I think maybe we did. [laughter] Yeah, I would completely agree that obfuscation is not security, but there are other aspects of including source maps that you are not considering. It's like saying I hacked NASA for taking a picture of the front of its building.

Sure, I would not say that this is a hack because while those source maps were available, anybody that went to the website and opened the dev tools could get access to the original source code. So, it's not a big deal that someone downloaded all of this this source code. It's just a big deal that they accidentally left those source maps on. And I say accidentally because now when you visit their website and you go to the debugger, that stuff is no longer available. You only see the minified code. You don't see all of the spelt components and everything else. So even Apple agrees that they do not want you to see those source maps. So they shipped front-end code to the front end.

Yeah, I think uh the issue with Reddit is a bunch of people just start piling on acting like they know what they're talking about when they actually haven't even looked into it. So yeah, the majority of these Reddit users have no idea what they're talking about. [laughter]

Quote it with credit and a link. Quoting Syntax