SIBERSALDIRI.COM · FOCUSED LESSON
What you will learn
- Explain the relationship between user data and the Embedded API.
- “What is the strongest first design choice?” To give a reasoned answer to the question.
- Changing the example and comparing expected and observed behavior.
How it works and where the trust boundary lies
Instead of calling a shell for work like file size, use the language's built-in API. If the command is really necessary, the executable file and arguments should be transferred with a separate contract, and the allowed operations and values should be restricted. The escape technique depends on the operating system and interpreter; It is not a general purpose cleaning guarantee. The service account must run with minimal permissions.
Worked example
The following passage makes the concept visible. Evaluate samples containing commands or code in your own separate testing environment, not in the production system. Architectural diagrams and policy examples are not executable programs.
<?php
$path = __DIR__ . '/sample.txt';
if (!is_file($path)) { throw new RuntimeException('Dosya yok'); }
echo filesize($path);Expected result and interpretation
The size of the local hard file is obtained without running the shell command.
Compare the scenarios
| Status | Recommended approach | Why? |
|---|---|---|
| Built-in API is sufficient | Using a shell | Interpreter limit is removed |
| command required | Constant executable and argument | Free codes are not accepted |
| Input is claimed to be sanitised | Verify context | Escape rules are not the same |
Practice task
Write how to replace a shell-using file listing job with the built-in file API.
- Write down the expected outcome and acceptance condition before the action.
- Change a single variable; Record the observation and the medium you used.
- Evaluate the result with the comparison table above. Explain which assumption might be wrong if it does not fit.
Common mistake and how to correct it
Do not accept commands or executable filenames from the client.
Test your understanding
What is the strongest first design choice?
Answer explained: Doing the job with the secure built-in API without the shell interpreter removes the associated interpreter limit.
Continue with related lessons
- Secure Coding: Validating Data at Trust Boundaries
- LFI: Not converting user input to file selection
- SSTI: Separating user data with template code
- SQL Basics: Selection, Relationships, and Safe Parameters
Technical reference
The explanation and examples of this course have been re-prepared for the academy. The link below is a technical reference to verify details of the technology or security approach used.
