Latest / CyberCode Academy / Course 39 - NodeJS Security Pentesting and Exploitation | Episode 1: From V8 Fundamentals to Namespace and Parameter Pollution
Transcript
- 0:00Speaker 1: So I want you to imagine something for a second.
- 0:02Speaker 1: You spent I don't know, thousands of dollars implementing this
- 0:05Speaker 1: absolute state of the art web application firewall for your company, right.
- 0:09Speaker 2: A massive investment exactly.
- 0:12Speaker 1: And it is just ruthlessly analyzing every single string of traffic.
- 0:16Speaker 1: It's blocking sequel injections, it's stopping cross sites scripting, and
- 0:21Speaker 1: basically keeping your entire back end completely.
- 0:23Speaker 2: Secure, doing exactly what it's supposed to do.
- 0:26Speaker 1: Right. But then an attacker realizes that your back end
- 0:29Speaker 1: is running no.
- 0:30Speaker 2: Js ah, yes, the plot twist.
- 0:33Speaker 1: Yeah, So instead of trying to outsmart your million dollar
- 0:36Speaker 1: firewall with some kind of complex cryptography or like a
- 0:39Speaker 1: zero day exploit, they just send it a duplicate URL parameter.
- 0:43Speaker 2: Let's a duplicate parameter.
- 0:44Speaker 1: Yeah, and your firewall, which expects a string, receives an
- 0:48Speaker 1: array instead, completely crashes, and the attacker just walks right
- 0:51Speaker 1: through the front door.
- 0:52Speaker 2: I mean, it sounds almost too simple to be real,
- 0:55Speaker 2: but it is just a fundamental reality of how different
- 0:57Speaker 2: layers of a tech stack interpret data. Great it is
- 1:01Speaker 2: because when you change the underlying rules of how a
- 1:04Speaker 2: server process is information, you inevitably change the rules of
- 1:09Speaker 2: how that server can be exploited.
- 1:11Speaker 1: And well, that is exactly what we're exploring in this
- 1:14Speaker 1: deep dive today. We are looking at nodes JS. It's
- 1:18Speaker 1: a huge topic, it really is. I mean, node is
- 1:21Speaker 1: undeniably powerful, it's blisteringly fast, and it runs a massive
- 1:25Speaker 1: chunk of the modern web as we know it absolutely
- 1:27Speaker 1: but hidden inside its unique architecture are these very specific
- 1:32Speaker 1: security traps that can blindside well, even incredibly experienced developers.
- 1:36Speaker 2: Yeah, people who have been coding for years get caught
- 1:38Speaker 2: by this.
- 1:39Speaker 1: Right, So for you listening, our mission today is to
- 1:42Speaker 1: walk through those engine mechanics. We want to understand the
- 1:46Speaker 1: single thread tightrope so to speak, good way to put it, thanks,
- 1:49Speaker 1: And we're going to break down exactly how vulnerabilities like
- 1:51Speaker 1: global namespace pollution and HTTPU parameter pollution happen right at
- 1:56Speaker 1: the code level.
- 1:56Speaker 2: And we really need to emphasize here that we are
- 1:59Speaker 2: bypassing gen naric web vulnerabilities, right, what like poor cryptography
- 2:04Speaker 2: or you know, bad regular expressions, because those things can
- 2:07Speaker 2: happen anywhere in any language. Oh sure, Yeah, we are
- 2:10Speaker 2: focusing strictly on the vulnerabilities that exist specifically because of
- 2:14Speaker 2: the way no JS was designed.
- 2:16Speaker 1: Okay, so let's start right there with the architecture. No
- 2:18Speaker 1: JS is famous for being very lightweight, but what is
- 2:22Speaker 1: actually happening under the hood, Because not just a language, right,
- 2:25Speaker 1: it's a runtime environment exactly.
- 2:28Speaker 2: To really understand the quirks, you have to look at
- 2:30Speaker 2: where it came from. The beating heart of NOJS is
- 2:34Speaker 2: the V eight JavaScript engine, okay. V eight Yeah, and
- 2:37Speaker 2: that is the exact same open source engine that Google
- 2:40Speaker 2: built for the Chrome browser. Oh wow, right, and V
- 2:43Speaker 2: eight is written in C plus plus ple. Its whole
- 2:46Speaker 2: job is to compile JavaScript directly into native machine kind
- 2:50Speaker 2: just before executing it.
- 2:51Speaker 1: So it's using what is it just in time compilation?
- 2:54Speaker 2: You got it just in time or GIT compilation?
- 2:56Speaker 1: Okay, So Ryan Dahl, the creator of Node, essentially just
- 2:59Speaker 1: rip the V eight engine out of the browser. Basically, yeah,
- 3:01Speaker 1: he ripped it out, wrapped it in C plus plus a,
- 3:04Speaker 1: and then gave it access to the underlying operating system exactly.
- 3:07Speaker 2: He gave it access to things the browser usually sandbox
- 3:11Speaker 2: is strictly away, like the file system or network sockets, right, because.
- 3:14Speaker 1: Obviously a browser shouldn't be reading your private local files exactly.
- 3:18Speaker 2: But a server needs to do that. So that is
- 3:20Speaker 2: the foundation. But the architectural choice that defines literally everything
- 3:25Speaker 2: we are going to discuss today is how node handles
- 3:28Speaker 2: concurrency to.
- 3:29Speaker 1: Currency, meaning how it handles a lot of users at once.
- 3:34Speaker 2: Right, So, think about traditional web servers, like older versions
- 3:37Speaker 2: of Apache or Tomcat. They generally use what we call
- 3:40Speaker 2: a multi threaded request response model.
- 3:43Speaker 1: Okay, walk me through that.
- 3:45Speaker 2: So if a thousand users hit the server, the server
- 3:47Speaker 2: spawns one thousand separate threads.
- 3:49Speaker 1: Oh wow, one for each person.
- 3:51Speaker 2: Yes, it allocates distinct memory and CPU time for every
- 3:55Speaker 2: single connection.
- 3:57Speaker 1: Okay, So if I'm building an API with a traditional
- 3:59Speaker 1: multi thread model and my traffic spikes to say, ten
- 4:02Speaker 1: thousand concurrent users, my server is just rapidly spinning up
- 4:07Speaker 1: ten thousand stepper threads to handle them all simultaneously.
- 4:10Speaker 2: Well, actually no, and that is the exact bottleneck Node
- 4:14Speaker 2: was trying to solve. Oh really yeah, because in a
- 4:17Speaker 2: traditional multi threaded model, you eventually just run out of.
- 4:20Speaker 1: RAM because threads take up memory exactly.
- 4:23Speaker 2: Threads are expensive. If a thread is waiting on a
- 4:26Speaker 2: database query to return, it just sits there. It consumes memory,
- 4:30Speaker 2: and it does absolutely nothing else.
- 4:32Speaker 1: While it waits just blocking the line.
- 4:33Speaker 2: Right. This is called blocking IO. Node took a completely
- 4:37Speaker 2: different approach to solve this memory exhaustion problem.
- 4:40Speaker 1: Okay.
- 4:41Speaker 2: Node uses an event driven, non blocking IO model, And
- 4:46Speaker 2: this is the crucial part. The JavaScript execution itself is
- 4:50Speaker 2: entirely single threaded.
- 4:51Speaker 1: Wait, hold on, If the execution is single threaded, how
- 4:54Speaker 1: does it handle ten thousand concurrent connections?
- 4:57Speaker 2: It sounds impossible, rund.
- 4:58Speaker 1: Yeah, I mean, if there's only one thread, doesn't it
- 5:00Speaker 1: just process user one and then user two and then
- 5:03Speaker 1: user ten thousand just times out waiting in line.
- 5:06Speaker 2: Well, it would if it were blocking. But this is
- 5:08Speaker 2: where the event loop comes in.
- 5:10Speaker 1: The event loop.
- 5:10Speaker 2: Yes, the single thread only handles the fast stuff. It
- 5:14Speaker 2: only executes the synchronous JavaScript callbacks. Whenever Node hits an asynchronous,
- 5:20Speaker 2: time consuming task like reading a really large file or
- 5:23Speaker 2: querying a database, it doesn't wait around, was it due?
- 5:27Speaker 2: It offloads that heavy lifting to the system kernel or
- 5:31Speaker 2: to a hidden pool of worker threads managed by a
- 5:33Speaker 2: C plus plus library called labouve.
- 5:36Speaker 1: So wait, it's not actually doing the heavy lifting itself. Nope, Okay,
- 5:39Speaker 1: let me see if I have this mental model right
- 5:41Speaker 1: for you, Listening is it like a waiter at a
- 5:45Speaker 1: really highly efficient restaurant.
- 5:46Speaker 2: Oh, I like this go on?
- 5:48Speaker 1: So the waiter walks up to table one, takes their
- 5:51Speaker 1: super complex order and hands it to the kitchen, right,
- 5:53Speaker 1: but instead of standing by the stove waiting for the
- 5:56Speaker 1: food to cook, which would obviously block them from doing
- 5:58Speaker 1: anything else, the waiter instantly pivots and takes the order
- 6:01Speaker 1: for table two.
- 6:02Speaker 2: Yes, exactly. The kitchen is laboove and your database, and
- 6:06Speaker 2: that waiter is your single JavaScript thread.
- 6:08Speaker 1: And then when the food is ready, the kitchen what
- 6:11Speaker 1: rings a bell and the waiter grabs the plate and
- 6:13Speaker 1: delivered it exactly.
- 6:14Speaker 2: So in code terms, the database finishes the query, it
- 6:18Speaker 2: pushes a callback function into the event queue, and then
- 6:21Speaker 2: the event loop picks it up and executes it on
- 6:24Speaker 2: that single thread.
- 6:25Speaker 1: Wow.
- 6:25Speaker 2: So this means one single thread can juggle tens of
- 6:28Speaker 2: thousands of concurrent connections simply because it never stands around waiting.
- 6:33Speaker 1: It's just constantly moving constantly.
- 6:35Speaker 2: It is incredibly efficient for memory.
- 6:37Speaker 1: Okay, that makes perfect sense for performance. But I can
- 6:40Speaker 1: already see the architectural tightrope here. Oh I bet you can, yeah,
- 6:44Speaker 1: because if absolutely everything I mean user authentication routing business logic.
- 6:50Speaker 1: If it's all executing on that one single thread, what
- 6:52Speaker 1: happens if the waiter trips and falls?
- 6:55Speaker 2: And there it is. This is our first major security
- 6:58Speaker 2: and stability trap I knew. So in a multi threaded architecture,
- 7:02Speaker 2: if a user sends a malicious payload that causes a
- 7:05Speaker 2: fatal error, that specific.
- 7:06Speaker 1: Thread crashes, just that one thread, right.
- 7:09Speaker 2: That one user gets a five hundred internal server error.
- 7:11Speaker 2: But the other ninety nine users are completely unaffected.
- 7:15Speaker 1: Because their threads are totally isolated from each other exactly.
- 7:18Speaker 2: But in no JS you have one thread.
- 7:20Speaker 1: Oh boy.
- 7:21Speaker 2: Yeah, So if an unhandled exception occurs, let's say a
- 7:25Speaker 2: type error because you tried to parse a badly formatted
- 7:30Speaker 2: Jason object without wrapping it in a trycatch block, that
- 7:33Speaker 2: single JavaScript thread crashes. The node process terminates entirely.
- 7:38Speaker 1: So a single unhandled error doesn't just drop the one
- 7:41Speaker 1: user's request, it takes the entire server offline. Yeah, everyone's
- 7:46Speaker 1: web application goes down instantly.
- 7:48Speaker 2: Instantly, it's totally gone. And from a security perspective, this
- 7:51Speaker 2: is a denial of service vulnerability baked right into the architecture.
- 7:55Speaker 1: That is wild.
- 7:56Speaker 2: An attacker doesn't even need a botnet to flood your
- 7:58Speaker 2: server with traffic. They don't need millions of machines.
- 8:01Speaker 1: They just need to find one end point where you
- 8:03Speaker 1: forgot to handle an asynchronous error bingo.
- 8:06Speaker 2: By sending one carefully crackted web request, they can kill
- 8:10Speaker 2: your entire back end process.
- 8:12Speaker 1: Wow. Okay, so how do developers actually defend against that? Because,
- 8:16Speaker 1: let's be real, it's impossible to write perfect code that
- 8:18Speaker 1: never throws an.
- 8:19Speaker 2: Error, right, you can't. So at a code level, you
- 8:21Speaker 2: have to be meticulous about error handling, especially with asynchronous code.
- 8:25Speaker 1: Just wrap everything in trycatch.
- 8:26Speaker 2: Well, no, because a standard triketch block doesn't always catch
- 8:30Speaker 2: errors inside an asynchronous callback. Oh really, Yeah, you have
- 8:34Speaker 2: to handle promise rejections explicitly, otherwise they bubble up to
- 8:38Speaker 2: an unhandled rejection event, and in modern node versions, that
- 8:42Speaker 2: will crash the process.
- 8:44Speaker 1: Okay, so that's the code level. What about the infrastructure level.
- 8:47Speaker 2: At the infrastructure level, you never ever run a bare
- 8:50Speaker 2: node process in production.
- 8:52Speaker 1: Okay, what do you use? Instead?
- 8:53Speaker 2: You use a process manager like PM two, or you
- 8:57Speaker 2: use Node's native cluster module. Spin up multiple instances of
- 9:01Speaker 2: your node application, let's say, one for each CPU core
- 9:04Speaker 2: on your.
- 9:05Speaker 1: Machine, so you have backups.
- 9:07Speaker 2: Right, the process manager acts as a load balancer. If
- 9:10Speaker 2: an attacker crashes one of your instances, the process manager
- 9:13Speaker 2: instantly routes traffing to the surviving instances while it quietly
- 9:17Speaker 2: restarts the dead one in the background.
- 9:18Speaker 1: Okay, that makes sense. So we've mapped out how the
- 9:21Speaker 1: single thread creates a massive bottleneck for stability. But I'm thinking,
- 9:25Speaker 1: if all of these users are sharing the exact same thread,
- 9:29Speaker 1: what does that mean for memory? Because in my head,
- 9:32Speaker 1: if they share a thread, they share the memory space.
- 9:35Speaker 2: Two, they absolutely do share the memory, and that observation
- 9:39Speaker 2: transitions us directly into a really severe vulnerability. It's known
- 9:43Speaker 2: as global name space pollution.
- 9:45Speaker 1: Global name space pollution.
- 9:46Speaker 2: Yeah bah. It is a trap that routinely catches developers
- 9:49Speaker 2: who transition to Node from traditional shared nothing architectures like PHP.
- 9:54Speaker 1: Let's walk through the code mechanics of this for the listener.
- 9:57Speaker 1: Imagine you are writing an application using Exis, which is
- 10:01Speaker 1: the most common web framework for Node.
- 10:03Speaker 2: Very standard.
- 10:04Speaker 1: Right, you set up a basic route handler for the
- 10:06Speaker 1: root directory. But before the route handler, at the very
- 10:09Speaker 1: top of your file, you declare a variable. Let's say,
- 10:13Speaker 1: let admin mode equals false.
- 10:15Speaker 2: Okay, yep, and the intention here is usually pretty benign.
- 10:18Speaker 2: A developer might think they are just setting a default
- 10:21Speaker 2: state for the incoming request.
- 10:22Speaker 1: Right then, inside the app dot get route, the code
- 10:26Speaker 1: runs some logic. Maybe it checks a cookie and if
- 10:29Speaker 1: the cookie is valid, it sets admin mode equals true,
- 10:32Speaker 1: It does some admin tasks, and then it sends a response.
- 10:35Speaker 2: Okay, so let's walk through how VA's memory heat handles this.
- 10:39Speaker 1: Good.
- 10:39Speaker 2: In PHP, when a web request comes in, the server
- 10:42Speaker 2: spins up a totally fresh environment. It executes the script,
- 10:46Speaker 2: serves the response, and then aggressively destroys all the memory
- 10:49Speaker 2: it just used.
- 10:50Speaker 1: Wow, just wipes it entirely.
- 10:52Speaker 2: Yes, everything is wiped clean. So variable states are completely ephemeral.
- 10:56Speaker 1: But no doesn't do that.
- 10:57Speaker 2: No, it doesn't. In no JS, the process stays alive
- 11:00Speaker 2: indefinitely to serve the event loop. When you require a module,
- 11:04Speaker 2: node caches it. Oh yeah. So when you declare a
- 11:07Speaker 2: variable like let admin mode equals false in the outer
- 11:10Speaker 2: module scope, So outside of the specific route handler function,
- 11:14Speaker 2: that variable lives continuously and Viate's memory heap. Wait, it
- 11:18Speaker 2: is shared across every single user session that hits that application.
- 11:21Speaker 1: I want to make sure I'm visualizing this correctly. So
- 11:24Speaker 1: user A visits the site, they are a legitimate administrator.
- 11:27Speaker 1: They hit the route, the application verifies their cookie and
- 11:31Speaker 1: flips that shared module variable. So now admin mode equals true.
- 11:35Speaker 1: The road logic finishes.
- 11:37Speaker 2: Now what happens when USERB connects a millisecond later, and
- 11:41Speaker 2: let's say user B is an unauthenticated guest.
- 11:44Speaker 1: Well, because the variable is outside their ad handler and
- 11:47Speaker 1: because the process never wiped the memory, admin mode is
- 11:50Speaker 1: still sitting in the heap, is true exactly. So user
- 11:53Speaker 1: B hits the route, the application checks admin mode, sees
- 11:57Speaker 1: that it's true, and accidentally gives a random game full
- 12:00Speaker 1: administrative access.
- 12:02Speaker 2: Yes, you nailed it. This is cross user data contamination.
- 12:07Speaker 2: The developer assumed the variable was scoped to the life
- 12:09Speaker 2: cycle of the request, but in reality it was scope
- 12:12Speaker 2: to the life cycle of the entire node process.
- 12:15Speaker 1: That is a staggering vulnerability. I mean you're not just
- 12:17Speaker 1: leaking data, you are completely warping the application state for
- 12:21Speaker 1: everyone concurrently connected to the server.
- 12:24Speaker 2: It's terrifying. During a code review of a node application,
- 12:27Speaker 2: this is one of the very first things a security
- 12:29Speaker 2: engineer looks for. You have to scrutinize the placement of
- 12:32Speaker 2: stateful variables.
- 12:33Speaker 1: So you look for variables at the top of the file.
- 12:35Speaker 2: Basically, if a variable holding sensitive data or authentication flags
- 12:40Speaker 2: or you know, shopping cart totals is declared in the
- 12:43Speaker 2: global scope or the outer module scope, the app is
- 12:46Speaker 2: fundamentally broken.
- 12:48Speaker 1: So how do you fix it?
- 12:49Speaker 2: All state meant for a subtle user must be strictly
- 12:52Speaker 2: confined inside the request response life cycle. It has to
- 12:55Speaker 2: be inside the callback function itself or attached directly to
- 12:59Speaker 2: the request op Okay.
- 13:00Speaker 1: So nodes internal memory management really requires strict discipline because
- 13:04Speaker 1: everything is shared like a big public whiteboard exactly. But
- 13:08Speaker 1: it's not just how node handles its internal memory that
- 13:11Speaker 1: causes issues, right, it's also how it parses external data
- 13:14Speaker 1: coming in from the wild.
- 13:15Speaker 2: Oh yeah, which brings us all the way back to
- 13:17Speaker 2: that Web application firewall crash we discussed at the very
- 13:20Speaker 2: beginning of the deep dive.
- 13:21Speaker 1: Right you called it HTTP parameter pollution, Yes, it topp Okay.
- 13:25Speaker 1: To map this out, we really need to look at
- 13:27Speaker 1: how data moves from a web URL into the back
- 13:30Speaker 1: end code. So when you fill out a search form
- 13:32Speaker 1: or click a tracking link, your browser appends query parameters
- 13:36Speaker 1: to the URL, so you might see something like question
- 13:38Speaker 1: marks userid equals one two, three four five.
- 13:41Speaker 2: Right, and the server takes that raw URL string and
- 13:45Speaker 2: parses it into a format the application can understand. In
- 13:48Speaker 2: an express application, it parses it into a JavaScript.
- 13:51Speaker 1: Object, which usually acts as via rick dot query.
- 13:53Speaker 2: Right exactly, So rec dot query dot usurid would output
- 13:56Speaker 2: the string one two three four five.
- 13:59Speaker 1: Okay, simple enough, But attackers don't play by the rules.
- 14:03Speaker 1: What happens if an attacker manually tampers with the URL
- 14:06Speaker 1: and sends the exact same parameter name twice.
- 14:08Speaker 2: You mean, like question mark userate equals one two, three
- 14:11Speaker 2: four five and person userate equals nine nine nine nine.
- 14:15Speaker 1: Yeah, two, competing instructions for the exact same variable.
- 14:18Speaker 2: Well, different languages resolve this collision totally differently. If you
- 14:22Speaker 2: send that conflicting URL to a traditional PHP back end,
- 14:25Speaker 2: PHP has a very hard coded, predictable behavior.
- 14:28Speaker 1: What does it do?
- 14:29Speaker 2: It looks at the duplicate keys, drops the first one,
- 14:31Speaker 2: and keeps the last occurrence, so it will only register
- 14:34Speaker 2: nine nine nine nine nine.
- 14:35Speaker 1: Oh okay, so it just overwrites the previous value.
- 14:37Speaker 2: That seems safe, it is predictable, but no. JS specifically,
- 14:42Speaker 2: the Express framework handles this completely differently, and to understand why,
- 14:47Speaker 2: you have to look at the underlying library Express uses
- 14:49Speaker 2: for parsing URLs. It's usually a library called queues or
- 14:53Speaker 2: query string.
- 14:54Speaker 1: Wait why does the library matter?
- 14:56Speaker 2: Because modern web applications and restdpis often need to send
- 15:00Speaker 2: complex data structures through the URL likewise, Well, they don't
- 15:04Speaker 2: just want flat strings. They want to send nested objects
- 15:06Speaker 2: and lists, and the ques library was explicitly designed to
- 15:10Speaker 2: support this. So if it sees multiple parameters with the
- 15:13Speaker 2: exact same name, it doesn't drop one.
- 15:15Speaker 1: It doesn't.
- 15:15Speaker 2: No, it assumes you are trying to send a list,
- 15:18Speaker 2: so it takes both values and dynamically transforms that parameter
- 15:22Speaker 2: from a string into a JavaScript array.
- 15:24Speaker 1: Wait, really, so instead of reci dot query dot user
- 15:26Speaker 1: toy being the string one two three forty five, it
- 15:29Speaker 1: suddenly becomes the array bracket one two, three, four five
- 15:32Speaker 1: nine nine nine nine nine bracket.
- 15:33Speaker 2: Yes, the data type fundamentally changes on the fly, based
- 15:36Speaker 2: entirely on the user's input.
- 15:38Speaker 1: Oh wow, okay, let's connect this to the firewall bypass.
- 15:40Speaker 1: You have a custom security filter or a wave sitting
- 15:43Speaker 1: in front of your application logic. It's inspecting every incoming
- 15:46Speaker 1: request to see if userid contains a malicious payload. Like
- 15:50Speaker 1: you know a SQL injection string, then how.
- 15:53Speaker 2: Do you inspect a string? In JavaScript?
- 15:54Speaker 1: You use string prototype methods, So the security filter might
- 15:58Speaker 1: call userd dot to lower case to realize the input,
- 16:01Speaker 1: or user dot match to run a regular expression against it.
- 16:04Speaker 2: Exactly, But the attacker didn't send a string. They sent duplicates,
- 16:08Speaker 2: so express turned it into an array. So when the
- 16:11Speaker 2: security filter attempts to call to lowercase or match on
- 16:14Speaker 2: an array object, what happens?
- 16:17Speaker 1: Well, arrays don't have it to lowercase methods, so the
- 16:19Speaker 1: JavaScript engine throws a type error like rec dot query
- 16:24Speaker 1: dot user redut to lower case is not a function.
- 16:27Speaker 2: Precisely, the security filter throws a fatal exception. Now, depending
- 16:30Speaker 2: on how that filter is architected, one of two things happens.
- 16:33Speaker 1: Okay, what's the first thing.
- 16:35Speaker 2: If it's a synchronous function on the main thread without
- 16:37Speaker 2: a trycatch, it triggers an unhandled exception and crashes the
- 16:41Speaker 2: entire node server, causing a denial of service right, which
- 16:44Speaker 2: we know is catastrophic Because of the single thread model,
- 16:47Speaker 2: we talked about.
- 16:47Speaker 1: It's awful. What's the second scenario?
- 16:49Speaker 2: The second scenario is often way worse. Many custom security
- 16:53Speaker 2: middlewars are actually designed with failsafe.
- 16:55Speaker 1: Okay, that sounds like a good thing.
- 16:57Speaker 2: You'd think. So if the inspection function errors out, the
- 17:00Speaker 2: middleware catches the error, assume something went wrong with the
- 17:03Speaker 2: logging or something minor, and simply calls next to pass
- 17:07Speaker 2: the request along to the database.
- 17:09Speaker 1: Wait, it fails open.
- 17:11Speaker 2: It fails open. The array slips right past the crash
- 17:14Speaker 2: security filter.
- 17:16Speaker 1: Oh my god.
- 17:16Speaker 2: Yeah. And because many database drivers, like certain Mango deb adopters,
- 17:20Speaker 2: are perfectly happy to accept arrays, they might even execute
- 17:23Speaker 2: them as complex queries, so the malicious payload hits the
- 17:27Speaker 2: database completely unobstructed.
- 17:29Speaker 1: That is an incredibly elegant exploit. I mean, the attacker
- 17:32Speaker 1: isn't brute forcing the firewall. They are just exploiting JavaScript's
- 17:36Speaker 1: dynamic typing to trick the firewall into throwing an error
- 17:40Speaker 1: on itself.
- 17:40Speaker 2: It's a devastating bypass. And when security researchers first mapped
- 17:44Speaker 2: out the full impact of this, you know how easily
- 17:47Speaker 2: it broke web application firewalls and custom sanitization logic. They
- 17:51Speaker 2: naturally filed bug reports. Oh, I'm sure they sent them
- 17:54Speaker 2: straight to the maintainers of no js and.
- 17:56Speaker 1: Express, and I would assume the maintainer's patched it immediately.
- 17:59Speaker 1: I mean, and it's a glaring vulnerability.
- 18:01Speaker 2: Well, that is where the tech lore gets really interesting.
- 18:04Speaker 2: The node in Express developers actually pushed back what the
- 18:09Speaker 2: ultimate conclusion of that debate was that this behavior is
- 18:12Speaker 2: not a bug, it is a documented feature.
- 18:15Speaker 1: Breaking security filters is a feature.
- 18:17Speaker 2: Their argument is rooted in the philosophy of the tool.
- 18:20Speaker 2: Express is designed to parse complex URL queries. It is
- 18:24Speaker 2: doing exactly what it was programmed to do, which is
- 18:27Speaker 2: capturing all the data the user provided and structuring it
- 18:30Speaker 2: into an array.
- 18:32Speaker 1: I mean technically true, right, So.
- 18:33Speaker 2: The official stance is that it is not the framework's
- 18:36Speaker 2: responsibility to guess what data types your security filter expects.
- 18:40Speaker 1: So they put the blame entirely on the security developers.
- 18:43Speaker 2: Essentially, Yes, if your custom waft crashes because it blindly
- 18:46Speaker 2: assumes an input is a string without checking the type first,
- 18:50Speaker 2: that is bad code on your end. Yeah, you should
- 18:53Speaker 2: be using TYPEO or array dot is array to validate
- 18:56Speaker 2: the data structure before you run string methods on it.
- 18:59Speaker 2: The frameworks. You the power to receive complex data, it's
- 19:02Speaker 2: on you to validate it safely.
- 19:04Speaker 1: Wow. That is a harsh lesson, but I guess it
- 19:07Speaker 1: really highlights the core theme of no JS. Yeah, it
- 19:11Speaker 1: is a remarkably powerful engine. It gives you raw, non
- 19:15Speaker 1: blocking speed and ultimate flexibility. But it absolutely does not
- 19:18Speaker 1: hold your hand, not at all. If you make a
- 19:20Speaker 1: bad assumption about memory or a bad assumption about data types,
- 19:24Speaker 1: the architecture will just amplify that mistake across the entire application.
- 19:28Speaker 2: Exactly, you cannot just write code that works. You have
- 19:31Speaker 2: to write code that anticipates how the runtime environment will
- 19:34Speaker 2: behave under pressure and manipulation.
- 19:37Speaker 1: That makes total sense. Well, let's quickly review the architecture
- 19:40Speaker 1: we've mapped out today for you listening. We started by
- 19:42Speaker 1: pulling the V eight engine out of the browser and
- 19:44Speaker 1: putting it on a server, and we examined how the
- 19:46Speaker 1: event loop and li boove allow a single JavaScript thread
- 19:50Speaker 1: to handle massive concurrent traffic through non blocking.
- 19:53Speaker 2: IO like our highly efficient waiter. But we also saw
- 19:56Speaker 2: the progility of that design. A single unhandled exception in
- 20:00Speaker 2: thread brings the entire process crashing down.
- 20:03Speaker 1: Yeah, totally offline. Then, we looked at memory management, exploring
- 20:07Speaker 1: how declaring variables outside the request life cycle in a
- 20:10Speaker 1: persistent node process leads to global namespace.
- 20:13Speaker 2: Pollution, which is accidentally sharing private data across entirely different
- 20:17Speaker 2: user sessions.
- 20:18Speaker 1: A huge deal. And finally we dissected HTTP parameter pollution.
- 20:23Speaker 1: We broke down how Express uses the QS library to
- 20:26Speaker 1: parse duplicate URL parameters into a rays and.
- 20:29Speaker 2: How attackers use that dynamic type shifting to crash security
- 20:32Speaker 2: filters that strictly expect strings.
- 20:35Speaker 1: Right, So, before we sign off, I want to challenge you,
- 20:38Speaker 1: the listener, to run a little mental test based on
- 20:40Speaker 1: what we've covered. So imagine you are reviewing a codebase
- 20:44Speaker 1: and you see an Express route handling incoming web traffic.
- 20:47Speaker 1: If an attacker sends a request with three identical parameter names,
- 20:51Speaker 1: let's say question mark filter equals admin ampersand filter equals
- 20:55Speaker 1: guest ampersan filter equals test.
- 20:57Speaker 2: Okay, three parameters, right, how.
- 20:59Speaker 1: Does the no JS back end parts that data compared
- 21:03Speaker 1: to a traditional PHP.
- 21:04Speaker 2: Back end lock in the mechanics in your mind? Right now?
- 21:07Speaker 1: If you remember that PHP drops the first two and
- 21:11Speaker 1: only keeps the final straying, but no JS captures all
- 21:14Speaker 1: three and dynamically constructs an array. Then you've got it perfect.
- 21:19Speaker 1: You now know exactly what to look for when securing
- 21:21Speaker 1: your routes.
- 21:22Speaker 2: But you know, beyond the code, there is a lingering
- 21:26Speaker 2: philosophical question here about the tech industry itself.
- 21:29Speaker 1: Yeah, that whole feature not a bug debate really sits
- 21:32Speaker 1: with me.
- 21:33Speaker 2: It raises a vital point about defensive architecture. When a
- 21:36Speaker 2: widely used framework behaves in a way that is profoundly
- 21:39Speaker 2: counterintuitive to industry norms.
- 21:41Speaker 1: Like turning duplicate strings into an array.
- 21:43Speaker 2: Right, and that behavior is officially documented in the fine
- 21:46Speaker 2: print as a feature. Who bears the ultimate moral responsibility
- 21:50Speaker 2: when a massive data breach occurs?
- 21:52Speaker 1: That's great question.
- 21:53Speaker 2: Does the blame fall on the language creators for building
- 21:56Speaker 2: an unexpected trap or does it fall purely on the
- 21:58Speaker 2: developers for not reading the fine print closely enough before
- 22:01Speaker 2: putting the application into production.
- 22:03Speaker 1: Honestly, it's a fine line between a powerful tool and
- 22:05Speaker 1: a loaded weapon. Well, until next time, keep digging, keep questioning,
- 22:09Speaker 1: and keep exploring the deep dive