1. Opening Problem Statement
Meet Sarah, an independent web developer tasked with ensuring her client’s e-commerce website is secure against common vulnerabilities. Without deep security expertise or expensive tools, Sarah spends hours manually checking HTTP headers and scanning page content for risks. She worries about missing critical security flaws like improper Content-Security-Policy headers or client-side JavaScript vulnerabilities that could expose customer data or enable attacks. The time-consuming audit costs precious hours and carries risk of human error, which could lead to serious breaches and damage her client’s reputation.
This is where an automated, precise, and developer-friendly workflow designed specifically for website security auditing becomes invaluable. By running this n8n-based workflow, Sarah can scan any website URL, analyze security headers and page code with expert-level AI, and receive a detailed visual report by email — drastically saving time and elevating audit accuracy.
2. What This Automation Does
This website security audit workflow built in n8n automates the process of scrutinizing a target landing page URL for client-side security issues and HTTP header misconfigurations using OpenAI’s GPT-4o models. When activated, it delivers an insightful audit report by Gmail. Here’s exactly what happens:
- Securely triggers on user input: The workflow starts when a user submits a landing page URL via a custom form, making it easy to scan varied websites on demand.
- Fetches full webpage content and headers: The HTTP Request node scrapes the URL’s HTML content and HTTP response headers, capturing key data needed for analysis.
- Analyses security headers with AI: One OpenAI agent inspects HTTP headers like Content-Security-Policy, Strict-Transport-Security, and cookies to identify missing or misconfigured security settings.
- Audits webpage content vulnerabilities: Another OpenAI agent reviews the HTML and JavaScript for client-side risks such as XSS openings or information leakage.
- Merges AI findings and scores security: Results from both agents are merged, aggregated, and a custom script calculates a security grade (A+ to F), highlighting critical issues and warnings.
- Formats a comprehensive HTML report: The final Code node builds a visually rich, color-coded email report that includes actionable recommendations, raw header data, and vulnerability details.
- Sends email via Gmail: The detailed report is emailed automatically to a specified recipient for timely review and remediation.
The workflow empowers users by automating exhaustive security audits that would otherwise require manual expertise and multiple tools. It saves hours per audit, reduces risk of oversights, and provides clear, digestible results that development teams can act upon quickly.
3. Prerequisites ⚙️
- n8n account: Have an active account on n8n cloud or a self-hosted instance.
- OpenAI API credentials 🔑: Obtain an API key from OpenAI to connect Langchain GPT-4o models for security analysis.
- Gmail OAuth2 credentials 📧: Setup Gmail OAuth2 credentials in n8n to send email reports via Gmail.
- Basic familiarity with n8n workflows: Helpful but not mandatory.
You can self-host n8n using services like Hostinger (link) if you prefer full control and privacy.
4. Step-by-Step Guide
Step 1: Create a Form Trigger to Capture URL Input
Navigate to Add Node → Trigger → Form Trigger. Name it “Landing Page Url”.
Configure the form with a single required field labeled “Landing Page Url” with a placeholder like https://example.com. Add a descriptive title and message to inform users this form will initiate a website security scan.
Save and activate the node.
You should see a webhook URL generated; this is the URL users will visit to submit their scan requests.
Common mistake: forgetting to mark the URL field as required, which may allow triggering without input.
Step 2: Add HTTP Request to Scrape Webpage & Headers
Add an HTTP Request node named “Scrape Website”.
Set the URL parameter dynamically to the submitted form input: {{ $json['Landing Page Url'] }}.
Under Options, allow following HTTP redirects up to 5 times.
Set the response format to Full Response to capture headers, and Response Type to Text.
This node fetches all the HTML and HTTP header info needed for the audit.
Expected output includes the webpage body and raw headers in JSON.
Common mistake: not enabling full response headers, which means data needed for header audit will be missing.
Step 3: Extract & Format Headers for Processing
Add a Code node called “Extract Headers for Debug”.
Paste this snippet to extract headers into a readable string and retain the original headers:
let formattedHeaders = '';
if (items[0].json.headers) {
for (const key in items[0].json.headers) {
formattedHeaders += `${key}: ${items[0].json.headers[key]}n`;
}
}
return [{
json: {
...items[0].json,
formattedHeaders: formattedHeaders,
originalHeaders: items[0].json.headers
}
}];
This node prepares headers for the subsequent AI audit nodes.
If you see missing headers downstream, check this node’s output for completeness.
Step 4: OpenAI Header Security Configuration Audit
Add an OpenAI Chat node (using Langchain) named “OpenAI Headers Analysis”.
Configure it to use GPT-4o-mini model or full GPT-4o for best results.
Credential: select your OpenAI API key from credentials.
Feed the formatted headers string as input context.
This node runs an expert audit to identify missing or misconfigured HTTP security headers like HSTS, CSP, and cookies.
Expected output is a structured report noting header presence, security implications, and recommendations.
Step 5: OpenAI Content Vulnerabilities Audit
Add a second OpenAI Chat node called “OpenAI Content Analysis”.
Feed it the scraped page HTML content.
This node acts as a security expert agent analyzing potential client-side vulnerabilities — including JavaScript issues or information leakage.
Output is another focused audit report with specific vulnerability findings and fixes.
Step 6: Combine Audit Results
Use a Merge node called “Merge Security Results” to combine the output from the two OpenAI audit nodes.
Set to merge by key or just join to output both results in one message.
This step consolidates header and content findings for unified processing.
Step 7: Aggregate Findings for Processing
Add an Aggregate node named “Aggregate Audit Results” to gather all audit text from the Merge node.
This node preps the collected data for formatted report generation.
Step 8: Analyze & Process Audit with Custom Code
Add a Code node labeled “Process Audit Results”.
This node contains custom JavaScript logic that:
- Extracts key security headers and their values
- Checks for common risks like “unsafe-inline” in CSP
- Determines an overall security grade (A+ through F)
- Prepares counts of critical issues and warnings for the report
- Formats strings usable for HTML report templates
Code is complex but well commented to facilitate understanding and modification.
Common mistake: Modifying script without retaining header names or grade logic can crash the report.
Step 9: Convert Audit Data into a Stylish HTML Email
Use another Code node named “convert to HTML”.
It generates a comprehensive and visually appealing HTML email including:
- Security grade badge with color coding
- Summary table with URL, timestamp, header badges, and issue counts
- Warnings highlighted in yellow with detailed explanation
- Raw HTTP headers table with color-coded statuses
- Detailed vulnerability and configuration issue blocks
- Additional information and implementation tips
This email is ready-to-send and mobile-responsive.
Common mistake: Removing or breaking HTML structure can prevent rendering in email clients.
Step 10: Email the Final Security Report
Add a Gmail node called “Send Security Report”.
Configure it with the recipient email, subject (including target URL), and insert the generated HTML content from the previous node.
Ensure your Gmail OAuth2 credential is active and correct.
Emails are sent automatically, dramatically accelerating communication of audit results.
Common mistake: forgetting to update the recipient email address for real deployments.
5. Customizations ✏️
- Change the email recipient: In the “Send Security Report” Gmail node, update the “sendTo” field to your desired receiver to make sure reports reach the right inbox.
- Upgrade OpenAI model: Switch GPT-4o-mini to full GPT-4o in the OpenAI nodes for deeper, more accurate analysis, especially for complex sites.
- Extend form fields: Add more inputs in the Form Trigger node, such as scanning frequency or alert emails, to customize automated scans further.
- Modify grading criteria: Edit the JavaScript in “Process Audit Results” node to tighten or loosen security grade thresholds based on your organizational standards.
- Adjust email style: In the “convert to HTML” node, tweak colors, fonts, or layout to align the report styling with your brand identity.
6. Troubleshooting 🔧
Problem: “No headers found” or header-related errors in audit results.
Cause: HTTP Request node not configured to return full headers.
Solution: Go to “Scrape Website” node → Options → ensure “Full Response” is enabled and headers are retrieved properly.
Problem: OpenAI nodes return generic error or timeout.
Cause: Incorrect or missing API key, or exceeding OpenAI usage limits.
Solution: Check credentials under Settings → Credentials → OpenAI API.
Also, review usage dashboard on OpenAI platform for rate limits.
Problem: Gmail node fails to send email.
Cause: OAuth token expired or not configured.
Solution: Re-authorize Gmail credentials in n8n and verify permissions.
7. Pre-Production Checklist ✅
- Verify OpenAI and Gmail credentials are valid and active.
Test by running test requests and sending dummy emails. - Submit test URLs (e.g. https://example.com) to ensure workflow triggers end-to-end.
Check audit emails for proper formatting and correct data. - Ensure HTTP Request node is configured to follow redirects and capture all headers.
- Backup your workflow before major modifications for rollback.
8. Deployment Guide
Once satisfied with testing, switch the workflow toggle to “Active”.
Share the webhook form URL with stakeholders or embed as needed.
Monitor workflow executions under n8n’s Activity tab to track usage.
You can set up notifications or logs for failures if desired.
Periodic reviews and API key rotations keep the automation robust and secure.
9. FAQs
Q: Can I use an alternative email service instead of Gmail?
A: Yes, you can replace the Gmail node with SMTP or other email nodes in n8n, but you will need to adjust authentication accordingly.
Q: Does running this workflow consume many OpenAI API credits?
A: While it makes two calls to the OpenAI API per run, analysis is optimized for summary and not excessive detail, balancing accuracy with cost.
Q: Is it safe to submit sensitive URLs?
A: The workflow only performs client-side analysis without logging or storing non-public data, but always consider your security policies.
Q: Can this handle high volumes of website scans?
A: For large scale usage, ensure your OpenAI account plan and Gmail usage limits support the volume, or use queuing and throttling in n8n.
10. Conclusion
By implementing this tailored n8n workflow, you have automated a comprehensive website security audit that leverages AI to identify header misconfigurations and client-side vulnerabilities simultaneously. You save hours per audit, boost accuracy, and empower informed remediation with clear, actionable reports sent directly by email.
This tool transforms security scanning from tedious manual task into a fast, professional process accessible to web developers like Sarah and beyond.
Next steps to explore include adding periodic scheduling for regular audits, integrating ticketing systems for issue tracking, or expanding analysis with server-side scans.
Keep securing the web one scan at a time!