Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Unified Diff: pkg/http_server/lib/src/virtual_directory.dart

Issue 18333003: Correctly url-decode the path segment in the http_server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't allow invalid characters in segment. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/http_server/test/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/lib/src/virtual_directory.dart
diff --git a/pkg/http_server/lib/src/virtual_directory.dart b/pkg/http_server/lib/src/virtual_directory.dart
index bb3b7ac44260916aae1e135a5e7a027441814651..f608eb9123c8a24d0d992880856168ab135811dc 100644
--- a/pkg/http_server/lib/src/virtual_directory.dart
+++ b/pkg/http_server/lib/src/virtual_directory.dart
@@ -65,6 +65,8 @@ class _VirtualDirectory implements VirtualDirectory {
bool allowDirectoryListing = false;
bool followLinks = true;
+ final RegExp _invalidPathRegExp = new RegExp("[\\\/\x00]");
+
Function _errorCallback;
Function _dirCallback;
@@ -75,13 +77,7 @@ class _VirtualDirectory implements VirtualDirectory {
}
void serveRequest(HttpRequest request) {
- var path = new Path(request.uri.path).canonicalize();
-
- if (!path.isAbsolute) {
- return _serveErrorPage(HttpStatus.NOT_FOUND, request);
- }
-
- _locateResource(new Path('.'), path.segments())
+ _locateResource(new Path('.'), request.uri.pathSegments.iterator..moveNext())
.then((entity) {
if (entity == null) {
_serveErrorPage(HttpStatus.NOT_FOUND, request);
@@ -106,23 +102,28 @@ class _VirtualDirectory implements VirtualDirectory {
}
Future<FileSystemEntity> _locateResource(Path path,
- Iterable<String> segments) {
+ Iterator<String> segments) {
+ path = path.canonicalize();
+ if (path.segments().first == "..") return new Future.value(null);
Path fullPath() => new Path(root).join(path);
return FileSystemEntity.type(fullPath().toNativePath(), followLinks: false)
.then((type) {
switch (type) {
case FileSystemEntityType.FILE:
- if (segments.isEmpty) return new File.fromPath(fullPath());
+ if (segments.current == null) {
+ return new File.fromPath(fullPath());
+ }
break;
case FileSystemEntityType.DIRECTORY:
- if (segments.isEmpty) {
+ if (segments.current == null) {
if (allowDirectoryListing) {
return new Directory.fromPath(fullPath());
}
} else {
- return _locateResource(path.append(segments.first),
- segments.skip(1));
+ if (_invalidPathRegExp.hasMatch(segments.current)) break;
+ return _locateResource(path.append(segments.current),
+ segments..moveNext());
}
break;
@@ -132,15 +133,8 @@ class _VirtualDirectory implements VirtualDirectory {
.then((target) {
var targetPath = new Path(target).canonicalize();
if (targetPath.isAbsolute) return null;
- targetPath =
- path.directoryPath.join(targetPath).canonicalize();
- if (targetPath.segments().isEmpty ||
- targetPath.segments().first == '..') return null;
- if (segments.isEmpty) {
- return _locateResource(targetPath, []);
- }
- return _locateResource(targetPath.append(segments.first),
- segments.skip(1));
+ targetPath = path.directoryPath.join(targetPath);
+ return _locateResource(targetPath, segments);
});
}
break;
« no previous file with comments | « no previous file | pkg/http_server/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698