Dart Unsafe Input Path Traversal Relative
Description
Detects potential path traversal vulnerabilities in Dart applications where file operations use relative paths from user input. This vulnerability could allow attackers to access files outside the intended directory by manipulating path inputs, potentially exposing sensitive files on the server.
Detection Strategy
• Check if the application imports the 'shelf' or 'path' packages from Dart
• Look for file operations (like File.read, File.write) that use relative paths
• Verify if the file operation uses path parameters that could contain user-controlled input without proper sanitization
Vulnerable code example
import 'dart:io';
import 'package:shelf/shelf.dart' as shelf;
Future<shelf.Response> serveFile(shelf.Request req) async {
final userInput = req.url.queryParameters['filename'];
// VULNERABLE: Direct string concatenation allows path traversal
final file = File('uploads/' + userInput);
return shelf.Response.ok(await file.readAsString());...✅ Secure code example
import 'dart:io';
import 'package:shelf/shelf.dart' as shelf;
import 'package:path/path.dart' as path;
Future<shelf.Response> serveFile(shelf.Request req) async {
final userInput = req.url.queryParameters['filename'];
if (userInput == null) {
return shelf.Response.badRequest(body: 'Filename parameter is required');...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.