14. Amazon S3: Buckets, Objects, Policies and Presigned URLs
14.6 Presigned URLs: Temporary Private Access
Bucket private aahe, pan user la ek video 10 minutes sathi baghu dyaycha aahe – kasa? Presigned URL. Server aaplya credentials ne ek URL "sign" karto; tya URL madhe expiry time aani signature asto. Expiry nantar URL band.
aws s3 presign s3://ravindra-demo-files-pune/site/index.html --expires-in 600 # 600 seconds
The output looks like this (shortened):
https://ravindra-demo-files-pune.s3.ap-south-1.amazonaws.com/site/index.html
?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA.../ap-south-1/s3/aws4_request
&X-Amz-Date=20260927T043000Z&X-Amz-Expires=600&X-Amz-Signature=5f2c...
In PHP (AWS SDK for PHP – we use exactly this in the project chapter):
<?php
require __DIR__ . '/vendor/autoload.php';
$s3 = new Aws\S3\S3Client(['region' => 'ap-south-1']); // credentials come from the IAM role
$cmd = $s3->getCommand('GetObject', ['Bucket' => 'ravindra-reels-media-pune', 'Key' => 'videos/a1.mp4']);
$url = (string) $s3->createPresignedRequest($cmd, '+15 minutes')->getUri();
echo $url;
| Presigned URL fact | Why it matters |
|---|---|
| Works for GET (download) and PUT (upload) | Browsers can upload directly to S3 without your credentials |
| Signed with the signer's permissions | If the role cannot read the object, the URL fails too |
| Anyone holding the URL can use it until expiry | Keep expiry short; don't log or share them |
| Role-based (temporary) credentials | The URL also stops working when those credentials expire |
Why this matters for security
Presigned URLs let you keep the bucket 100% private and still serve files to logged-in users – the right design for user uploads. But they are bearer tokens (वाहक टोकन): whoever has the link has access. Short expiry, HTTPS only, and never presigning keys that come straight from user input without checks (or a user could ask for someone else's file – an IDOR bug).
Ravindra Bagale's Tip
Many students give a presigned URL a 7-day expiry "for convenience", and the URL ends up circulating on WhatsApp! For a video feed, 10–20 minutes is enough – a new URL is created when the page reloads. And if you run aws s3 presign on your laptop and get a 403, check the region – sign in the bucket's own region.
Ravindra Bagale's Tip – मराठी
बरेच students "सोयीसाठी" presigned URL ला 7 दिवसांची expiry देतात आणि तो URL WhatsApp वर फिरतो! Video feed साठी 10–20 minutes पुरेसे आहेत – page reload झालं की नवीन URL बनतो. आणि laptop वर aws s3 presign केल्यावर 403 आला तर region बघा – bucket च्या region मध्येच sign करा.
Ravindra Bagale's Tip – हिंदी
बहुत से students "सुविधा के लिए" presigned URL को 7 दिन की expiry दे देते हैं और वह URL WhatsApp पर घूमने लगता है! Video feed के लिए 10–20 minutes काफ़ी हैं – page reload होते ही नया URL बनता है. और laptop पर aws s3 presign करने पर 403 आए तो region देखो – bucket के region में ही sign करो.
Lab
Upload a private image. Confirm its plain object URL returns AccessDenied in the browser. Generate a presigned URL with --expires-in 60, open it immediately, then open it again after two minutes and observe the expiry error.
Extended teaching notes
Why this lesson matters
Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.
Apply the fix across stacks
Same class of bug, same idea in every language.
Java / Spring Boot
Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.
ASP.NET Core
EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.
Node.js / Express
helmet, parameterised SQL, npm audit, avoid eval and shell concat.
Python / Django / Flask / FastAPI
ORM, autoescape, pip-audit, Bandit; never shell=True with user input.
PHP / Laravel
PDO/Eloquent, Blade escaping, composer audit.
Go / Ruby
database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.
nginx / Apache / Tomcat
Hide versions, TLS, security headers, least-open ports.
MySQL / PostgreSQL / MongoDB / Redis
Private networks, auth on, least-privilege users, no 0.0.0.0/0.
AWS / Azure / GCP
Roles not long-lived keys, private data stores, cloud audit logs on.
Mini case study
Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.
Defender's worksheet (do this today)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.
Indian workplace (sample data)
Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).
Global practice
Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.
Everyday analogy
Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.
Key terms
- Control: a safeguard (patch, config, process, detection).
- Finding: a weakness backed by evidence.
- Remediation: the fix plus how you verified it.
- Scope: systems you have written permission to touch.
- Least privilege: only the access the task needs.
- Defence in depth: several layers so one failure does not end the story.
Common mistakes
- Skipping written permission "just for a quick scan".
- Practising on hostel, office or public targets without authorisation.
- Collecting tool output without writing the fix.
- Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
- Publishing screenshots that contain secrets, cookies or internal hostnames.
Recap
- Evidence, fix, owner, date.
- Own lab only.
- Fix > spectacle.