-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #426 from owasp-noir/add-actix-web
✨ Add ActixWeb
- Loading branch information
Showing
9 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "example-hello-world" | ||
|
||
[dependencies] | ||
actix-web = "4.9" | ||
actix-web-actors = "4.1" | ||
actix-web-lab = "0.22" | ||
actix-ws = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder}; | ||
|
||
#[get("/")] | ||
async fn hello() -> impl Responder { | ||
HttpResponse::Ok().body("Hello world!") | ||
} | ||
|
||
#[post("/echo")] | ||
async fn echo(req_body: String) -> impl Responder { | ||
HttpResponse::Ok().body(req_body) | ||
} | ||
|
||
async fn manual_hello() -> impl Responder { | ||
HttpResponse::Ok().body("Hey there!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require "../func_spec.cr" | ||
|
||
extected_endpoints = [ | ||
Endpoint.new("/", "GET"), | ||
Endpoint.new("/echo", "POST"), | ||
] | ||
|
||
FunctionalTester.new("fixtures/rust_actix_web/", { | ||
:techs => 1, | ||
:endpoints => extected_endpoints.size, | ||
}, extected_endpoints).test_all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "../../../models/analyzer" | ||
|
||
module Analyzer::Rust | ||
class ActixWeb < Analyzer | ||
def analyze | ||
# Source Analysis | ||
pattern = /#\[(get|post|put|delete|patch)\("([^"]+)"\)\]/ | ||
|
||
begin | ||
Dir.glob("#{base_path}/**/*") do |path| | ||
next if File.directory?(path) | ||
|
||
if File.exists?(path) && File.extname(path) == ".rs" | ||
File.open(path, "r", encoding: "utf-8", invalid: :skip) do |file| | ||
file.each_line.with_index do |line, index| | ||
if line.to_s.includes? "#[" | ||
match = line.match(pattern) | ||
if match | ||
begin | ||
route_argument = match[2] | ||
callback_argument = match[1] | ||
details = Details.new(PathInfo.new(path, index + 1)) | ||
result << Endpoint.new("#{route_argument}", callback_to_method(callback_argument), details) | ||
rescue | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
rescue e | ||
end | ||
|
||
result | ||
end | ||
|
||
def callback_to_method(str) | ||
method = str.split("(").first | ||
if !["get", "post", "put", "delete"].includes?(method) | ||
method = "get" | ||
end | ||
|
||
method.upcase | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "../../../models/detector" | ||
|
||
module Detector::Rust | ||
class ActixWeb < Detector | ||
def detect(filename : String, file_contents : String) : Bool | ||
check = file_contents.includes?("actix-web") | ||
check = check && file_contents.includes?("dependencies") | ||
check = check && filename.includes?("Cargo.toml") | ||
|
||
check | ||
end | ||
|
||
def set_name | ||
@name = "rust_actix_web" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters